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