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