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