| 1 | <?php |
| 2 | /*************************************************************************** |
| 3 | * Copyright (C) 2003-2011 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 SUBADMINAREAS = 'subadminareas'; |
| 50 | const LOCALITIES = 'localities'; |
| 51 | |
| 52 | const COMPANIES = 'companies'; |
| 53 | const JOBDESCRIPTION = 'jobdescription'; |
| 54 | const JOBTERMS = 'jobterms'; |
| 55 | |
| 56 | const NETWORKS = 'networking'; |
| 57 | |
| 58 | const MEDALS = 'medals'; |
| 59 | |
| 60 | const ACCOUNTTYPES = 'accounttypes'; |
| 61 | const SKINS = 'skins'; |
| 62 | |
| 63 | static private $enumerations = array(); |
| 64 | |
| 65 | static private function init($type) |
| 66 | { |
| 67 | if (Platal::globals()->cacheEnabled() && S::has('__DE_' . $type)) { |
| 68 | self::$enumerations[$type] = S::v('__DE_' . $type); |
| 69 | } else { |
| 70 | $cls = "DE_" . ucfirst($type); |
| 71 | $obj = new $cls(); |
| 72 | self::$enumerations[$type] = $obj; |
| 73 | if (Platal::globals()->cacheEnabled() |
| 74 | && $obj->capabilities & DirEnumeration::SAVE_IN_SESSION) { |
| 75 | S::set('__DE_' . $type, $obj); |
| 76 | } |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | /** Retrieves all options for a given type |
| 81 | * @param $type Type of enum for which options are requested |
| 82 | * @return Array of the results |
| 83 | */ |
| 84 | static public function getOptions($type) |
| 85 | { |
| 86 | if (!array_key_exists($type, self::$enumerations)) { |
| 87 | self::init($type); |
| 88 | } |
| 89 | $obj = self::$enumerations[$type]; |
| 90 | if ($obj->capabilities & DirEnumeration::HAS_OPTIONS) { |
| 91 | return call_user_func(array($obj, 'getOptions')); |
| 92 | } else { |
| 93 | return array(); |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | /** Retrieves all options for a given type |
| 98 | * @param $type Type of enum for which options are requested |
| 99 | * @return PlIterator over the results |
| 100 | */ |
| 101 | static public function getOptionsIter($type) |
| 102 | { |
| 103 | if (!array_key_exists($type, self::$enumerations)) { |
| 104 | self::init($type); |
| 105 | } |
| 106 | $obj = self::$enumerations[$type]; |
| 107 | $args = func_get_args(); |
| 108 | array_shift($args); |
| 109 | if ($obj->capabilities & DirEnumeration::HAS_OPTIONS) { |
| 110 | return call_user_func_array(array($obj, 'getOptionsIter'), $args); |
| 111 | } else { |
| 112 | return PlIteratorUtils::fromArray(array()); |
| 113 | } |
| 114 | } |
| 115 | |
| 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 |
| 119 | * @return PlIterator over the results |
| 120 | */ |
| 121 | static public function getAutoComplete($type, $text) |
| 122 | { |
| 123 | if (!array_key_exists($type, self::$enumerations)) { |
| 124 | self::init($type); |
| 125 | } |
| 126 | $obj = self::$enumerations[$type]; |
| 127 | if ($obj->capabilities & DirEnumeration::HAS_AUTOCOMP) { |
| 128 | return call_user_func(array($obj, 'getAutoComplete'), $text); |
| 129 | } else { |
| 130 | return PlIteratorUtils::fromArray(array()); |
| 131 | } |
| 132 | } |
| 133 | |
| 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 | */ |
| 139 | static public function getIDs($type, $text, $mode = XDB::WILDCARD_EXACT) |
| 140 | { |
| 141 | if (!array_key_exists($type, self::$enumerations)) { |
| 142 | self::init($type); |
| 143 | } |
| 144 | $obj = self::$enumerations[$type]; |
| 145 | if ($obj->capabilities & DirEnumeration::HAS_OPTIONS) { |
| 146 | return call_user_func(array($obj, 'getIDs'), $text, $mode); |
| 147 | } else { |
| 148 | return array(); |
| 149 | } |
| 150 | } |
| 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 | { |
| 159 | $ids = self::getIDs($type, $text, $mode); |
| 160 | return array_shift($ids); |
| 161 | } |
| 162 | } |
| 163 | // }}} |
| 164 | |
| 165 | // {{{ class DirEnumeration |
| 166 | abstract class DirEnumeration |
| 167 | { |
| 168 | const AUTOCOMPLETE_LIMIT = 11; |
| 169 | |
| 170 | const HAS_OPTIONS = 0x001; |
| 171 | const HAS_AUTOCOMP = 0x002; |
| 172 | const SAVE_IN_SESSION = 0x004; |
| 173 | |
| 174 | public $capabilities = 0x003; // self::HAS_OPTIONS | self::HAS_AUTOCOMP; |
| 175 | |
| 176 | /** An internal array of ID => optionTxt |
| 177 | */ |
| 178 | protected $options = null; |
| 179 | |
| 180 | /** Description of the MySQL storage of the fields |
| 181 | */ |
| 182 | protected $idfield = 'id'; |
| 183 | protected $valfield = 'text'; |
| 184 | protected $valfield2 = null; |
| 185 | protected $from; |
| 186 | protected $join = ''; |
| 187 | protected $where = ''; |
| 188 | |
| 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 | |
| 198 | protected function _fetchOptions() |
| 199 | { |
| 200 | if (is_null($this->options)) { |
| 201 | $this->loadOptions(); |
| 202 | } |
| 203 | } |
| 204 | |
| 205 | public function getOptions() |
| 206 | { |
| 207 | $this->_fetchOptions(); |
| 208 | return $this->options; |
| 209 | } |
| 210 | |
| 211 | public function getOptionsIter() |
| 212 | { |
| 213 | $options = $this->getOptions(); |
| 214 | $options = self::expandArray($options); |
| 215 | return PlIteratorUtils::fromArray($options, 1, true); |
| 216 | } |
| 217 | |
| 218 | // {{{ function getIDs |
| 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 | { |
| 226 | if ($mode == XDB::WILDCARD_EXACT) { |
| 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 | } |
| 235 | $conds = array(); |
| 236 | $conds[] = $this->valfield . XDB::formatWildcards($mode, $text); |
| 237 | if ($this->valfield2 != null) { |
| 238 | $conds[] = $this->valfield2 . XDB::formatWildcards($mode, $text); |
| 239 | } |
| 240 | $where .= '(' . implode(' OR ', $conds) . ')'; |
| 241 | |
| 242 | return XDB::fetchColumn('SELECT ' . $this->idfield . ' |
| 243 | FROM ' . $this->from . ' |
| 244 | ' . $this->join . ' |
| 245 | ' . $where . ' |
| 246 | GROUP BY ' . $this->idfield); |
| 247 | } |
| 248 | } |
| 249 | // }}} |
| 250 | |
| 251 | /** Builds a list of query parts for searching @$text in @$field : |
| 252 | * field LIKE 'text%', field LIKE '% text%', field LIKE '%-text%' |
| 253 | */ |
| 254 | private function mkTests($field, $text) |
| 255 | { |
| 256 | $tests = array(); |
| 257 | $tests[] = $field . XDB::formatWildcards(XDB::WILDCARD_PREFIX, $text); |
| 258 | if (!$this->ac_beginwith) { |
| 259 | $tests[] = $field . XDB::formatWildcards(XDB::WILDCARD_CONTAINS, ' ' . $text); |
| 260 | $tests[] = $field . XDB::formatWildcards(XDB::WILDCARD_CONTAINS, '-' . $text); |
| 261 | } |
| 262 | return $tests; |
| 263 | } |
| 264 | |
| 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 | |
| 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') : '') |
| 297 | . ($this->ac_withid ? (', ' . $this->idfield . ' AS id') : '') . ' |
| 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) . ' |
| 303 | LIMIT ' . self::AUTOCOMPLETE_LIMIT); |
| 304 | } |
| 305 | // }}} |
| 306 | |
| 307 | // {{{ function loadOptions |
| 308 | /** The function used to load options |
| 309 | */ |
| 310 | protected function loadOptions() |
| 311 | { |
| 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); |
| 319 | } |
| 320 | // }}} |
| 321 | } |
| 322 | // }}} |
| 323 | |
| 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 | |
| 333 | protected function loadOptions() |
| 334 | { |
| 335 | $opts = XDB::fetchAllAssoc('id', 'SELECT ' . $this->valfield . ' AS field, |
| 336 | ' . $this->optfield . ' AS subid, |
| 337 | ' . $this->idfield . ' AS id |
| 338 | FROM ' . $this->from . ' |
| 339 | ' . $this->join . ' |
| 340 | ' . $this->where . ' |
| 341 | GROUP BY ' . $this->valfield . ' |
| 342 | ORDER BY ' . $this->valfield); |
| 343 | $this->options = array(); |
| 344 | $this->suboptions = array(); |
| 345 | foreach ($opts as $id => $opt) { |
| 346 | $this->options[$id] = $opt['field']; |
| 347 | if (!array_key_exists($opt['subid'], $this->suboptions)) { |
| 348 | $this->suboptions[$opt['subid']] = array(); |
| 349 | } |
| 350 | $this->suboptions[$opt['subid']][$id] = $opt['field']; |
| 351 | } |
| 352 | } |
| 353 | |
| 354 | public function getOptions($subid = null) |
| 355 | { |
| 356 | $this->_fetchOptions(); |
| 357 | if ($subid == null) { |
| 358 | return $this->options; |
| 359 | } else if (array_key_exists($subid, $this->suboptions)) { |
| 360 | return $this->suboptions[$subid]; |
| 361 | } else { |
| 362 | return array(); |
| 363 | } |
| 364 | } |
| 365 | |
| 366 | public function getOptionsIter($subid = null) |
| 367 | { |
| 368 | return PlIteratorUtils::fromArray(self::expandArray($this->getOptions($subid)), 1, true); |
| 369 | } |
| 370 | |
| 371 | public function getIDs($text, $mode, $subid = null) |
| 372 | { |
| 373 | if ($mode == XDB::WILDCARD_EXACT) { |
| 374 | $options = $this->getOptions($subid); |
| 375 | return array_keys($options, $text); |
| 376 | } else { |
| 377 | if ($this->where == null) { |
| 378 | $where = 'WHERE '; |
| 379 | } else { |
| 380 | $where = $this->where . ' AND '; |
| 381 | } |
| 382 | if ($subid != null && array_key_exists($subid, $this->suboptions)) { |
| 383 | $where .= XDB::format($this->optfield . ' = {?} AND ', $subid); |
| 384 | } |
| 385 | |
| 386 | $conds = array(); |
| 387 | $conds[] = $this->valfield . XDB::formatWildcards($mode, $text); |
| 388 | if ($this->valfield2 != null) { |
| 389 | $conds[] = $this->valfield2 . XDB::formatWildcards($mode, $text); |
| 390 | } |
| 391 | $where .= '(' . implode(' OR ', $conds) . ')'; |
| 392 | |
| 393 | return XDB::fetchColumn('SELECT ' . $this->idfield . ' |
| 394 | FROM ' . $this->from . ' |
| 395 | ' . $this->join . ' |
| 396 | ' . $where . ' |
| 397 | GROUP BY ' . $this->idfield); |
| 398 | } |
| 399 | } |
| 400 | |
| 401 | public function getAutoComplete($text, $subid = null) |
| 402 | { |
| 403 | $text = str_replace(array('%', '_'), '', $text); |
| 404 | |
| 405 | if (is_null($this->ac_where) || $this->ac_where == '') { |
| 406 | $where = ''; |
| 407 | } else { |
| 408 | $where = $this->ac_where . ' AND '; |
| 409 | } |
| 410 | |
| 411 | if ($subid != null && array_key_exists($subid, $this->suboptions)) { |
| 412 | $where .= XDB::format($this->optfield . ' = {?} AND ', $subid); |
| 413 | } |
| 414 | |
| 415 | $tests = $this->mkTests($this->valfield, $text); |
| 416 | if (!is_null($this->valfield2)) { |
| 417 | $tests = array_merge($tests, $this->mkTests($this->valfield2, $text)); |
| 418 | } |
| 419 | |
| 420 | $where .= '(' . implode(' OR ', $tests) . ')'; |
| 421 | |
| 422 | return XDB::iterator('SELECT ' . $this->valfield . ' AS field' |
| 423 | . ($this->ac_distinct ? (', COUNT(DISTINCT ' . $this->ac_unique . ') AS nb') : '') |
| 424 | . ($this->ac_withid ? (', ' . $this->idfield . ' AS id') : '') . ' |
| 425 | FROM ' . $this->from . ' |
| 426 | ' . $this->ac_join . ' |
| 427 | WHERE ' . $where . ' |
| 428 | GROUP BY ' . $this->valfield . ' |
| 429 | ORDER BY ' . ($this->ac_distinct ? 'nb DESC' : $this->valfield) . ' |
| 430 | LIMIT ' . self::AUTOCOMPLETE_LIMIT); |
| 431 | } |
| 432 | } |
| 433 | // }}} |
| 434 | |
| 435 | // {{{ class DE_NameTypes |
| 436 | // returns 'system' names ('lastname', 'lastname_marital', ...) |
| 437 | class DE_NameTypes extends DirEnumeration |
| 438 | { |
| 439 | public $capabilities = 0x005; // self::HAS_OPTIONS | self::SAVE_IN_SESSION; |
| 440 | |
| 441 | protected $from = 'profile_name_enum'; |
| 442 | protected $valfield = 'type'; |
| 443 | } |
| 444 | // }}} |
| 445 | |
| 446 | // {{{ class DE_Names |
| 447 | // returns 'system' names ('lastname', 'lastname_marital', ...) |
| 448 | class DE_Names extends DirEnumeration |
| 449 | { |
| 450 | public $capabilities = 0x005; // self::HAS_OPTIONS | self::SAVE_IN_SESSION; |
| 451 | |
| 452 | protected $from = 'profile_name_enum'; |
| 453 | protected $idfield = 'type'; |
| 454 | protected $valfield = 'name'; |
| 455 | } |
| 456 | // }}} |
| 457 | |
| 458 | /** GROUPS |
| 459 | */ |
| 460 | // {{{ class DE_Binets |
| 461 | class DE_Binets extends DirEnumeration |
| 462 | { |
| 463 | protected $from = 'profile_binet_enum'; |
| 464 | |
| 465 | protected $ac_join = 'INNER JOIN profile_binets ON (profile_binet_enum.id = profile_binets.binet_id)'; |
| 466 | protected $ac_unique = 'profile_binets.pid'; |
| 467 | } |
| 468 | // }}} |
| 469 | |
| 470 | // {{{ class DE_Sections |
| 471 | class DE_Sections extends DirEnumeration |
| 472 | { |
| 473 | protected $from = 'profile_section_enum'; |
| 474 | |
| 475 | protected $ac_join = 'INNER JOIN profiles ON (profiles.section = profile_section_enum.id)'; |
| 476 | protected $ac_unique = 'profiles.pid'; |
| 477 | } |
| 478 | // }}} |
| 479 | |
| 480 | // {{{ class DE_GroupesX |
| 481 | class DE_GroupesX extends DirEnumeration |
| 482 | { |
| 483 | protected $idfield = 'groups.id'; |
| 484 | protected $valfield = 'groups.nom'; |
| 485 | protected $valfield2 = 'groups.diminutif'; |
| 486 | protected $from = 'groups'; |
| 487 | protected $where = 'WHERE (cat = \'GroupesX\' OR cat = \'Institutions\') AND pub = \'public\''; |
| 488 | |
| 489 | protected $ac_join = "INNER JOIN group_members ON (groups.id = group_members.asso_id |
| 490 | AND (groups.cat = 'GroupesX' OR groups.cat = 'Institutions') |
| 491 | AND groups.pub = 'public')"; |
| 492 | protected $ac_unique = 'group_members.uid'; |
| 493 | } |
| 494 | // }}} |
| 495 | |
| 496 | /** EDUCATION |
| 497 | */ |
| 498 | // {{{ class DE_EducationSchools |
| 499 | class DE_EducationSchools extends DirEnumeration |
| 500 | { |
| 501 | protected $idfield = 'profile_education_enum.id'; |
| 502 | protected $valfield = 'profile_education_enum.name'; |
| 503 | protected $valfield2 = 'profile_education_enum.abbreviation'; |
| 504 | protected $from = 'profile_education_enum'; |
| 505 | |
| 506 | protected $ac_join = 'INNER JOIN profile_education ON (profile_education.eduid = profile_education_enum.id)'; |
| 507 | protected $ac_unique = 'profile_education.pid'; |
| 508 | } |
| 509 | // }}} |
| 510 | |
| 511 | // {{{ class DE_EducationDegrees |
| 512 | class DE_EducationDegrees extends DirEnumeration |
| 513 | { |
| 514 | public $capabilities = self::HAS_OPTIONS; |
| 515 | |
| 516 | protected $idfield = 'profile_education_degree.degreeid'; |
| 517 | protected $optfield = 'profile_education_degree.eduid'; |
| 518 | protected $valfield = 'profile_education_degree_enum.degree'; |
| 519 | protected $from = 'profile_education_degree_enum'; |
| 520 | protected $join = 'INNER JOIN profile_education_degree ON (profile_education_degree.degreeid = profile_education_degree_enum.id)'; |
| 521 | |
| 522 | } |
| 523 | // }}} |
| 524 | |
| 525 | // {{{ class DE_EducationFields |
| 526 | class DE_EducationFields extends DirEnumeration |
| 527 | { |
| 528 | protected $valfield = 'profile_education_field_enum.field'; |
| 529 | protected $from = 'profile_education_field_enum'; |
| 530 | |
| 531 | protected $ac_join = 'INNER JOIN profile_education ON (profile_education.fieldid = profile_education_field_enum.id)'; |
| 532 | protected $ac_unique = 'profile_education.pid'; |
| 533 | } |
| 534 | // }}} |
| 535 | |
| 536 | // {{{ class DE_Corps |
| 537 | class DE_Corps extends DirEnumeration |
| 538 | { |
| 539 | protected $idfield = 'profile_corps_enum.id'; |
| 540 | protected $valfield = 'profile_corps_enum.name'; |
| 541 | protected $valfield2 = 'profile_corps_enum.abbrev'; |
| 542 | protected $from = 'profile_corps_enum'; |
| 543 | |
| 544 | protected $ac_unique = 'profile_corps.pid'; |
| 545 | protected $ac_join = 'INNER JOIN profile_corps ON (profile_corps.current_corpsid = profile_corps_enum.id)'; |
| 546 | } |
| 547 | // }}} |
| 548 | |
| 549 | // {{{ class DE_CorpsRanks |
| 550 | class DE_CorpsRanks extends DirEnumeration |
| 551 | { |
| 552 | protected $idfield = 'profile_corps_rank_enum.id'; |
| 553 | protected $valfield = 'profile_corps_rank_enum.name'; |
| 554 | protected $valfield2 = 'profile_corps_rank_enum.abbrev'; |
| 555 | protected $from = 'profile_corps_rank_enum'; |
| 556 | |
| 557 | protected $ac_unique = 'profile_corps.pid'; |
| 558 | protected $ac_join = 'INNER JOIN profile_corps ON (profile_corps.rankid = profile_corps_rank_enum.id)'; |
| 559 | } |
| 560 | // }}} |
| 561 | |
| 562 | /** GEOLOC |
| 563 | */ |
| 564 | // {{{ class DE_Nationalities |
| 565 | class DE_Nationalities extends DirEnumeration |
| 566 | { |
| 567 | protected $idfield = 'geoloc_countries.iso_3166_1_a2'; |
| 568 | protected $valfield = 'geoloc_countries.nationality'; |
| 569 | protected $valfield2 = 'geoloc_countries.nationalityEn'; |
| 570 | protected $from = 'geoloc_countries'; |
| 571 | protected $join = 'INNER JOIN profiles ON (geoloc_countries.iso_3166_1_a2 IN (profiles.nationality1, profiles.nationality2, profiles.nationality3))'; |
| 572 | |
| 573 | protected $ac_join = 'INNER JOIN profiles ON (geoloc_countries.iso_3166_1_a2 IN (profiles.nationality1, profiles.nationality2, profiles.nationality3))'; |
| 574 | protected $ac_unique = 'profiles.pid'; |
| 575 | } |
| 576 | // }}} |
| 577 | |
| 578 | // {{{ class DE_Countries |
| 579 | class DE_Countries extends DirEnumeration |
| 580 | { |
| 581 | protected $idfield = 'geoloc_countries.iso_3166_1_a2'; |
| 582 | protected $valfield = 'geoloc_countries.country'; |
| 583 | protected $valfield2 = 'geoloc_countries.countryEn'; |
| 584 | protected $from = 'geoloc_countries'; |
| 585 | |
| 586 | protected $ac_join = 'INNER JOIN profile_addresses ON (geoloc_countries.iso_3166_1_a2 = profile_addresses.countryId)'; |
| 587 | protected $ac_unique = 'profile_addresses.pid'; |
| 588 | } |
| 589 | // }}} |
| 590 | |
| 591 | // {{{ class DE_AdminAreas |
| 592 | class DE_AdminAreas extends DE_WithSuboption |
| 593 | { |
| 594 | protected $idfield = 'geoloc_administrativeareas.id'; |
| 595 | protected $optfield = 'geoloc_administrativeareas.country'; |
| 596 | protected $valfield = 'geoloc_administrativeareas.name'; |
| 597 | protected $from = 'geoloc_administrativeareas'; |
| 598 | |
| 599 | protected $ac_join = 'INNER JOIN profile_addresses ON (profile_addresses.administrativeAreaId = geoloc_administrativeareas.id)'; |
| 600 | protected $ac_unique = 'profile_addresses.pid'; |
| 601 | } |
| 602 | // }}} |
| 603 | |
| 604 | // {{{ class DE_SubAdminAreas |
| 605 | class DE_SubAdminAreas extends DE_WithSuboption |
| 606 | { |
| 607 | protected $idfield = 'geoloc_subadministrativeareas.id'; |
| 608 | protected $optfield = 'geoloc_subadministrativeareas.administrativearea'; |
| 609 | protected $valfield = 'geoloc_subadministrativeareas.name'; |
| 610 | protected $from = 'geoloc_subadministrativeareas'; |
| 611 | |
| 612 | protected $ac_join = 'INNER JOIN profile_addresses ON (profile_addresses.subadministrativeAreaId = geoloc_subadministrativeareas.id)'; |
| 613 | protected $ac_unique = 'profile_addresses.pid'; |
| 614 | } |
| 615 | // }}} |
| 616 | |
| 617 | // {{{ class DE_Localities |
| 618 | class DE_Localities extends DirEnumeration |
| 619 | { |
| 620 | protected $idfield = 'geoloc_localities.id'; |
| 621 | protected $valfield = 'geoloc_localities.name'; |
| 622 | protected $from = 'geoloc_localities'; |
| 623 | |
| 624 | protected $ac_join = 'INNER JOIN profile_addresses ON (profile_addresses.localityID = geoloc_localities.id)'; |
| 625 | protected $ac_unique = 'profile_addresses.pid'; |
| 626 | } |
| 627 | // }}} |
| 628 | |
| 629 | /** JOBS |
| 630 | */ |
| 631 | // {{{ class DE_Companies |
| 632 | class DE_Companies extends DirEnumeration |
| 633 | { |
| 634 | protected $idfield = 'profile_job_enum.id'; |
| 635 | protected $valfield = 'profile_job_enum.name'; |
| 636 | protected $valfield2 = 'profile_job_enum.acronym'; |
| 637 | protected $from = 'profile_job_enum'; |
| 638 | |
| 639 | protected $ac_join = 'INNER JOIN profile_job ON (profile_job.jobid = profile_job_enum.id)'; |
| 640 | protected $ac_unique = 'profile_job.pid'; |
| 641 | } |
| 642 | // }}} |
| 643 | |
| 644 | // {{{ class DE_JobDescription |
| 645 | class DE_JobDescription extends DirEnumeration |
| 646 | { |
| 647 | protected $valfield = 'profile_job.description'; |
| 648 | protected $from = 'profile_job'; |
| 649 | protected $idfield = 'profile_job.pid'; |
| 650 | |
| 651 | protected $ac_unique = 'profile_job.pid'; |
| 652 | } |
| 653 | // }}} |
| 654 | |
| 655 | // {{{ class DE_JobTerms |
| 656 | class DE_JobTerms extends DirEnumeration |
| 657 | { |
| 658 | // {{{ function getAutoComplete |
| 659 | public function getAutoComplete($text) |
| 660 | { |
| 661 | $tokens = JobTerms::tokenize($text.'%'); |
| 662 | if (count($tokens) == 0) { |
| 663 | return PlIteratorUtils::fromArray(array()); |
| 664 | } |
| 665 | $token_join = JobTerms::token_join_query($tokens, 'e'); |
| 666 | return XDB::iterator('SELECT e.jtid AS id, e.full_name AS field, COUNT(DISTINCT p.pid) AS nb |
| 667 | FROM profile_job_term_enum AS e |
| 668 | INNER JOIN profile_job_term_relation AS r ON (r.jtid_1 = e.jtid) |
| 669 | INNER JOIN profile_job_term AS p ON (r.jtid_2 = p.jtid) |
| 670 | '.$token_join.' |
| 671 | GROUP BY e.jtid |
| 672 | ORDER BY nb DESC, field |
| 673 | LIMIT ' . self::AUTOCOMPLETE_LIMIT); |
| 674 | } |
| 675 | // }}} |
| 676 | } |
| 677 | // }}} |
| 678 | |
| 679 | /** NETWORKING |
| 680 | */ |
| 681 | // {{{ class DE_Networking |
| 682 | class DE_Networking extends DirEnumeration |
| 683 | { |
| 684 | protected $idfield = 'profile_networking_enum.nwid'; |
| 685 | protected $valfield = 'profile_networking_enum.name'; |
| 686 | protected $from = 'profile_networking_enum'; |
| 687 | |
| 688 | |
| 689 | protected $ac_join = 'INNER JOIN profile_networking ON (profile_networking.nwid = profile_networking_enum.nwid)'; |
| 690 | protected $ac_unique = 'profile_networking.pid'; |
| 691 | } |
| 692 | // }}} |
| 693 | |
| 694 | /** MEDALS |
| 695 | */ |
| 696 | // {{{ class DE_Medals |
| 697 | class DE_Medals extends DirEnumeration |
| 698 | { |
| 699 | protected $from = 'profile_medal_enum'; |
| 700 | |
| 701 | protected $ac_join = 'INNER JOIN profile_medals ON (profile_medals.mid = profile_medal_enum.id)'; |
| 702 | protected $ac_unique = 'profile_medals.pid'; |
| 703 | } |
| 704 | // }}} |
| 705 | |
| 706 | /** ACCOUNTS |
| 707 | */ |
| 708 | // {{{ class DE_AccountTypes |
| 709 | class DE_AccountTypes extends DirEnumeration |
| 710 | { |
| 711 | public $capabilities = 0x005; // self::HAS_OPTIONS | self::SAVE_IN_SESSION; |
| 712 | |
| 713 | protected $from = 'account_types'; |
| 714 | protected $valfield = 'perms'; |
| 715 | protected $idfield = 'type'; |
| 716 | } |
| 717 | // }}} |
| 718 | |
| 719 | // {{{ class DE_Skins |
| 720 | class DE_Skins extends DirEnumeration |
| 721 | { |
| 722 | public $capabilities = 0x005; // self::HAS_OPTIONS | self::SAVE_IN_SESSION; |
| 723 | |
| 724 | protected $from = 'skins'; |
| 725 | protected $valfield = 'name'; |
| 726 | protected $idfield = 'skin_tpl'; |
| 727 | } |
| 728 | // }}} |
| 729 | |
| 730 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: |
| 731 | ?> |