Changes geocoding engine to gmaps v3.
[platal.git] / classes / direnum.php
CommitLineData
e39e72a6
RB
1<?php
2/***************************************************************************
12262f13 3 * Copyright (C) 2003-2011 Polytechnique.org *
e39e72a6
RB
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
00f25ab1
SJ
43 const CURRENTCORPS = 'currentcorps';
44 const ORIGINCORPS = 'origincorps';
7f7ef715
RB
45 const CORPSRANKS = 'corpsranks';
46
21b67462
RB
47 const NATIONALITIES = 'nationalities';
48 const COUNTRIES = 'countries';
5ab3ef57 49 const ADMINAREAS = 'adminareas';
86ab1c8f 50 const SUBADMINAREAS = 'subadminareas';
5ab3ef57
RB
51 const LOCALITIES = 'localities';
52
53 const COMPANIES = 'companies';
5ab3ef57 54 const JOBDESCRIPTION = 'jobdescription';
3ac45f10 55 const JOBTERMS = 'jobterms';
5ab3ef57 56
21b67462 57 const NETWORKS = 'networking';
e39e72a6 58
3ad5702f
RB
59 const MEDALS = 'medals';
60
20b087ff 61 const ACCOUNTTYPES = 'accounttypes';
b47cc6f0 62 const SKINS = 'skins';
20b087ff 63
e39e72a6
RB
64 static private $enumerations = array();
65
66 static private function init($type)
67 {
5b98acfa 68 if (Platal::globals()->cacheEnabled() && S::has('__DE_' . $type)) {
cf570028
FB
69 self::$enumerations[$type] = S::v('__DE_' . $type);
70 } else {
71 $cls = "DE_" . ucfirst($type);
72 $obj = new $cls();
73 self::$enumerations[$type] = $obj;
5b98acfa
FB
74 if (Platal::globals()->cacheEnabled()
75 && $obj->capabilities & DirEnumeration::SAVE_IN_SESSION) {
cf570028
FB
76 S::set('__DE_' . $type, $obj);
77 }
78 }
e39e72a6
RB
79 }
80
81 /** Retrieves all options for a given type
82 * @param $type Type of enum for which options are requested
2998edf1 83 * @return Array of the results
e39e72a6 84 */
cf570028 85 static public function getOptions($type)
e39e72a6 86 {
e39e72a6
RB
87 if (!array_key_exists($type, self::$enumerations)) {
88 self::init($type);
89 }
90 $obj = self::$enumerations[$type];
2998edf1 91 if ($obj->capabilities & DirEnumeration::HAS_OPTIONS) {
cf570028 92 return call_user_func(array($obj, 'getOptions'));
2998edf1
RB
93 } else {
94 return array();
95 }
e39e72a6 96 }
21b67462 97
a137e407
RB
98 /** Retrieves all options for a given type
99 * @param $type Type of enum for which options are requested
2998edf1 100 * @return PlIterator over the results
a137e407 101 */
cf570028 102 static public function getOptionsIter($type)
a137e407 103 {
a137e407
RB
104 if (!array_key_exists($type, self::$enumerations)) {
105 self::init($type);
106 }
107 $obj = self::$enumerations[$type];
ffd70398
PC
108 $args = func_get_args();
109 array_shift($args);
2998edf1 110 if ($obj->capabilities & DirEnumeration::HAS_OPTIONS) {
ffd70398 111 return call_user_func_array(array($obj, 'getOptionsIter'), $args);
2998edf1
RB
112 } else {
113 return PlIteratorUtils::fromArray(array());
114 }
a137e407
RB
115 }
116
30b9ca46
RB
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
2998edf1 120 * @return PlIterator over the results
30b9ca46 121 */
cf570028 122 static public function getAutoComplete($type, $text)
30b9ca46 123 {
30b9ca46
RB
124 if (!array_key_exists($type, self::$enumerations)) {
125 self::init($type);
126 }
127 $obj = self::$enumerations[$type];
2998edf1 128 if ($obj->capabilities & DirEnumeration::HAS_AUTOCOMP) {
cf570028 129 return call_user_func(array($obj, 'getAutoComplete'), $text);
2998edf1
RB
130 } else {
131 return PlIteratorUtils::fromArray(array());
132 }
30b9ca46
RB
133 }
134
98925aab
RB
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 */
69ef14a5 140 static public function getIDs($type, $text, $mode = XDB::WILDCARD_EXACT)
21b67462 141 {
21b67462
RB
142 if (!array_key_exists($type, self::$enumerations)) {
143 self::init($type);
144 }
145 $obj = self::$enumerations[$type];
2998edf1 146 if ($obj->capabilities & DirEnumeration::HAS_OPTIONS) {
69ef14a5 147 return call_user_func(array($obj, 'getIDs'), $text, $mode);
2998edf1
RB
148 } else {
149 return array();
150 }
21b67462 151 }
69ef14a5
FB
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 {
cf570028
FB
160 $ids = self::getIDs($type, $text, $mode);
161 return array_shift($ids);
69ef14a5 162 }
e39e72a6 163}
98925aab 164// }}}
e39e72a6 165
98925aab 166// {{{ class DirEnumeration
e39e72a6
RB
167abstract class DirEnumeration
168{
2998edf1
RB
169 const AUTOCOMPLETE_LIMIT = 11;
170
171 const HAS_OPTIONS = 0x001;
172 const HAS_AUTOCOMP = 0x002;
cf570028 173 const SAVE_IN_SESSION = 0x004;
2998edf1
RB
174
175 public $capabilities = 0x003; // self::HAS_OPTIONS | self::HAS_AUTOCOMP;
176
e39e72a6
RB
177 /** An internal array of ID => optionTxt
178 */
9ed7f5bc 179 protected $options = null;
e39e72a6 180
21b67462
RB
181 /** Description of the MySQL storage of the fields
182 */
e39e72a6
RB
183 protected $idfield = 'id';
184 protected $valfield = 'text';
30b9ca46 185 protected $valfield2 = null;
e39e72a6 186 protected $from;
21b67462 187 protected $join = '';
e39e72a6
RB
188 protected $where = '';
189
30b9ca46
RB
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
9ed7f5bc
RB
199 protected function _fetchOptions()
200 {
201 if (is_null($this->options)) {
202 $this->loadOptions();
203 }
e39e72a6
RB
204 }
205
206 public function getOptions()
207 {
9ed7f5bc 208 $this->_fetchOptions();
e39e72a6
RB
209 return $this->options;
210 }
211
2998edf1 212 public function getOptionsIter()
a137e407 213 {
70bcaa84
FB
214 $options = $this->getOptions();
215 $options = self::expandArray($options);
216 return PlIteratorUtils::fromArray($options, 1, true);
a137e407
RB
217 }
218
30b9ca46 219 // {{{ function getIDs
21b67462
RB
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 {
658b4c83 227 if ($mode == XDB::WILDCARD_EXACT) {
21b67462
RB
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 }
30b9ca46 236 $conds = array();
658b4c83 237 $conds[] = $this->valfield . XDB::formatWildcards($mode, $text);
30b9ca46 238 if ($this->valfield2 != null) {
658b4c83 239 $conds[] = $this->valfield2 . XDB::formatWildcards($mode, $text);
30b9ca46
RB
240 }
241 $where .= '(' . implode(' OR ', $conds) . ')';
242
21b67462
RB
243 return XDB::fetchColumn('SELECT ' . $this->idfield . '
244 FROM ' . $this->from . '
245 ' . $this->join . '
30b9ca46 246 ' . $where . '
21b67462
RB
247 GROUP BY ' . $this->idfield);
248 }
249 }
30b9ca46 250 // }}}
21b67462 251
eb872b24
RB
252 /** Builds a list of query parts for searching @$text in @$field :
253 * field LIKE 'text%', field LIKE '% text%', field LIKE '%-text%'
254 */
30b9ca46
RB
255 private function mkTests($field, $text)
256 {
257 $tests = array();
658b4c83 258 $tests[] = $field . XDB::formatWildcards(XDB::WILDCARD_PREFIX, $text);
30b9ca46 259 if (!$this->ac_beginwith) {
658b4c83
RB
260 $tests[] = $field . XDB::formatWildcards(XDB::WILDCARD_CONTAINS, ' ' . $text);
261 $tests[] = $field . XDB::formatWildcards(XDB::WILDCARD_CONTAINS, '-' . $text);
30b9ca46
RB
262 }
263 return $tests;
264 }
265
2998edf1
RB
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
30b9ca46
RB
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') : '')
70bcaa84 298 . ($this->ac_withid ? (', ' . $this->idfield . ' AS id') : '') . '
30b9ca46
RB
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) . '
2998edf1 304 LIMIT ' . self::AUTOCOMPLETE_LIMIT);
30b9ca46
RB
305 }
306 // }}}
307
30b9ca46 308 // {{{ function loadOptions
e39e72a6
RB
309 /** The function used to load options
310 */
311 protected function loadOptions()
312 {
2998edf1
RB
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);
e39e72a6 320 }
30b9ca46 321 // }}}
e39e72a6 322}
98925aab 323// }}}
e39e72a6 324
2998edf1
RB
325// {{{ class DE_WithSuboption
326/** A class for DirEnum with possibility to select only suboptions for a given parameter (country, school, ...)
327 */
328abstract 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 {
ffd70398 363 return array();
2998edf1
RB
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
5c32cc1a
RB
436// {{{ class DE_NameTypes
437// returns 'system' names ('lastname', 'lastname_marital', ...)
438class DE_NameTypes extends DirEnumeration
439{
cf570028 440 public $capabilities = 0x005; // self::HAS_OPTIONS | self::SAVE_IN_SESSION;
2998edf1 441
5c32cc1a
RB
442 protected $from = 'profile_name_enum';
443 protected $valfield = 'type';
444}
445// }}}
446
b270577e
SJ
447// {{{ class DE_Names
448// returns 'system' names ('lastname', 'lastname_marital', ...)
449class 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
5ab3ef57
RB
459/** GROUPS
460 */
98925aab 461// {{{ class DE_Binets
e39e72a6
RB
462class DE_Binets extends DirEnumeration
463{
5c8a71f2 464 protected $from = 'profile_binet_enum';
30b9ca46 465
5c8a71f2 466 protected $ac_join = 'INNER JOIN profile_binets ON (profile_binet_enum.id = profile_binets.binet_id)';
bdd977d7 467 protected $ac_unique = 'profile_binets.pid';
e39e72a6 468}
98925aab
RB
469// }}}
470
471// {{{ class DE_Sections
e39e72a6
RB
472class DE_Sections extends DirEnumeration
473{
5c8a71f2 474 protected $from = 'profile_section_enum';
30b9ca46 475
5c8a71f2 476 protected $ac_join = 'INNER JOIN profiles ON (profiles.section = profile_section_enum.id)';
30b9ca46 477 protected $ac_unique = 'profiles.pid';
e39e72a6 478}
98925aab
RB
479// }}}
480
5ab3ef57
RB
481// {{{ class DE_GroupesX
482class DE_GroupesX extends DirEnumeration
483{
2998edf1
RB
484 protected $idfield = 'groups.id';
485 protected $valfield = 'groups.nom';
486 protected $valfield2 = 'groups.diminutif';
487 protected $from = 'groups';
5ab3ef57
RB
488 protected $where = 'WHERE (cat = \'GroupesX\' OR cat = \'Institutions\') AND pub = \'public\'';
489
70bcaa84 490 protected $ac_join = "INNER JOIN group_members ON (groups.id = group_members.asso_id
2998edf1
RB
491 AND (groups.cat = 'GroupesX' OR groups.cat = 'Institutions')
492 AND groups.pub = 'public')";
493 protected $ac_unique = 'group_members.uid';
5ab3ef57
RB
494}
495// }}}
496
497/** EDUCATION
498 */
fb3b6547
RB
499// {{{ class DE_EducationSchools
500class DE_EducationSchools extends DirEnumeration
e39e72a6 501{
70bcaa84 502 protected $idfield = 'profile_education_enum.id';
2998edf1
RB
503 protected $valfield = 'profile_education_enum.name';
504 protected $valfield2 = 'profile_education_enum.abbreviation';
30b9ca46
RB
505 protected $from = 'profile_education_enum';
506
507 protected $ac_join = 'INNER JOIN profile_education ON (profile_education.eduid = profile_education_enum.id)';
ce0b2c6f 508 protected $ac_unique = 'profile_education.pid';
e39e72a6 509}
98925aab
RB
510// }}}
511
fb3b6547
RB
512// {{{ class DE_EducationDegrees
513class DE_EducationDegrees extends DirEnumeration
e39e72a6 514{
2998edf1 515 public $capabilities = self::HAS_OPTIONS;
21b67462 516
2998edf1
RB
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)';
e5fb8f87 522
21b67462 523}
98925aab
RB
524// }}}
525
fb3b6547
RB
526// {{{ class DE_EducationFields
527class DE_EducationFields extends DirEnumeration
21b67462 528{
2998edf1 529 protected $valfield = 'profile_education_field_enum.field';
30b9ca46
RB
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)';
ce0b2c6f 533 protected $ac_unique = 'profile_education.pid';
e39e72a6 534}
98925aab
RB
535// }}}
536
00f25ab1
SJ
537// {{{ class DE_CurrentCorps
538class DE_CurrentCorps extends DirEnumeration
7f7ef715 539{
fe8c06e0
RB
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';
00f25ab1 544 protected $where = 'WHERE profile_corps_enum.still_exists = 1';
7f7ef715 545
fe8c06e0
RB
546 protected $ac_unique = 'profile_corps.pid';
547 protected $ac_join = 'INNER JOIN profile_corps ON (profile_corps.current_corpsid = profile_corps_enum.id)';
7f7ef715 548}
00f25ab1
SJ
549// }}}
550//
551// {{{ class DE_OriginCorps
552class 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}
7f7ef715
RB
562// }}}
563
564// {{{ class DE_CorpsRanks
565class DE_CorpsRanks extends DirEnumeration
566{
fe8c06e0
RB
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';
7f7ef715 571
fe8c06e0
RB
572 protected $ac_unique = 'profile_corps.pid';
573 protected $ac_join = 'INNER JOIN profile_corps ON (profile_corps.rankid = profile_corps_rank_enum.id)';
7f7ef715
RB
574}
575// }}}
576
5ab3ef57
RB
577/** GEOLOC
578 */
98925aab 579// {{{ class DE_Nationalities
e39e72a6
RB
580class DE_Nationalities extends DirEnumeration
581{
2998edf1 582 protected $idfield = 'geoloc_countries.iso_3166_1_a2';
2b7ead0f
SJ
583 protected $valfield = 'geoloc_countries.nationality';
584 protected $valfield2 = 'geoloc_countries.nationalityEn';
2998edf1
RB
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))';
30b9ca46 587
2998edf1 588 protected $ac_join = 'INNER JOIN profiles ON (geoloc_countries.iso_3166_1_a2 IN (profiles.nationality1, profiles.nationality2, profiles.nationality3))';
30b9ca46 589 protected $ac_unique = 'profiles.pid';
e39e72a6 590}
98925aab
RB
591// }}}
592
593// {{{ class DE_Countries
e39e72a6
RB
594class DE_Countries extends DirEnumeration
595{
2998edf1 596 protected $idfield = 'geoloc_countries.iso_3166_1_a2';
1c305d4c
SJ
597 protected $valfield = 'geoloc_countries.country';
598 protected $valfield2 = 'geoloc_countries.countryEn';
30b9ca46
RB
599 protected $from = 'geoloc_countries';
600
70bcaa84 601 protected $ac_join = 'INNER JOIN profile_addresses ON (geoloc_countries.iso_3166_1_a2 = profile_addresses.countryId)';
30b9ca46 602 protected $ac_unique = 'profile_addresses.pid';
a47c5eab 603 protected $ac_where = 'profile_addresses.type = \'home\'';
e39e72a6 604}
98925aab
RB
605// }}}
606
607// {{{ class DE_AdminAreas
2998edf1 608class DE_AdminAreas extends DE_WithSuboption
e39e72a6 609{
2998edf1
RB
610 protected $idfield = 'geoloc_administrativeareas.id';
611 protected $optfield = 'geoloc_administrativeareas.country';
612 protected $valfield = 'geoloc_administrativeareas.name';
613 protected $from = 'geoloc_administrativeareas';
9ed7f5bc 614
2998edf1
RB
615 protected $ac_join = 'INNER JOIN profile_addresses ON (profile_addresses.administrativeAreaId = geoloc_administrativeareas.id)';
616 protected $ac_unique = 'profile_addresses.pid';
e39e72a6 617}
98925aab
RB
618// }}}
619
86ab1c8f
SJ
620// {{{ class DE_SubAdminAreas
621class DE_SubAdminAreas extends DE_WithSuboption
622{
623 protected $idfield = 'geoloc_subadministrativeareas.id';
624 protected $optfield = 'geoloc_subadministrativeareas.administrativearea';
625 protected $valfield = 'geoloc_subadministrativeareas.name';
626 protected $from = 'geoloc_subadministrativeareas';
627
628 protected $ac_join = 'INNER JOIN profile_addresses ON (profile_addresses.subadministrativeAreaId = geoloc_subadministrativeareas.id)';
629 protected $ac_unique = 'profile_addresses.pid';
630}
631// }}}
632
5ab3ef57
RB
633// {{{ class DE_Localities
634class DE_Localities extends DirEnumeration
e39e72a6 635{
70bcaa84 636 protected $idfield = 'geoloc_localities.id';
2998edf1
RB
637 protected $valfield = 'geoloc_localities.name';
638 protected $from = 'geoloc_localities';
30b9ca46 639
70bcaa84 640 protected $ac_join = 'INNER JOIN profile_addresses ON (profile_addresses.localityID = geoloc_localities.id)';
2998edf1 641 protected $ac_unique = 'profile_addresses.pid';
5ab3ef57
RB
642}
643// }}}
644
645/** JOBS
646 */
647// {{{ class DE_Companies
648class DE_Companies extends DirEnumeration
649{
70bcaa84 650 protected $idfield = 'profile_job_enum.id';
2998edf1
RB
651 protected $valfield = 'profile_job_enum.name';
652 protected $valfield2 = 'profile_job_enum.acronym';
653 protected $from = 'profile_job_enum';
5ab3ef57 654
2998edf1 655 protected $ac_join = 'INNER JOIN profile_job ON (profile_job.jobid = profile_job_enum.id)';
ce0b2c6f 656 protected $ac_unique = 'profile_job.pid';
e39e72a6 657}
98925aab
RB
658// }}}
659
5ab3ef57 660// {{{ class DE_JobDescription
70bcaa84 661class DE_JobDescription extends DirEnumeration
5ab3ef57 662{
2998edf1
RB
663 protected $valfield = 'profile_job.description';
664 protected $from = 'profile_job';
665 protected $idfield = 'profile_job.pid';
5ab3ef57 666
2998edf1 667 protected $ac_unique = 'profile_job.pid';
5ab3ef57
RB
668}
669// }}}
670
3ac45f10
PC
671// {{{ class DE_JobTerms
672class DE_JobTerms extends DirEnumeration
673{
674 // {{{ function getAutoComplete
675 public function getAutoComplete($text)
676 {
677 $tokens = JobTerms::tokenize($text.'%');
678 if (count($tokens) == 0) {
679 return PlIteratorUtils::fromArray(array());
680 }
681 $token_join = JobTerms::token_join_query($tokens, 'e');
682 return XDB::iterator('SELECT e.jtid AS id, e.full_name AS field, COUNT(DISTINCT p.pid) AS nb
683 FROM profile_job_term_enum AS e
684 INNER JOIN profile_job_term_relation AS r ON (r.jtid_1 = e.jtid)
685 INNER JOIN profile_job_term AS p ON (r.jtid_2 = p.jtid)
686 '.$token_join.'
687 GROUP BY e.jtid
688 ORDER BY nb DESC, field
689 LIMIT ' . self::AUTOCOMPLETE_LIMIT);
690 }
691 // }}}
692}
693// }}}
694
5ab3ef57
RB
695/** NETWORKING
696 */
98925aab 697// {{{ class DE_Networking
e39e72a6
RB
698class DE_Networking extends DirEnumeration
699{
1f5cd004 700 protected $idfield = 'profile_networking_enum.nwid';
30b9ca46 701 protected $valfield = 'profile_networking_enum.name';
e39e72a6 702 protected $from = 'profile_networking_enum';
30b9ca46
RB
703
704
1f5cd004 705 protected $ac_join = 'INNER JOIN profile_networking ON (profile_networking.nwid = profile_networking_enum.nwid)';
ce0b2c6f 706 protected $ac_unique = 'profile_networking.pid';
e39e72a6 707}
98925aab 708// }}}
69ef14a5 709
eb872b24
RB
710/** MEDALS
711 */
712// {{{ class DE_Medals
713class DE_Medals extends DirEnumeration
714{
715 protected $from = 'profile_medal_enum';
716
717 protected $ac_join = 'INNER JOIN profile_medals ON (profile_medals.mid = profile_medal_enum.id)';
718 protected $ac_unique = 'profile_medals.pid';
719}
720// }}}
721
20b087ff
FB
722/** ACCOUNTS
723 */
724// {{{ class DE_AccountTypes
725class DE_AccountTypes extends DirEnumeration
726{
727 public $capabilities = 0x005; // self::HAS_OPTIONS | self::SAVE_IN_SESSION;
728
729 protected $from = 'account_types';
730 protected $valfield = 'perms';
731 protected $idfield = 'type';
732}
733// }}}
734
b47cc6f0
FB
735// {{{ class DE_Skins
736class DE_Skins extends DirEnumeration
737{
738 public $capabilities = 0x005; // self::HAS_OPTIONS | self::SAVE_IN_SESSION;
739
740 protected $from = 'skins';
741 protected $valfield = 'name';
742 protected $idfield = 'skin_tpl';
743}
744// }}}
745
69ef14a5 746// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
e39e72a6 747?>