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