optionTxt */ protected $options; /** Description of the MySQL storage of the fields */ protected $idfield = 'id'; protected $valfield = 'text'; protected $from; protected $join = ''; protected $where = ''; public function __construct() { $this->loadOptions(); } public function getOptions() { return $this->options; } /** Retrieves possible IDs for given text * @param $text Text to search for IDs * @param $mode Mode of search (PREFIX, SUFFIX, CONTAINS) * @return An array of matching IDs ; if empty, input should be considered invalid */ public function getIDs($text, $mode) { if ($mode == self::MODE_EXACT) { $options = $this->getOptions(); return array_keys($options, $text); } else { if ($this->where == null) { $where = 'WHERE '; } else { $where = $this->where . ' AND '; } return XDB::fetchColumn('SELECT ' . $this->idfield . ' FROM ' . $this->from . ' ' . $this->join . ' ' . $where . $this->valfield . self::makeSqlConcat($text, $mode) . ' GROUP BY ' . $this->idfield); } } static protected function makeSqlConcat($text, $mode) { if ($mode == self::MODE_EXACT) { return ' = ' . XDB::format('{?}', $text); } if (($mode & self::MODE_CONTAINS) == self::MODE_PREFIX) { $right = XDB::format('CONCAT({?}, \'%\')', $text); } else if (($mode & self::MODE_CONTAINS) == self::MODE_SUFFIX) { $right = XDB::format('CONCAT(\'%\', {?})', $text); } else { $right = XDB::format('CONCAT(\'%\', {?}, \'%\')', $text); } return ' LIKE ' . $right; } /** The function used to load options */ protected function loadOptions() { $this->options = XDB::iterator('SELECT ' . $this->valfield . ' AS field, ' . $this->idfield . ' AS id FROM ' . $this->from . ' ' . $this->join . ' ' . $this->where . ' GROUP BY ' . $this->valfield . ' ORDER BY ' . $this->valfield); } } // }}} // {{{ class DE_Binets class DE_Binets extends DirEnumeration { protected $from = 'binets_def'; } // }}} // {{{ class DE_Sections class DE_Sections extends DirEnumeration { protected $from = 'sections'; } // }}} // {{{ class DE_Schools class DE_Schools extends DirEnumeration { protected $valfield = 'name'; protected $from = 'profile_education_enum'; } // }}} // {{{ class DE_Degrees class DE_Degrees extends DirEnumeration { protected $suboptions = array(); protected function loadOptions() { $res = XDB::query('SELECT ped.eduid, ped.degreeid, pede.degree FROM profile_education_enum AS pee LEFT JOIN profile_education_degree AS ped ON (pee.id = ped.eduid) LEFT JOIN profile_education_degree_enum AS pede ON (ped.degreeid = pede.id) ORDER BY pede.degree'); foreach($res->fetchAllRow() as $row) { list($eduid, $degreeid, $name) = $row; $this->options[$degreeid] = array('id' => $degreeid, 'field' => $name); if (!array_key_exists($eduid, $this->suboptions)) { $this->suboptions[$eduid] = array(); } $this->suboptions[$eduid][] = array('id' => $degreeid, 'field' => $name); } } public function getOptions($eduid = null) { if ($eduid == null) { return PlIteratorUtils::fromArray($this->options, 1, true); } if (array_key_exists($eduid, $this->suboptions)) { return PlIteratorUtils::fromArray($this->suboptions[$eduid], 1, true); } else { return array(); } } public function getIDs($text, $mode, $eduid = null) { if ($eduid == null) { return XDB::fetchColumn('SELECT id FROM profile_education_degree_enum WHERE degree ' . self::makeSqlConcat($text, $mode)); } else { return XDB::fetchColumn('SELECT pede.id FROM profile_education_degree AS ped LEFT JOIN profile_education_degree_enum AS pede ON (ped.degreeid = pede.id) WHERE ped.eduid = {?} AND pede.degree ' . self::makeSqlConcat($text, $mode), $eduid); } } } // }}} // {{{ class DE_StudiesSector class DE_StudiesSector extends DirEnumeration { protected $valfield = 'field'; protected $from = 'profile_education_field_enum'; } // }}} // {{{ class DE_Nationalities class DE_Nationalities extends DirEnumeration { protected $idfield = 'iso_3166_1_a2'; protected $valfield = 'nationalityFR'; protected $from = 'geoloc_countries AS gc'; protected $join = 'INNER JOIN profiles AS p ON (gc.iso_3166_1_a2 IN (p.nationality1, p.nationality2, p.nationality3))'; } // }}} // {{{ class DE_Countries class DE_Countries extends DirEnumeration { protected $idfield = 'iso_3166_1_a2'; protected $valfield = 'countryFR'; protected $from = 'geoloc_countries'; } // }}} // {{{ class DE_AdminAreas class DE_AdminAreas extends DirEnumeration { protected $suboptions = array(); protected function loadOptions() { $res = XDB::query('SELECT id, name AS field, country FROM geoloc_administrativeareas GROUP BY name ORDER BY name'); foreach($res->fetchAllRow() as $row) { list($id, $field, $country) = $row; $this->options[] = array('id' => $id, 'field' => $field); if (!array_key_exists($country, $this->suboptions)) { $this->suboptions[$country] = array(); } $this->suboptions[$country][] = array('id' => $id, 'field' => $field); } } public function getOptions($country = null) { if ($country == null) { return PlIteratorUtils::fromArray($this->options, 1, true); } if (array_key_exists($country, $this->suboptions)) { return PlIteratorUtils::fromArray($this->suboptions[$country], 1, true); } else { return array(); } } public function getIDs($text, $mode, $country = null) { if ($country == null) { return XDB::fetchColumn('SELECT id FROM geoloc_administrativeareas WHERE name ' . self::makeSqlConcat($text, $mode)); } else { return XDB::fetchColumn('SELECT id FROM geoloc_administrativeareas WHERE country = {?} AND name' . self::makeSqlConcat($text, $mode), $country); } } } // }}} // {{{ class DE_GroupesX class DE_GroupesX extends DirEnumeration { protected $valfield = 'nom'; protected $from = '#groupex#.asso'; protected $where = 'WHERE (cat = \'GroupesX\' OR cat = \'Institutions\') AND pub = \'public\''; } // }}} // {{{ class DE_Sectors class DE_Sectors extends DirEnumeration { protected $valfield = 'name'; protected $from = 'profile_job_sector_enum'; } // }}} // {{{ class DE_Networking class DE_Networking extends DirEnumeration { protected $idfield = 'network_type'; protected $valfield = 'name'; protected $from = 'profile_networking_enum'; } // }}} ?>