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