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