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