Merge branch 'xorg/master' into xorg/f/geocoding
[platal.git] / classes / direnum.php
1 <?php
2 /***************************************************************************
3 * Copyright (C) 2003-2011 Polytechnique.org *
4 * http://opensource.polytechnique.org/ *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the Free Software *
18 * Foundation, Inc., *
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
20 ***************************************************************************/
21
22 // {{{ class DirEnum
23 /** This class stores all data for the different kinds of fields.
24 * It is only a dispatcher for the various DirEnum_XXX classes.
25 */
26 class DirEnum
27 {
28 /** Name of availables Enumerations
29 * Each of these consts contains the basename of the class (its full name
30 * being DE_$basename).
31 */
32 const NAMETYPES = 'nametypes';
33 const NAMES = 'names';
34
35 const BINETS = 'binets';
36 const GROUPESX = 'groupesx';
37 const SECTIONS = 'sections';
38
39 const EDUSCHOOLS = 'educationschools';
40 const EDUDEGREES = 'educationdegrees';
41 const EDUFIELDS = 'educationfields';
42
43 const CURRENTCORPS = 'currentcorps';
44 const ORIGINCORPS = 'origincorps';
45 const CORPSRANKS = 'corpsranks';
46
47 const NATIONALITIES = 'nationalities';
48 const SUBLOCALITIES = 'sublocalities';
49 const LOCALITIES = 'localities';
50 const ADMNISTRATIVEAREAS3 = 'admnistrativeareas3';
51 const ADMNISTRATIVEAREAS2 = 'admnistrativeareas2';
52 const ADMNISTRATIVEAREAS1 = 'admnistrativeareas1';
53 const COUNTRIES = 'countries';
54
55 const COMPANIES = 'companies';
56 const JOBDESCRIPTION = 'jobdescription';
57 const JOBTERMS = 'jobterms';
58
59 const NETWORKS = 'networking';
60
61 const MEDALS = 'medals';
62
63 const ACCOUNTTYPES = 'accounttypes';
64 const SKINS = 'skins';
65
66 static private $enumerations = array();
67
68 static private function init($type)
69 {
70 if (Platal::globals()->cacheEnabled() && S::has('__DE_' . $type)) {
71 self::$enumerations[$type] = S::v('__DE_' . $type);
72 } else {
73 $cls = "DE_" . ucfirst($type);
74 $obj = new $cls();
75 self::$enumerations[$type] = $obj;
76 if (Platal::globals()->cacheEnabled()
77 && $obj->capabilities & DirEnumeration::SAVE_IN_SESSION) {
78 S::set('__DE_' . $type, $obj);
79 }
80 }
81 }
82
83 /** Retrieves all options for a given type
84 * @param $type Type of enum for which options are requested
85 * @return Array of the results
86 */
87 static public function getOptions($type)
88 {
89 if (!array_key_exists($type, self::$enumerations)) {
90 self::init($type);
91 }
92 $obj = self::$enumerations[$type];
93 if ($obj->capabilities & DirEnumeration::HAS_OPTIONS) {
94 return call_user_func(array($obj, 'getOptions'));
95 } else {
96 return array();
97 }
98 }
99
100 /** Retrieves all options for a given type
101 * @param $type Type of enum for which options are requested
102 * @return PlIterator over the results
103 */
104 static public function getOptionsIter($type)
105 {
106 if (!array_key_exists($type, self::$enumerations)) {
107 self::init($type);
108 }
109 $obj = self::$enumerations[$type];
110 $args = func_get_args();
111 array_shift($args);
112 if ($obj->capabilities & DirEnumeration::HAS_OPTIONS) {
113 return call_user_func_array(array($obj, 'getOptionsIter'), $args);
114 } else {
115 return PlIteratorUtils::fromArray(array());
116 }
117 }
118
119 /** Retrieves all options with number of profiles for autocompletion
120 * @param $type Type of enum for which options are requested
121 * @param $text Text to autocomplete
122 * @return PlIterator over the results
123 */
124 static public function getAutoComplete($type, $text)
125 {
126 if (!array_key_exists($type, self::$enumerations)) {
127 self::init($type);
128 }
129 $obj = self::$enumerations[$type];
130 if ($obj->capabilities & DirEnumeration::HAS_AUTOCOMP) {
131 return call_user_func(array($obj, 'getAutoComplete'), $text);
132 } else {
133 return PlIteratorUtils::fromArray(array());
134 }
135 }
136
137 /** Retrieves a list of IDs for a given type
138 * @param $type Type of enum for which IDs are requested
139 * @param $text Text to search in enum valuees
140 * @param $mode Mode of search for those IDs (prefix/suffix/infix)
141 */
142 static public function getIDs($type, $text, $mode = XDB::WILDCARD_EXACT)
143 {
144 if (!array_key_exists($type, self::$enumerations)) {
145 self::init($type);
146 }
147 $obj = self::$enumerations[$type];
148 if ($obj->capabilities & DirEnumeration::HAS_OPTIONS) {
149 return call_user_func(array($obj, 'getIDs'), $text, $mode);
150 } else {
151 return array();
152 }
153 }
154
155 /** Retrieves a single ID for a given type.
156 * @param $type Type of the enum for which an ID is requested
157 * @param $text Text to search in enum values
158 * @param $mode Mode of search of that ID (prefix/suffix/infix/exact)
159 */
160 static public function getID($type, $text, $mode = XDB::WILDCARD_EXACT)
161 {
162 $ids = self::getIDs($type, $text, $mode);
163 return array_shift($ids);
164 }
165 }
166 // }}}
167
168 // {{{ class DirEnumeration
169 abstract class DirEnumeration
170 {
171 const AUTOCOMPLETE_LIMIT = 11;
172
173 const HAS_OPTIONS = 0x001;
174 const HAS_AUTOCOMP = 0x002;
175 const SAVE_IN_SESSION = 0x004;
176
177 public $capabilities = 0x003; // self::HAS_OPTIONS | self::HAS_AUTOCOMP;
178
179 /** An internal array of ID => optionTxt
180 */
181 protected $options = null;
182
183 /** Description of the MySQL storage of the fields
184 */
185 protected $idfield = 'id';
186 protected $valfield = 'text';
187 protected $valfield2 = null;
188 protected $from;
189 protected $join = '';
190 protected $where = '';
191
192 /** Fields for autocompletion
193 */
194 protected $ac_join = ''; // Additional joins
195 protected $ac_where = null; // Additional where
196 protected $ac_beginwith = true; // Whether to search for 'x%' or for '%x%'
197 protected $ac_unique; // Which field is to be taken as unique
198 protected $ac_distinct = true; // Whether we want to keep only distinct valfield value
199 protected $ac_withid = true; // Do we want to fetch id too ?
200
201 protected function _fetchOptions()
202 {
203 if (is_null($this->options)) {
204 $this->loadOptions();
205 }
206 }
207
208 public function getOptions()
209 {
210 $this->_fetchOptions();
211 return $this->options;
212 }
213
214 public function getOptionsIter()
215 {
216 $options = $this->getOptions();
217 $options = self::expandArray($options);
218 return PlIteratorUtils::fromArray($options, 1, true);
219 }
220
221 // {{{ function getIDs
222 /** Retrieves possible IDs for given text
223 * @param $text Text to search for IDs
224 * @param $mode Mode of search (PREFIX, SUFFIX, CONTAINS)
225 * @return An array of matching IDs ; if empty, input should be considered invalid
226 */
227 public function getIDs($text, $mode)
228 {
229 if ($mode == XDB::WILDCARD_EXACT) {
230 $options = $this->getOptions();
231 return array_keys($options, $text);
232 } else {
233 if ($this->where == null) {
234 $where = 'WHERE ';
235 } else {
236 $where = $this->where . ' AND ';
237 }
238 $conds = array();
239 $conds[] = $this->valfield . XDB::formatWildcards($mode, $text);
240 if ($this->valfield2 != null) {
241 $conds[] = $this->valfield2 . XDB::formatWildcards($mode, $text);
242 }
243 $where .= '(' . implode(' OR ', $conds) . ')';
244
245 return XDB::fetchColumn('SELECT ' . $this->idfield . '
246 FROM ' . $this->from . '
247 ' . $this->join . '
248 ' . $where . '
249 GROUP BY ' . $this->idfield);
250 }
251 }
252 // }}}
253
254 /** Builds a list of query parts for searching @$text in @$field :
255 * field LIKE 'text%', field LIKE '% text%', field LIKE '%-text%'
256 */
257 private function mkTests($field, $text)
258 {
259 $tests = array();
260 $tests[] = $field . XDB::formatWildcards(XDB::WILDCARD_PREFIX, $text);
261 if (!$this->ac_beginwith) {
262 $tests[] = $field . XDB::formatWildcards(XDB::WILDCARD_CONTAINS, ' ' . $text);
263 $tests[] = $field . XDB::formatWildcards(XDB::WILDCARD_CONTAINS, '-' . $text);
264 }
265 return $tests;
266 }
267
268 static protected function expandArray(array $tab, $keyname = 'id', $valname = 'field')
269 {
270 $res = array();
271 foreach ($tab as $key => $val) {
272 $res[$key] = array(
273 $keyname => $key,
274 $valname => $val,
275 );
276 }
277 return $res;
278 }
279
280 // {{{ function getAutoComplete
281 public function getAutoComplete($text)
282 {
283 $text = str_replace(array('%', '_'), '', $text);
284
285 if (is_null($this->ac_where) || $this->ac_where == '') {
286 $where = '';
287 } else {
288 $where = $this->ac_where . ' AND ';
289 }
290
291 $tests = $this->mkTests($this->valfield, $text);
292 if (!is_null($this->valfield2)) {
293 $tests = array_merge($tests, $this->mkTests($this->valfield2, $text));
294 }
295
296 $where .= '(' . implode(' OR ', $tests) . ')';
297
298 return XDB::iterator('SELECT ' . $this->valfield . ' AS field'
299 . ($this->ac_distinct ? (', COUNT(DISTINCT ' . $this->ac_unique . ') AS nb') : '')
300 . ($this->ac_withid ? (', ' . $this->idfield . ' AS id') : '') . '
301 FROM ' . $this->from . '
302 ' . $this->ac_join . '
303 WHERE ' . $where . '
304 GROUP BY ' . $this->valfield . '
305 ORDER BY ' . ($this->ac_distinct ? 'nb DESC' : $this->valfield) . '
306 LIMIT ' . self::AUTOCOMPLETE_LIMIT);
307 }
308 // }}}
309
310 // {{{ function loadOptions
311 /** The function used to load options
312 */
313 protected function loadOptions()
314 {
315 $this->options = XDB::fetchAllAssoc('id', 'SELECT ' . $this->valfield . ' AS field,
316 ' . $this->idfield . ' AS id
317 FROM ' . $this->from . '
318 ' . $this->join . '
319 ' . $this->where . '
320 GROUP BY ' . $this->valfield . '
321 ORDER BY ' . $this->valfield);
322 }
323 // }}}
324 }
325 // }}}
326
327 // {{{ class DE_WithSuboption
328 /** A class for DirEnum with possibility to select only suboptions for a given parameter (country, school, ...)
329 */
330 abstract class DE_WithSuboption extends DirEnumeration
331 {
332 protected $optfield;
333
334 protected $suboptions = null;
335
336 protected function loadOptions()
337 {
338 $opts = XDB::fetchAllAssoc('id', 'SELECT ' . $this->valfield . ' AS field,
339 ' . $this->optfield . ' AS subid,
340 ' . $this->idfield . ' AS id
341 FROM ' . $this->from . '
342 ' . $this->join . '
343 ' . $this->where . '
344 GROUP BY ' . $this->valfield . '
345 ORDER BY ' . $this->valfield);
346 $this->options = array();
347 $this->suboptions = array();
348 foreach ($opts as $id => $opt) {
349 $this->options[$id] = $opt['field'];
350 if (!array_key_exists($opt['subid'], $this->suboptions)) {
351 $this->suboptions[$opt['subid']] = array();
352 }
353 $this->suboptions[$opt['subid']][$id] = $opt['field'];
354 }
355 }
356
357 public function getOptions($subid = null)
358 {
359 $this->_fetchOptions();
360 if ($subid == null) {
361 return $this->options;
362 } else if (array_key_exists($subid, $this->suboptions)) {
363 return $this->suboptions[$subid];
364 } else {
365 return array();
366 }
367 }
368
369 public function getOptionsIter($subid = null)
370 {
371 return PlIteratorUtils::fromArray(self::expandArray($this->getOptions($subid)), 1, true);
372 }
373
374 public function getIDs($text, $mode, $subid = null)
375 {
376 if ($mode == XDB::WILDCARD_EXACT) {
377 $options = $this->getOptions($subid);
378 return array_keys($options, $text);
379 } else {
380 if ($this->where == null) {
381 $where = 'WHERE ';
382 } else {
383 $where = $this->where . ' AND ';
384 }
385 if ($subid != null && array_key_exists($subid, $this->suboptions)) {
386 $where .= XDB::format($this->optfield . ' = {?} AND ', $subid);
387 }
388
389 $conds = array();
390 $conds[] = $this->valfield . XDB::formatWildcards($mode, $text);
391 if ($this->valfield2 != null) {
392 $conds[] = $this->valfield2 . XDB::formatWildcards($mode, $text);
393 }
394 $where .= '(' . implode(' OR ', $conds) . ')';
395
396 return XDB::fetchColumn('SELECT ' . $this->idfield . '
397 FROM ' . $this->from . '
398 ' . $this->join . '
399 ' . $where . '
400 GROUP BY ' . $this->idfield);
401 }
402 }
403
404 public function getAutoComplete($text, $subid = null)
405 {
406 $text = str_replace(array('%', '_'), '', $text);
407
408 if (is_null($this->ac_where) || $this->ac_where == '') {
409 $where = '';
410 } else {
411 $where = $this->ac_where . ' AND ';
412 }
413
414 if ($subid != null && array_key_exists($subid, $this->suboptions)) {
415 $where .= XDB::format($this->optfield . ' = {?} AND ', $subid);
416 }
417
418 $tests = $this->mkTests($this->valfield, $text);
419 if (!is_null($this->valfield2)) {
420 $tests = array_merge($tests, $this->mkTests($this->valfield2, $text));
421 }
422
423 $where .= '(' . implode(' OR ', $tests) . ')';
424
425 return XDB::iterator('SELECT ' . $this->valfield . ' AS field'
426 . ($this->ac_distinct ? (', COUNT(DISTINCT ' . $this->ac_unique . ') AS nb') : '')
427 . ($this->ac_withid ? (', ' . $this->idfield . ' AS id') : '') . '
428 FROM ' . $this->from . '
429 ' . $this->ac_join . '
430 WHERE ' . $where . '
431 GROUP BY ' . $this->valfield . '
432 ORDER BY ' . ($this->ac_distinct ? 'nb DESC' : $this->valfield) . '
433 LIMIT ' . self::AUTOCOMPLETE_LIMIT);
434 }
435 }
436 // }}}
437
438 // {{{ class DE_NameTypes
439 // returns 'system' names ('lastname', 'lastname_marital', ...)
440 class DE_NameTypes extends DirEnumeration
441 {
442 public $capabilities = 0x005; // self::HAS_OPTIONS | self::SAVE_IN_SESSION;
443
444 protected $from = 'profile_name_enum';
445 protected $valfield = 'type';
446 }
447 // }}}
448
449 // {{{ class DE_Names
450 // returns 'system' names ('lastname', 'lastname_marital', ...)
451 class DE_Names extends DirEnumeration
452 {
453 public $capabilities = 0x005; // self::HAS_OPTIONS | self::SAVE_IN_SESSION;
454
455 protected $from = 'profile_name_enum';
456 protected $idfield = 'type';
457 protected $valfield = 'name';
458 }
459 // }}}
460
461 /** GROUPS
462 */
463 // {{{ class DE_Binets
464 class DE_Binets extends DirEnumeration
465 {
466 protected $from = 'profile_binet_enum';
467
468 protected $ac_join = 'INNER JOIN profile_binets ON (profile_binet_enum.id = profile_binets.binet_id)';
469 protected $ac_unique = 'profile_binets.pid';
470 }
471 // }}}
472
473 // {{{ class DE_Sections
474 class DE_Sections extends DirEnumeration
475 {
476 protected $from = 'profile_section_enum';
477
478 protected $ac_join = 'INNER JOIN profiles ON (profiles.section = profile_section_enum.id)';
479 protected $ac_unique = 'profiles.pid';
480 }
481 // }}}
482
483 // {{{ class DE_GroupesX
484 class DE_GroupesX extends DirEnumeration
485 {
486 protected $idfield = 'groups.id';
487 protected $valfield = 'groups.nom';
488 protected $valfield2 = 'groups.diminutif';
489 protected $from = 'groups';
490 protected $where = 'WHERE (cat = \'GroupesX\' OR cat = \'Institutions\') AND pub = \'public\'';
491
492 protected $ac_join = "INNER JOIN group_members ON (groups.id = group_members.asso_id
493 AND (groups.cat = 'GroupesX' OR groups.cat = 'Institutions')
494 AND groups.pub = 'public')";
495 protected $ac_unique = 'group_members.uid';
496 }
497 // }}}
498
499 /** EDUCATION
500 */
501 // {{{ class DE_EducationSchools
502 class DE_EducationSchools extends DirEnumeration
503 {
504 protected $ac_beginwith = false;
505 protected $idfield = 'profile_education_enum.id';
506 protected $valfield = 'profile_education_enum.name';
507 protected $valfield2 = 'profile_education_enum.abbreviation';
508 protected $from = 'profile_education_enum';
509
510 protected $ac_join = 'INNER JOIN profile_education ON (profile_education.eduid = profile_education_enum.id)';
511 protected $ac_unique = 'profile_education.pid';
512 }
513 // }}}
514
515 // {{{ class DE_EducationDegrees
516 class DE_EducationDegrees extends DirEnumeration
517 {
518 public $capabilities = self::HAS_OPTIONS;
519
520 protected $idfield = 'profile_education_degree.degreeid';
521 protected $optfield = 'profile_education_degree.eduid';
522 protected $valfield = 'profile_education_degree_enum.degree';
523 protected $from = 'profile_education_degree_enum';
524 protected $join = 'INNER JOIN profile_education_degree ON (profile_education_degree.degreeid = profile_education_degree_enum.id)';
525
526 }
527 // }}}
528
529 // {{{ class DE_EducationFields
530 class DE_EducationFields extends DirEnumeration
531 {
532 protected $valfield = 'profile_education_field_enum.field';
533 protected $from = 'profile_education_field_enum';
534
535 protected $ac_join = 'INNER JOIN profile_education ON (profile_education.fieldid = profile_education_field_enum.id)';
536 protected $ac_unique = 'profile_education.pid';
537 }
538 // }}}
539
540 // {{{ class DE_CurrentCorps
541 class DE_CurrentCorps extends DirEnumeration
542 {
543 protected $idfield = 'profile_corps_enum.id';
544 protected $valfield = 'profile_corps_enum.name';
545 protected $valfield2 = 'profile_corps_enum.abbrev';
546 protected $from = 'profile_corps_enum';
547 protected $where = 'WHERE profile_corps_enum.still_exists = 1';
548
549 protected $ac_unique = 'profile_corps.pid';
550 protected $ac_join = 'INNER JOIN profile_corps ON (profile_corps.current_corpsid = profile_corps_enum.id)';
551 }
552 // }}}
553 //
554 // {{{ class DE_OriginCorps
555 class DE_OriginCorps extends DirEnumeration
556 {
557 protected $idfield = 'profile_corps_enum.id';
558 protected $valfield = 'profile_corps_enum.name';
559 protected $valfield2 = 'profile_corps_enum.abbrev';
560 protected $from = 'profile_corps_enum';
561
562 protected $ac_unique = 'profile_corps.pid';
563 protected $ac_join = 'INNER JOIN profile_corps ON (profile_corps.original_corpsid = profile_corps_enum.id)';
564 }
565 // }}}
566
567 // {{{ class DE_CorpsRanks
568 class DE_CorpsRanks extends DirEnumeration
569 {
570 protected $idfield = 'profile_corps_rank_enum.id';
571 protected $valfield = 'profile_corps_rank_enum.name';
572 protected $valfield2 = 'profile_corps_rank_enum.abbrev';
573 protected $from = 'profile_corps_rank_enum';
574
575 protected $ac_unique = 'profile_corps.pid';
576 protected $ac_join = 'INNER JOIN profile_corps ON (profile_corps.rankid = profile_corps_rank_enum.id)';
577 }
578 // }}}
579
580 /** GEOLOC
581 */
582 // {{{ class DE_Nationalities
583 class DE_Nationalities extends DirEnumeration
584 {
585 protected $idfield = 'geoloc_countries.iso_3166_1_a2';
586 protected $valfield = 'geoloc_countries.nationality';
587 protected $valfield2 = 'geoloc_countries.nationalityEn';
588 protected $from = 'geoloc_countries';
589 protected $join = 'INNER JOIN profiles ON (geoloc_countries.iso_3166_1_a2 IN (profiles.nationality1, profiles.nationality2, profiles.nationality3))';
590
591 protected $ac_join = 'INNER JOIN profiles ON (geoloc_countries.iso_3166_1_a2 IN (profiles.nationality1, profiles.nationality2, profiles.nationality3))';
592 protected $ac_unique = 'profiles.pid';
593 }
594 // }}}
595
596 // {{{ class DE_AddressesComponents
597 class DE_AddressesComponents extends DirEnumeration
598 {
599 protected $idfield = 'profile_addresses_components_enum.id';
600 protected $valfield = 'profile_addresses_components_enum.long_name';
601 protected $from = 'profile_addresses_components_enum';
602
603 protected $ac_join = 'INNER JOIN profile_addresses_components ON (profile_addresses_components.component_id = profile_addresses_components_enum.id)';
604 protected $ac_unique = 'profile_addresses_components.pid';
605 protected $ac_where = 'profile_addresses_components.type = \'home\'';
606 }
607 // }}}
608 // {{{ class DE_AddressesComponents extensions
609 class DE_Countries extends DE_AddressesComponents
610 {
611 protected $where = 'WHERE FIND_IN_SET(\'country\', profile_addresses_components_enum.types)';
612 }
613
614 class DE_Admnistrativeareas1 extends DE_AddressesComponents
615 {
616 protected $where = 'WHERE FIND_IN_SET(\'admnistrative_area_1\', profile_addresses_components_enum.types)';
617 }
618
619 class DE_Admnistrativeareas2 extends DE_AddressesComponents
620 {
621 protected $where = 'WHERE FIND_IN_SET(\'admnistrative_area_2\', profile_addresses_components_enum.types)';
622 }
623
624 class DE_Admnistrativeareas3 extends DE_AddressesComponents
625 {
626 protected $where = 'WHERE FIND_IN_SET(\'admnistrative_area_3\', profile_addresses_components_enum.types)';
627 }
628
629 class DE_Localities extends DE_AddressesComponents
630 {
631 protected $where = 'WHERE FIND_IN_SET(\'locality\', profile_addresses_components_enum.types)';
632 }
633
634 class DE_Sublocalities extends DE_AddressesComponents
635 {
636 protected $where = 'WHERE FIND_IN_SET(\'sublocality\', profile_addresses_components_enum.types)';
637 }
638
639 // }}}
640
641 /** JOBS
642 */
643 // {{{ class DE_Companies
644 class DE_Companies extends DirEnumeration
645 {
646 protected $idfield = 'profile_job_enum.id';
647 protected $valfield = 'profile_job_enum.name';
648 protected $valfield2 = 'profile_job_enum.acronym';
649 protected $from = 'profile_job_enum';
650
651 protected $ac_join = 'INNER JOIN profile_job ON (profile_job.jobid = profile_job_enum.id)';
652 protected $ac_unique = 'profile_job.pid';
653 }
654 // }}}
655
656 // {{{ class DE_JobDescription
657 class DE_JobDescription extends DirEnumeration
658 {
659 protected $valfield = 'profile_job.description';
660 protected $from = 'profile_job';
661 protected $idfield = 'profile_job.pid';
662
663 protected $ac_unique = 'profile_job.pid';
664 }
665 // }}}
666
667 // {{{ class DE_JobTerms
668 class DE_JobTerms extends DirEnumeration
669 {
670 // {{{ function getAutoComplete
671 public function getAutoComplete($text)
672 {
673 $tokens = JobTerms::tokenize($text.'%');
674 if (count($tokens) == 0) {
675 return PlIteratorUtils::fromArray(array());
676 }
677 $token_join = JobTerms::token_join_query($tokens, 'e');
678 return XDB::iterator('SELECT e.jtid AS id, e.full_name AS field, COUNT(DISTINCT p.pid) AS nb
679 FROM profile_job_term_enum AS e
680 INNER JOIN profile_job_term_relation AS r ON (r.jtid_1 = e.jtid)
681 INNER JOIN profile_job_term AS p ON (r.jtid_2 = p.jtid)
682 '.$token_join.'
683 GROUP BY e.jtid
684 ORDER BY nb DESC, field
685 LIMIT ' . self::AUTOCOMPLETE_LIMIT);
686 }
687 // }}}
688 }
689 // }}}
690
691 /** NETWORKING
692 */
693 // {{{ class DE_Networking
694 class DE_Networking extends DirEnumeration
695 {
696 protected $idfield = 'profile_networking_enum.nwid';
697 protected $valfield = 'profile_networking_enum.name';
698 protected $from = 'profile_networking_enum';
699
700
701 protected $ac_join = 'INNER JOIN profile_networking ON (profile_networking.nwid = profile_networking_enum.nwid)';
702 protected $ac_unique = 'profile_networking.pid';
703 }
704 // }}}
705
706 /** MEDALS
707 */
708 // {{{ class DE_Medals
709 class DE_Medals extends DirEnumeration
710 {
711 protected $from = 'profile_medal_enum';
712
713 protected $ac_join = 'INNER JOIN profile_medals ON (profile_medals.mid = profile_medal_enum.id)';
714 protected $ac_unique = 'profile_medals.pid';
715 }
716 // }}}
717
718 /** ACCOUNTS
719 */
720 // {{{ class DE_AccountTypes
721 class DE_AccountTypes extends DirEnumeration
722 {
723 public $capabilities = 0x005; // self::HAS_OPTIONS | self::SAVE_IN_SESSION;
724
725 protected $from = 'account_types';
726 protected $valfield = 'perms';
727 protected $idfield = 'type';
728 }
729 // }}}
730
731 // {{{ class DE_Skins
732 class DE_Skins extends DirEnumeration
733 {
734 public $capabilities = 0x005; // self::HAS_OPTIONS | self::SAVE_IN_SESSION;
735
736 protected $from = 'skins';
737 protected $valfield = 'name';
738 protected $idfield = 'skin_tpl';
739 }
740 // }}}
741
742 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
743 ?>