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