1962d2868fde7db23f3f6b16700e6cee86c648b5
[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 $ac_beginwith = false;
503 protected $idfield = 'profile_education_enum.id';
504 protected $valfield = 'profile_education_enum.name';
505 protected $valfield2 = 'profile_education_enum.abbreviation';
506 protected $from = 'profile_education_enum';
507
508 protected $ac_join = 'INNER JOIN profile_education ON (profile_education.eduid = profile_education_enum.id)';
509 protected $ac_unique = 'profile_education.pid';
510 }
511 // }}}
512
513 // {{{ class DE_EducationDegrees
514 class DE_EducationDegrees extends DirEnumeration
515 {
516 public $capabilities = self::HAS_OPTIONS;
517
518 protected $idfield = 'profile_education_degree.degreeid';
519 protected $optfield = 'profile_education_degree.eduid';
520 protected $valfield = 'profile_education_degree_enum.degree';
521 protected $from = 'profile_education_degree_enum';
522 protected $join = 'INNER JOIN profile_education_degree ON (profile_education_degree.degreeid = profile_education_degree_enum.id)';
523
524 }
525 // }}}
526
527 // {{{ class DE_EducationFields
528 class DE_EducationFields extends DirEnumeration
529 {
530 protected $valfield = 'profile_education_field_enum.field';
531 protected $from = 'profile_education_field_enum';
532
533 protected $ac_join = 'INNER JOIN profile_education ON (profile_education.fieldid = profile_education_field_enum.id)';
534 protected $ac_unique = 'profile_education.pid';
535 }
536 // }}}
537
538 // {{{ class DE_CurrentCorps
539 class DE_CurrentCorps extends DirEnumeration
540 {
541 protected $idfield = 'profile_corps_enum.id';
542 protected $valfield = 'profile_corps_enum.name';
543 protected $valfield2 = 'profile_corps_enum.abbrev';
544 protected $from = 'profile_corps_enum';
545 protected $where = 'WHERE profile_corps_enum.still_exists = 1';
546
547 protected $ac_unique = 'profile_corps.pid';
548 protected $ac_join = 'INNER JOIN profile_corps ON (profile_corps.current_corpsid = profile_corps_enum.id)';
549 }
550 // }}}
551 //
552 // {{{ class DE_OriginCorps
553 class DE_OriginCorps extends DirEnumeration
554 {
555 protected $idfield = 'profile_corps_enum.id';
556 protected $valfield = 'profile_corps_enum.name';
557 protected $valfield2 = 'profile_corps_enum.abbrev';
558 protected $from = 'profile_corps_enum';
559
560 protected $ac_unique = 'profile_corps.pid';
561 protected $ac_join = 'INNER JOIN profile_corps ON (profile_corps.original_corpsid = profile_corps_enum.id)';
562 }
563 // }}}
564
565 // {{{ class DE_CorpsRanks
566 class DE_CorpsRanks extends DirEnumeration
567 {
568 protected $idfield = 'profile_corps_rank_enum.id';
569 protected $valfield = 'profile_corps_rank_enum.name';
570 protected $valfield2 = 'profile_corps_rank_enum.abbrev';
571 protected $from = 'profile_corps_rank_enum';
572
573 protected $ac_unique = 'profile_corps.pid';
574 protected $ac_join = 'INNER JOIN profile_corps ON (profile_corps.rankid = profile_corps_rank_enum.id)';
575 }
576 // }}}
577
578 /** GEOLOC
579 */
580 // {{{ class DE_Nationalities
581 class DE_Nationalities extends DirEnumeration
582 {
583 protected $idfield = 'geoloc_countries.iso_3166_1_a2';
584 protected $valfield = 'geoloc_countries.nationality';
585 protected $valfield2 = 'geoloc_countries.nationalityEn';
586 protected $from = 'geoloc_countries';
587 protected $join = 'INNER JOIN profiles ON (geoloc_countries.iso_3166_1_a2 IN (profiles.nationality1, profiles.nationality2, profiles.nationality3))';
588
589 protected $ac_join = 'INNER JOIN profiles ON (geoloc_countries.iso_3166_1_a2 IN (profiles.nationality1, profiles.nationality2, profiles.nationality3))';
590 protected $ac_unique = 'profiles.pid';
591 }
592 // }}}
593
594 // {{{ class DE_Countries
595 class DE_Countries extends DirEnumeration
596 {
597 protected $idfield = 'geoloc_countries.iso_3166_1_a2';
598 protected $valfield = 'geoloc_countries.country';
599 protected $valfield2 = 'geoloc_countries.countryEn';
600 protected $from = 'geoloc_countries';
601
602 protected $ac_join = 'INNER JOIN profile_addresses ON (geoloc_countries.iso_3166_1_a2 = profile_addresses.countryId)';
603 protected $ac_unique = 'profile_addresses.pid';
604 protected $ac_where = 'profile_addresses.type = \'home\'';
605 }
606 // }}}
607
608 // {{{ class DE_AdminAreas
609 class DE_AdminAreas extends DE_WithSuboption
610 {
611 protected $idfield = 'geoloc_administrativeareas.id';
612 protected $optfield = 'geoloc_administrativeareas.country';
613 protected $valfield = 'geoloc_administrativeareas.name';
614 protected $from = 'geoloc_administrativeareas';
615
616 protected $ac_join = 'INNER JOIN profile_addresses ON (profile_addresses.administrativeAreaId = geoloc_administrativeareas.id)';
617 protected $ac_unique = 'profile_addresses.pid';
618 }
619 // }}}
620
621 // {{{ class DE_SubAdminAreas
622 class DE_SubAdminAreas extends DE_WithSuboption
623 {
624 protected $idfield = 'geoloc_subadministrativeareas.id';
625 protected $optfield = 'geoloc_subadministrativeareas.administrativearea';
626 protected $valfield = 'geoloc_subadministrativeareas.name';
627 protected $from = 'geoloc_subadministrativeareas';
628
629 protected $ac_join = 'INNER JOIN profile_addresses ON (profile_addresses.subadministrativeAreaId = geoloc_subadministrativeareas.id)';
630 protected $ac_unique = 'profile_addresses.pid';
631 }
632 // }}}
633
634 // {{{ class DE_Localities
635 class DE_Localities extends DirEnumeration
636 {
637 protected $idfield = 'geoloc_localities.id';
638 protected $valfield = 'geoloc_localities.name';
639 protected $from = 'geoloc_localities';
640
641 protected $ac_join = 'INNER JOIN profile_addresses ON (profile_addresses.localityID = geoloc_localities.id)';
642 protected $ac_unique = 'profile_addresses.pid';
643 }
644 // }}}
645
646 /** JOBS
647 */
648 // {{{ class DE_Companies
649 class DE_Companies extends DirEnumeration
650 {
651 protected $idfield = 'profile_job_enum.id';
652 protected $valfield = 'profile_job_enum.name';
653 protected $valfield2 = 'profile_job_enum.acronym';
654 protected $from = 'profile_job_enum';
655
656 protected $ac_join = 'INNER JOIN profile_job ON (profile_job.jobid = profile_job_enum.id)';
657 protected $ac_unique = 'profile_job.pid';
658 }
659 // }}}
660
661 // {{{ class DE_JobDescription
662 class DE_JobDescription extends DirEnumeration
663 {
664 protected $valfield = 'profile_job.description';
665 protected $from = 'profile_job';
666 protected $idfield = 'profile_job.pid';
667
668 protected $ac_unique = 'profile_job.pid';
669 }
670 // }}}
671
672 // {{{ class DE_JobTerms
673 class DE_JobTerms extends DirEnumeration
674 {
675 // {{{ function getAutoComplete
676 public function getAutoComplete($text)
677 {
678 $tokens = JobTerms::tokenize($text.'%');
679 if (count($tokens) == 0) {
680 return PlIteratorUtils::fromArray(array());
681 }
682 $token_join = JobTerms::token_join_query($tokens, 'e');
683 return XDB::iterator('SELECT e.jtid AS id, e.full_name AS field, COUNT(DISTINCT p.pid) AS nb
684 FROM profile_job_term_enum AS e
685 INNER JOIN profile_job_term_relation AS r ON (r.jtid_1 = e.jtid)
686 INNER JOIN profile_job_term AS p ON (r.jtid_2 = p.jtid)
687 '.$token_join.'
688 GROUP BY e.jtid
689 ORDER BY nb DESC, field
690 LIMIT ' . self::AUTOCOMPLETE_LIMIT);
691 }
692 // }}}
693 }
694 // }}}
695
696 /** NETWORKING
697 */
698 // {{{ class DE_Networking
699 class DE_Networking extends DirEnumeration
700 {
701 protected $idfield = 'profile_networking_enum.nwid';
702 protected $valfield = 'profile_networking_enum.name';
703 protected $from = 'profile_networking_enum';
704
705
706 protected $ac_join = 'INNER JOIN profile_networking ON (profile_networking.nwid = profile_networking_enum.nwid)';
707 protected $ac_unique = 'profile_networking.pid';
708 }
709 // }}}
710
711 /** MEDALS
712 */
713 // {{{ class DE_Medals
714 class DE_Medals extends DirEnumeration
715 {
716 protected $from = 'profile_medal_enum';
717
718 protected $ac_join = 'INNER JOIN profile_medals ON (profile_medals.mid = profile_medal_enum.id)';
719 protected $ac_unique = 'profile_medals.pid';
720 }
721 // }}}
722
723 /** ACCOUNTS
724 */
725 // {{{ class DE_AccountTypes
726 class DE_AccountTypes extends DirEnumeration
727 {
728 public $capabilities = 0x005; // self::HAS_OPTIONS | self::SAVE_IN_SESSION;
729
730 protected $from = 'account_types';
731 protected $valfield = 'perms';
732 protected $idfield = 'type';
733 }
734 // }}}
735
736 // {{{ class DE_Skins
737 class DE_Skins extends DirEnumeration
738 {
739 public $capabilities = 0x005; // self::HAS_OPTIONS | self::SAVE_IN_SESSION;
740
741 protected $from = 'skins';
742 protected $valfield = 'name';
743 protected $idfield = 'skin_tpl';
744 }
745 // }}}
746
747 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
748 ?>