Moving to GitHub.
[platal.git] / classes / direnum.php
1 <?php
2 /***************************************************************************
3 * Copyright (C) 2003-2014 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 BINETS = 'binets';
33 const GROUPESX = 'groupesx';
34 const SECTIONS = 'sections';
35
36 const EDUSCHOOLS = 'educationschools';
37 const EDUDEGREES = 'educationdegrees';
38 const EDUFIELDS = 'educationfields';
39
40 const CURRENTCORPS = 'currentcorps';
41 const ORIGINCORPS = 'origincorps';
42 const CORPSRANKS = 'corpsranks';
43
44 const NATIONALITIES = 'nationalities';
45 const POSTALCODES = 'postalcodes';
46 const SUBLOCALITIES = 'sublocalities';
47 const LOCALITIES = 'localities';
48 const ADMNISTRATIVEAREAS3 = 'admnistrativeareas3';
49 const ADMNISTRATIVEAREAS2 = 'admnistrativeareas2';
50 const ADMNISTRATIVEAREAS1 = 'admnistrativeareas1';
51 const COUNTRIES = 'countries';
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, $sub_id = null)
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(array($obj, 'getAutoComplete'), array($text, $sub_id));
130 } else {
131 return 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 protected 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, $sub_id = null)
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::fetchAllAssoc('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 _fetchSubOptions($subid)
335 {
336 if (is_null($this->suboptions)) {
337 $this->loadSubOptions($subid);
338 }
339 }
340
341 protected function loadSubOptions($subid)
342 {
343 $where = ($this->where == '') ? '' : $this->where . ' AND ';
344 $this->suboptions = XDB::fetchAllAssoc('id', 'SELECT ' . $this->valfield . ' AS field,
345 ' . $this->idfield . ' AS id
346 FROM ' . $this->from . '
347 ' . $this->join . '
348 WHERE ' . $where . $this->optfield . ' = ' . $subid . '
349 GROUP BY ' . $this->valfield . '
350 ORDER BY ' . $this->valfield);
351 }
352
353 public function getOptions($subid = null)
354 {
355 if ($subid == null) {
356 $this->_fetchOptions();
357 return $this->options;
358 }
359
360 $this->_fetchSubOptions($subid);
361 if (is_array($this->suboptions)) {
362 return $this->suboptions;
363 }
364
365 return array();
366 }
367
368 public function getOptionsIter($subid = null)
369 {
370 return PlIteratorUtils::fromArray(self::expandArray($this->getOptions($subid)), 1, true);
371 }
372
373 public function getIDs($text, $mode, $subid = null)
374 {
375 if ($mode == XDB::WILDCARD_EXACT) {
376 $options = $this->getOptions($subid);
377 return array_keys($options, $text);
378 } else {
379 if ($this->where == null) {
380 $where = 'WHERE ';
381 } else {
382 $where = $this->where . ' AND ';
383 }
384 if ($subid != null && array_key_exists($subid, $this->suboptions)) {
385 $where .= XDB::format($this->optfield . ' = {?} AND ', $subid);
386 }
387
388 $conds = array();
389 $conds[] = $this->valfield . XDB::formatWildcards($mode, $text);
390 if ($this->valfield2 != null) {
391 $conds[] = $this->valfield2 . XDB::formatWildcards($mode, $text);
392 }
393 $where .= '(' . implode(' OR ', $conds) . ')';
394
395 return XDB::fetchColumn('SELECT ' . $this->idfield . '
396 FROM ' . $this->from . '
397 ' . $this->join . '
398 ' . $where . '
399 GROUP BY ' . $this->idfield);
400 }
401 }
402
403 public function getAutoComplete($text, $subid = null)
404 {
405 $text = str_replace(array('%', '_'), '', $text);
406
407 if (is_null($this->ac_where) || $this->ac_where == '') {
408 $where = '';
409 } else {
410 $where = $this->ac_where . ' AND ';
411 }
412
413 if ($subid != null && array_key_exists($subid, $this->suboptions)) {
414 $where .= XDB::format($this->optfield . ' = {?} AND ', $subid);
415 }
416
417 $tests = $this->mkTests($this->valfield, $text);
418 if (!is_null($this->valfield2)) {
419 $tests = array_merge($tests, $this->mkTests($this->valfield2, $text));
420 }
421
422 $where .= '(' . implode(' OR ', $tests) . ')';
423
424 return XDB::fetchAllAssoc('SELECT ' . $this->valfield . ' AS field'
425 . ($this->ac_distinct ? (', COUNT(DISTINCT ' . $this->ac_unique . ') AS nb') : '')
426 . ($this->ac_withid ? (', ' . $this->idfield . ' AS id') : '') . '
427 FROM ' . $this->from . '
428 ' . $this->ac_join . '
429 WHERE ' . $where . '
430 GROUP BY ' . $this->valfield . '
431 ORDER BY ' . ($this->ac_distinct ? 'nb DESC' : $this->valfield) . '
432 LIMIT ' . self::AUTOCOMPLETE_LIMIT);
433 }
434 }
435 // }}}
436
437 /** GROUPS
438 */
439 // {{{ class DE_Binets
440 class DE_Binets extends DirEnumeration
441 {
442 protected $from = 'profile_binet_enum';
443
444 protected $ac_join = 'INNER JOIN profile_binets ON (profile_binet_enum.id = profile_binets.binet_id)';
445 protected $ac_unique = 'profile_binets.pid';
446 }
447 // }}}
448
449 // {{{ class DE_Sections
450 class DE_Sections extends DirEnumeration
451 {
452 protected $from = 'profile_section_enum';
453
454 protected $ac_join = 'INNER JOIN profiles ON (profiles.section = profile_section_enum.id)';
455 protected $ac_unique = 'profiles.pid';
456 }
457 // }}}
458
459 // {{{ class DE_GroupesX
460 class DE_GroupesX extends DirEnumeration
461 {
462 protected $idfield = 'groups.id';
463 protected $valfield = 'groups.nom';
464 protected $valfield2 = 'groups.diminutif';
465 protected $from = 'groups';
466 protected $where = 'WHERE (cat = \'GroupesX\' OR cat = \'Institutions\') AND pub = \'public\'';
467
468 protected $ac_join = "INNER JOIN group_members ON (groups.id = group_members.asso_id
469 AND (groups.cat = 'GroupesX' OR groups.cat = 'Institutions')
470 AND groups.pub = 'public')";
471 protected $ac_unique = 'group_members.uid';
472 }
473 // }}}
474
475 /** EDUCATION
476 */
477 // {{{ class DE_EducationSchools
478 class DE_EducationSchools extends DirEnumeration
479 {
480 protected $ac_beginwith = false;
481 protected $idfield = 'profile_education_enum.id';
482 protected $valfield = 'profile_education_enum.name';
483 protected $valfield2 = 'profile_education_enum.abbreviation';
484 protected $from = 'profile_education_enum';
485
486 protected $ac_join = 'INNER JOIN profile_education ON (profile_education.eduid = profile_education_enum.id)';
487 protected $ac_unique = 'profile_education.pid';
488 }
489 // }}}
490
491 // {{{ class DE_EducationDegrees
492 class DE_EducationDegrees extends DE_WithSuboption
493 {
494 public $capabilities = self::HAS_OPTIONS;
495
496 protected $idfield = 'profile_education_degree.degreeid';
497 protected $optfield = 'profile_education_degree.eduid';
498 protected $valfield = 'profile_education_degree_enum.degree';
499 protected $from = 'profile_education_degree_enum';
500 protected $join = 'INNER JOIN profile_education_degree ON (profile_education_degree.degreeid = profile_education_degree_enum.id)';
501
502 }
503 // }}}
504
505 // {{{ class DE_EducationFields
506 class DE_EducationFields extends DirEnumeration
507 {
508 protected $valfield = 'profile_education_field_enum.field';
509 protected $from = 'profile_education_field_enum';
510
511 protected $ac_join = 'INNER JOIN profile_education ON (profile_education.fieldid = profile_education_field_enum.id)';
512 protected $ac_unique = 'profile_education.pid';
513 }
514 // }}}
515
516 // {{{ class DE_CurrentCorps
517 class DE_CurrentCorps extends DirEnumeration
518 {
519 protected $idfield = 'profile_corps_enum.id';
520 protected $valfield = 'profile_corps_enum.name';
521 protected $valfield2 = 'profile_corps_enum.abbrev';
522 protected $from = 'profile_corps_enum';
523 protected $where = 'WHERE profile_corps_enum.still_exists = 1';
524
525 protected $ac_unique = 'profile_corps.pid';
526 protected $ac_join = 'INNER JOIN profile_corps ON (profile_corps.current_corpsid = profile_corps_enum.id)';
527 }
528 // }}}
529 //
530 // {{{ class DE_OriginCorps
531 class DE_OriginCorps extends DirEnumeration
532 {
533 protected $idfield = 'profile_corps_enum.id';
534 protected $valfield = 'profile_corps_enum.name';
535 protected $valfield2 = 'profile_corps_enum.abbrev';
536 protected $from = 'profile_corps_enum';
537
538 protected $ac_unique = 'profile_corps.pid';
539 protected $ac_join = 'INNER JOIN profile_corps ON (profile_corps.original_corpsid = profile_corps_enum.id)';
540 }
541 // }}}
542
543 // {{{ class DE_CorpsRanks
544 class DE_CorpsRanks extends DirEnumeration
545 {
546 protected $idfield = 'profile_corps_rank_enum.id';
547 protected $valfield = 'profile_corps_rank_enum.name';
548 protected $valfield2 = 'profile_corps_rank_enum.abbrev';
549 protected $from = 'profile_corps_rank_enum';
550
551 protected $ac_unique = 'profile_corps.pid';
552 protected $ac_join = 'INNER JOIN profile_corps ON (profile_corps.rankid = profile_corps_rank_enum.id)';
553 }
554 // }}}
555
556 /** GEOLOC
557 */
558 // {{{ class DE_Nationalities
559 class DE_Nationalities extends DirEnumeration
560 {
561 protected $idfield = 'geoloc_countries.iso_3166_1_a2';
562 protected $valfield = 'geoloc_countries.nationality';
563 protected $valfield2 = 'geoloc_countries.nationalityEn';
564 protected $from = 'geoloc_countries';
565 protected $join = 'INNER JOIN profiles ON (geoloc_countries.iso_3166_1_a2 IN (profiles.nationality1, profiles.nationality2, profiles.nationality3))';
566
567 protected $ac_join = 'INNER JOIN profiles ON (geoloc_countries.iso_3166_1_a2 IN (profiles.nationality1, profiles.nationality2, profiles.nationality3))';
568 protected $ac_unique = 'profiles.pid';
569 }
570 // }}}
571
572 // {{{ class DE_AddressesComponents
573 class DE_AddressesComponents extends DirEnumeration
574 {
575 protected $idfield = 'profile_addresses_components_enum.id';
576 protected $valfield = 'profile_addresses_components_enum.long_name';
577 protected $from = 'profile_addresses_components_enum';
578
579 protected $ac_join = 'INNER JOIN profile_addresses_components ON (profile_addresses_components.component_id = profile_addresses_components_enum.id)';
580 protected $ac_unique = 'profile_addresses_components.pid';
581 }
582 // }}}
583 // {{{ class DE_AddressesComponents extensions
584 class DE_Countries extends DE_AddressesComponents
585 {
586 protected $where = 'WHERE FIND_IN_SET(\'country\', profile_addresses_components_enum.types)';
587 protected $ac_where = 'profile_addresses_components.type = \'home\' AND FIND_IN_SET(\'country\', profile_addresses_components_enum.types)';
588 }
589
590 class DE_Admnistrativeareas1 extends DE_AddressesComponents
591 {
592 protected $where = 'WHERE FIND_IN_SET(\'admnistrative_area_1\', profile_addresses_components_enum.types)';
593 protected $ac_where = 'profile_addresses_components.type = \'home\' AND FIND_IN_SET(\'admnistrative_area_1\', profile_addresses_components_enum.types)';
594 }
595
596 class DE_Admnistrativeareas2 extends DE_AddressesComponents
597 {
598 protected $where = 'WHERE FIND_IN_SET(\'admnistrative_area_2\', profile_addresses_components_enum.types)';
599 protected $ac_where = 'profile_addresses_components.type = \'home\' AND FIND_IN_SET(\'admnistrative_area_2\', profile_addresses_components_enum.types)';
600 }
601
602 class DE_Admnistrativeareas3 extends DE_AddressesComponents
603 {
604 protected $where = 'WHERE FIND_IN_SET(\'admnistrative_area_3\', profile_addresses_components_enum.types)';
605 protected $ac_where = 'profile_addresses_components.type = \'home\' AND FIND_IN_SET(\'admnistrative_area_3\', profile_addresses_components_enum.types)';
606 }
607
608 class DE_Localities extends DE_AddressesComponents
609 {
610 protected $where = 'WHERE FIND_IN_SET(\'locality\', profile_addresses_components_enum.types)';
611 protected $ac_where = 'profile_addresses_components.type = \'home\' AND FIND_IN_SET(\'locality\', profile_addresses_components_enum.types)';
612
613 // {{{ function getAutoComplete
614 public function getAutoComplete($text, $sub_id = null)
615 {
616 if (is_null($sub_id)) {
617 return parent::getAutoComplete($text);
618 } else {
619 $tests = $this->mkTests('pace1.long_name', $text);
620 $where .= '(' . implode(' OR ', $tests) . ')';
621 $query = "SELECT pace1.id AS id, pace1.long_name AS field, COUNT(DISTINCT(pac1.pid)) AS nb
622 FROM profile_addresses_components_enum AS pace1
623 INNER JOIN profile_addresses_components AS pac1 ON (pac1.component_id = pace1.id)
624 INNER JOIN profile_addresses_components AS pac2 ON (pac1.pid = pac2.pid AND pac1.jobid = pac2.jobid AND pac1.id = pac2.id
625 AND pac1.groupid = pac2.groupid AND pac1.type = pac2.type)
626 INNER JOIN profile_addresses_components_enum AS pace2 ON (pac2.component_id = pace2.id AND FIND_IN_SET('country', pace2.types))
627 WHERE pace2.id = {?} AND FIND_IN_SET('locality', pace1.types) AND pac1.type = 'home' AND " . $where . "
628 GROUP BY pace1.long_name
629 ORDER BY nb DESC, field
630 LIMIT " . self::AUTOCOMPLETE_LIMIT;
631 return XDB::fetchAllAssoc($query, $sub_id);
632 }
633 }
634 // }}}
635
636 }
637
638 class DE_Sublocalities extends DE_AddressesComponents
639 {
640 protected $where = 'WHERE FIND_IN_SET(\'sublocality\', profile_addresses_components_enum.types)';
641 protected $ac_where = 'profile_addresses_components.type = \'home\' AND FIND_IN_SET(\'sublocality\', profile_addresses_components_enum.types)';
642 }
643
644 class DE_Postalcodes extends DE_AddressesComponents
645 {
646 protected $where = 'WHERE FIND_IN_SET(\'postal_code\', profile_addresses_components_enum.types)';
647 protected $ac_where = 'profile_addresses_components.type = \'home\' AND FIND_IN_SET(\'postal_code\', profile_addresses_components_enum.types)';
648 }
649
650 // }}}
651
652 /** JOBS
653 */
654 // {{{ class DE_Companies
655 class DE_Companies extends DirEnumeration
656 {
657 protected $idfield = 'profile_job_enum.id';
658 protected $valfield = 'profile_job_enum.name';
659 protected $valfield2 = 'profile_job_enum.acronym';
660 protected $from = 'profile_job_enum';
661
662 protected $ac_join = 'INNER JOIN profile_job ON (profile_job.jobid = profile_job_enum.id)';
663 protected $ac_unique = 'profile_job.pid';
664 }
665 // }}}
666
667 // {{{ class DE_JobDescription
668 class DE_JobDescription extends DirEnumeration
669 {
670 protected $valfield = 'profile_job.description';
671 protected $from = 'profile_job';
672 protected $idfield = 'profile_job.pid';
673
674 protected $ac_unique = 'profile_job.pid';
675 }
676 // }}}
677
678 // {{{ class DE_JobTerms
679 class DE_JobTerms extends DirEnumeration
680 {
681 protected $valfield = 'profile_job_term_enum.name';
682 protected $from = 'profile_job_term_enum';
683 protected $idfield = 'profile_job_term_enum.jtid';
684
685 // {{{ function getAutoComplete
686 public function getAutoComplete($text, $sub_id = null)
687 {
688 $tokens = JobTerms::tokenize($text.'%');
689 if (count($tokens) == 0) {
690 return array();
691 }
692 $token_join = JobTerms::token_join_query($tokens, 'e');
693 return XDB::fetchAllAssoc('SELECT e.jtid AS id, e.full_name AS field, COUNT(DISTINCT p.pid) AS nb
694 FROM profile_job_term_enum AS e
695 INNER JOIN profile_job_term_relation AS r ON (r.jtid_1 = e.jtid)
696 INNER JOIN profile_job_term AS p ON (r.jtid_2 = p.jtid)
697 '.$token_join.'
698 GROUP BY e.jtid
699 ORDER BY nb DESC, field
700 LIMIT ' . self::AUTOCOMPLETE_LIMIT);
701 }
702 // }}}
703 }
704 // }}}
705
706 /** NETWORKING
707 */
708 // {{{ class DE_Networking
709 class DE_Networking extends DirEnumeration
710 {
711 protected $idfield = 'profile_networking_enum.nwid';
712 protected $valfield = 'profile_networking_enum.name';
713 protected $from = 'profile_networking_enum';
714
715
716 protected $ac_join = 'INNER JOIN profile_networking ON (profile_networking.nwid = profile_networking_enum.nwid)';
717 protected $ac_unique = 'profile_networking.pid';
718 }
719 // }}}
720
721 /** MEDALS
722 */
723 // {{{ class DE_Medals
724 class DE_Medals extends DirEnumeration
725 {
726 protected $from = 'profile_medal_enum';
727
728 protected $ac_join = 'INNER JOIN profile_medals ON (profile_medals.mid = profile_medal_enum.id)';
729 protected $ac_unique = 'profile_medals.pid';
730 }
731 // }}}
732
733 /** ACCOUNTS
734 */
735 // {{{ class DE_AccountTypes
736 class DE_AccountTypes extends DirEnumeration
737 {
738 public $capabilities = 0x005; // self::HAS_OPTIONS | self::SAVE_IN_SESSION;
739
740 protected $from = 'account_types';
741 protected $valfield = 'perms';
742 protected $idfield = 'type';
743 }
744 // }}}
745
746 // {{{ class DE_Skins
747 class DE_Skins extends DirEnumeration
748 {
749 public $capabilities = 0x005; // self::HAS_OPTIONS | self::SAVE_IN_SESSION;
750
751 protected $from = 'skins';
752 protected $valfield = 'name';
753 protected $idfield = 'skin_tpl';
754 }
755 // }}}
756
757 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker fenc=utf-8:
758 ?>