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