X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=include%2Fufbuilder.inc.php;h=2eacd435cddd0c6a878967cb38575585e68428e8;hb=78a47eb456adb9dec306b7de02391956f98a239c;hp=ee8f3fd4b911494693f3299866eb40d8204202e5;hpb=658b4c83a68ef3bee04742128743bf0687e9600e;p=platal.git diff --git a/include/ufbuilder.inc.php b/include/ufbuilder.inc.php index ee8f3fd..2eacd43 100644 --- a/include/ufbuilder.inc.php +++ b/include/ufbuilder.inc.php @@ -19,8 +19,6 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * ***************************************************************************/ -require_once 'directory.enums.inc.php'; - // {{{ class UserFilterBuilder class UserFilterBuilder { @@ -107,24 +105,56 @@ class UserFilterBuilder /** Wrappers around Env::i/s/..., to add envprefix */ - public function s($key, $def = '') { - return trim(Env::s($this->envprefix . $key, $def)); + public function s($key, $def = '') + { + return Env::s($this->envprefix . $key, $def); + } + + public function t($key, $def = '') + { + return Env::t($this->envprefix . $key, $def); } - public function i($key, $def = 0) { - return intval(trim(Env::i($this->envprefix . $key, $def))); + public function i($key, $def = 0) + { + return Env::i($this->envprefix . $key, $def); } - public function v($key, $def = null) { + public function v($key, $def = null) + { return Env::v($this->envprefix . $key, $def); } - public function has($key) { - return (Env::has($this->envprefix . $key) && strlen($this->s($key, '')) > 0); + public function b($key, $def = false) + { + return Env::b($this->envprefix . $key, $def); + } + + public function has($key) + { + return Env::has($this->envprefix . $key); + } + + public function blank($key, $strict = false) + { + return Env::blank($key, $strict); + } + + public function hasAlnum($key) + { + $str = $this->s($key); + return preg_match('/[a-z0-9]/i', $str); + } + + public function hasAlpha($key) + { + $str = $this->s($key); + return preg_match('/[a-z]/i', $str); } - public function isOn($key) { - return (Env::has($this->envprefix . $key) && $this->s($key) == 'on'); + public function isOn($key) + { + return $this->has($key) && $this->t($key) == 'on'; } } // }}} @@ -136,6 +166,7 @@ class UFB_QuickSearch extends UserFilterBuilder { $fields = array( new UFBF_Quick('quick', 'Recherche rapide'), + new UFBF_NotRegistered('nonins', 'Non inscrits'), ); parent::__construct($fields, $envprefix); } @@ -160,9 +191,9 @@ class UFB_AdvancedSearch extends UserFilterBuilder new UFBF_AdminArea('region', 'Région'), new UFBF_JobCompany('entreprise', 'Entreprise'), - new UFBF_JobSector('sector', 'Poste'), new UFBF_JobDescription('jobdescription', 'Fonction'), new UFBF_JobCv('cv', 'CV'), + new UFBF_JobTerms('jobterm', 'Mots-clefs'), new UFBF_Nationality('nationaliteTxt', 'nationalite', 'Nationalité'), new UFBF_Binet('binetTxt', 'binet', 'Binet'), @@ -176,6 +207,8 @@ class UFB_AdvancedSearch extends UserFilterBuilder new UFBF_Comment('free', 'Commentaire'), new UFBF_Phone('phone_number', 'Téléphone'), new UFBF_Networking('networking_address', 'networking_type', 'Networking et sites webs'), + + new UFBF_Mentor('only_referent', 'Référent'), ); parent::__construct($fields, $envprefix); } @@ -188,9 +221,8 @@ class UFB_MentorSearch extends UserFilterBuilder public function __construct($envprefix = '') { $fields = array( - new UFBF_MentorCountry('pays_sel'), - new UFBF_MentorSectorization('sector', '', UFC_Mentor_Sectorization::SECTOR), - new UFBF_MentorSectorization('subSector', '', UFC_Mentor_Sectorization::SUBSECTOR), + new UFBF_MentorCountry('country'), + new UFBF_MentorTerm('jobterm', 'jobtermText'), new UFBF_MentorExpertise('expertise'), ); parent::__construct($fields, $envprefix); @@ -237,7 +269,7 @@ abstract class UFB_Field return false; } - if (!$this->empty) { + if (!$this->isEmpty()) { $ufc = $this->buildUFC($ufb); if ($ufc != null) { $ufb->addCond($ufc); @@ -280,17 +312,17 @@ abstract class UFBF_Text extends UFB_Field protected function check(UserFilterBuilder &$ufb) { - if (!$ufb->has($this->envfield)) { + if ($ufb->blank($this->envfield)) { $this->empty = true; return true; } - $this->val = $ufb->s($this->envfield); + $this->val = $ufb->t($this->envfield); if (strlen($this->val) < $this->minlength) { return $this->raise("Le champ %s est trop court (minimum {$this->minlength})."); } else if (strlen($this->val) > $this->maxlength) { return $this->raise("Le champ %s est trop long (maximum {$this->maxlength})."); - } else if (preg_match(":[\]\[<>{}~/§_`|%$^=+]|\*\*:u", $this->val)) { + } else if (preg_match(":[\]\[<>{}~§_`|%$^=]|\*\*:u", $this->val)) { return $this->raise('Le champ %s contient un caractère interdit rendant la recherche impossible.'); } @@ -317,7 +349,7 @@ abstract class UFBF_Range extends UFB_Field protected function check(UserFilterBuilder &$ufb) { - if (!$ufb->has($this->envfield)) { + if ($ufb->blank($this->envfield)) { $this->empty = true; return true; } @@ -340,7 +372,7 @@ abstract class UFBF_Index extends UFB_Field { protected function check(UserFilterBuilder &$ufb) { - if (!$ufb->has($this->envfield)) { + if ($ufb->blank($this->envfield)) { $this->empty = true; } $this->val = $ufb->i($this->envfield); @@ -365,7 +397,7 @@ abstract class UFBF_Enum extends UFB_Field protected function check(UserFilterBuilder &$ufb) { - if (!$ufb->has($this->envfield)) { + if ($ufb->blank($this->envfield)) { $this->empty = true; return true; } @@ -388,12 +420,12 @@ abstract class UFBF_Bool extends UFB_Field { protected function check(UserFilterBuilder &$ufb) { - if (!$ufb->has($this->envfield)) { + if ($ufb->blank($this->envfield)) { $this->empty = true; return true; } - $this->val = ($ufb->i($this->envfield) != 0); + $this->val = $ufb->b($this->envfield); return true; } } @@ -418,12 +450,12 @@ abstract class UFBF_Mixed extends UFB_Field protected function check(UserFilterBuilder &$ufb) { - if (!$ufb->has($this->envfieldindex) && !$ufb->has($this->envfield)) { + if ($ufb->blank($this->envfieldindex) && !$ufb->hasAlnum($this->envfield)) { $this->empty = true; return true; } - if ($ufb->has($this->envfieldindex)) { + if (!$ufb->blank($this->envfieldindex)) { $index = $ufb->v($this->envfieldindex); if (is_int($index)) { $index = intval($index); @@ -432,8 +464,8 @@ abstract class UFBF_Mixed extends UFB_Field } $this->val = array($index); } else { - $indexes = DirEnum::getIDs($this->direnum, $ufb->s($this->envfield), - $ufb->i('exact') ? XDB::WILDCARD_EXACT : XDB::WILDCARD_CONTAINS); + $indexes = DirEnum::getIDs($this->direnum, $ufb->t($this->envfield), + $ufb->b('exact') ? XDB::WILDCARD_EXACT : XDB::WILDCARD_CONTAINS); if (count($indexes) == 0) { return false; } @@ -449,12 +481,12 @@ class UFBF_Quick extends UFB_Field { protected function check(UserFilterBuilder &$ufb) { - if (!$ufb->has($this->envfield)) { + if ($ufb->blank($this->envfield)) { $this->empty = true; return true; } - $this->val = str_replace('*', '%', replace_accent($ufb->s($this->envfield))); + $this->val = str_replace('*', '%', replace_accent($ufb->t($this->envfield))); return true; } @@ -469,8 +501,7 @@ class UFBF_Quick extends UFB_Field if (S::admin() && strpos($s, '@') !== false) { return new UFC_Email($s); } else if (S::admin() && preg_match('/[0-9]+\.([0-9]+|%)\.([0-9]+|%)\.([0-9]+|%)/', $s)) { - $this->conds->addChild(new UFC_Ip($s)); - return; + return new UFC_Ip($s); } $conds = new PFC_And(); @@ -490,22 +521,8 @@ class UFBF_Quick extends UFB_Field } else { $flags = array('public'); } - if ($ufb->i('soundex')) { - $soundex = true; - $st = array(); - foreach ($strings as $string) { - $st[] = soundex_fr($string); - } - } else { - $soundex = false; - $st = $strings; - } - if ($ufb->i('exact')) { - $exact = true; - } else { - $exact = false; - } - $conds->addChild(new UFC_NameTokens($st, $flags, $soundex, $exact)); + $exact =$ufb->b('exact'); + $conds->addChild(new UFC_NameTokens($strings, $flags, $ufb->b('with_soundex'), $exact)); $ufb->addOrder(new UFO_Score()); } @@ -565,7 +582,7 @@ class UFBF_Name extends UFBF_Text protected function buildUFC(UserFilterBuilder &$ufb) { - return new UFC_NameTokens($this->val, array(), $ufb->i('with_soundex'), $ufb->i('exact')); + return new UFC_NameTokens($this->val, array(), $ufb->b('with_soundex'), $ufb->b('exact')); } } // }}} @@ -585,13 +602,13 @@ class UFBF_Promo extends UFB_Field protected function check(UserFilterBuilder &$ufb) { - if (!$ufb->has($this->envfield) || !$ufb->has($this->envfieldcomp)) { + if ($ufb->blank($this->envfield) || $ufb->blank($this->envfieldcomp)) { $this->empty = true; return true; } - $this->val = $ubf->i($this->envfield); - $this->comp = $ubf->v($this->envfieldcomp); + $this->val = $ufb->i($this->envfield); + $this->comp = $ufb->v($this->envfieldcomp); if (!in_array($this->comp, self::$validcomps)) { return $this->raise("Le critère {$this->comp} n'est pas valide pour le champ %s"); @@ -607,7 +624,7 @@ class UFBF_Promo extends UFB_Field } protected function buildUFC(UserFilterBuilder &$ufb) { - return new UFC_Promo($this->comp, UserFilter::DISPLAY, 'X' . $this->val); + return new UFC_Promo($this->comp, UserFilter::GRADE_ING, $this->val); } } // }}} @@ -639,6 +656,22 @@ class UFBF_Sex extends UFBF_Enum } // }}} +// {{{ class UFBF_NotRegistered +// Simple field for selecting only alive, not registered users (for quick search) +class UFBF_NotRegistered extends UFBF_Bool +{ + protected function buildUFC(UserFilterBuilder &$ufb) + { + if ($this->val) { + return new PFC_And( + new PFC_Not(new UFC_Dead()), + new PFC_Not(new UFC_Registered()) + ); + } + } +} +// }}} + // {{{ class UFBF_Registered class UFBF_Registered extends UFBF_Enum { @@ -652,7 +685,7 @@ class UFBF_Registered extends UFBF_Enum if ($this->val == 1) { return new UFC_Registered(); } else if ($this->val == 2) { - return new PFC_Not(UFC_Registered()); + return new PFC_Not(new UFC_Registered()); } } } @@ -669,7 +702,7 @@ class UFBF_Dead extends UFBF_Enum protected function buildUFC(UserFilterBuilder &$ufb) { if ($this->val == 1) { - return new PFC_Not(UFC_Dead()); + return new PFC_Not(new UFC_Dead()); } else if ($this->val == 2) { return new UFC_Dead(); } @@ -711,7 +744,7 @@ class UFBF_Town extends UFBF_Text return new PFC_False(); } } else { - $byname = new UFC_AddressText(null, UFC_Address::CONTAINS, UFC_Address::TYPE_ANY, $flags, null, $this->val); + $byname = new UFC_AddressText(null, XDB::WILDCARD_CONTAINS, UFC_Address::TYPE_ANY, $flags, null, $this->val); $byzip = new UFC_AddressField($this->val, UFC_AddressField::FIELD_ZIPCODE, UFC_Address::TYPE_ANY, $flags); if ($this->type & self::TYPE_ANY) { return new PFC_Or($byname, $byzip); @@ -751,14 +784,14 @@ class UFBF_Country extends UFBF_Mixed // }}} // {{{ class UFBF_AdminArea -class UFBF_AdminArea extends UFBF_Mixed +class UFBF_AdminArea extends UFBF_Index { protected $direnum = DirEnum::ADMINAREAS; protected $onlycurrentfield; - public function __construct($envfieldtext, $envfieldindex, $formtext = '', $onlycurrentfield = 'only_current') + public function __construct($envfield, $formtext = '', $onlycurrentfield = 'only_current') { - parent::__construct($envfieldtext, $envfieldindex, $formtext); + parent::__construct($envfield, $formtext); $this->onlycurrentfield = $onlycurrentfield; } @@ -806,25 +839,12 @@ class UFBF_JobCompany extends UFBF_Text } // }}} -// {{{ class UFBF_JobSector -class UFBF_JobSector extends UFBF_Mixed +// {{{ class UFBF_JobTerms +class UFBF_JobTerms extends UFBF_Index { - protected $direnum = DirEnum::SECTORS; - private $onlymentorfield; - - public function __construct($envfieldtext, $envfieldindex, $formtext = '', $onlymentorfield = 'only_referent') - { - parent::__construct($envfieldtext, $envfieldindex, $formtext); - $this->onlymentorfield = $onlymentorfield; - } - protected function buildUFC(UserFilterBuilder &$ufb) { - if ($ufb->isOn($this->onlymentorfield)) { - return new UFC_Mentor_Sectorization($this->val, UserFilter::JOB_SUBSECTOR); - } else { - return new UFC_Job_Sectorization($this->val, UserFilter::JOB_SUBSUBSECTOR); - } + return new UFC_Job_Terms($this->val); } } // }}} @@ -918,7 +938,7 @@ class UFBF_Group extends UFBF_Mixed // }}} // {{{ class UFBF_Section -class UFBF_Section extends UFBF_Index +class UFBF_Section extends UFBF_Mixed { protected $direnum = DirEnum::SECTIONS; @@ -1007,6 +1027,11 @@ class UFBF_Networking extends UFBF_Text } } + public function isEmpty() + { + return parent::isEmpty() || $this->nwtype == 0; + } + public function buildUFC(UserFilterBuilder &$ufb) { return new UFC_Networking($this->nwtype, $this->val); @@ -1014,30 +1039,32 @@ class UFBF_Networking extends UFBF_Text } // }}} -// {{{ class UFBF_MentorCountry -class UFBF_MentorCountry extends UFBF_Index +// {{{ class UFBF_Mentor +class UFBF_Mentor extends UFBF_Bool { protected function buildUFC(UserFilterBuilder &$ufb) { - return new UFC_Mentor_Country($this->val); + return new UFC_Mentor(); } } // }}} -// {{{ class UFBF_MentorSectorization -class UFBF_MentorSectorization extends UFBF_Index +// {{{ class UFBF_MentorCountry +class UFBF_MentorCountry extends UFBF_Text { - protected $type; - - public function __construct($envfield, $formtext = '', $type = UFC_Mentor_Sectorization::SECTOR) + protected function buildUFC(UserFilterBuilder &$ufb) { - parent::__construct($envfield, $formtext); - $this->type = $type; + return new UFC_Mentor_Country($this->val); } +} +// }}} +// {{{ class UFBF_Mentorterm +class UFBF_MentorTerm extends UFBF_Index +{ protected function buildUFC(UserFilterBuilder &$ufb) { - return new UFC_Mentor_Sectorization($this->val, $this->type); + return new UFC_Mentor_Terms($this->val); } } // }}} @@ -1051,4 +1078,6 @@ class UFBF_MentorExpertise extends UFBF_Text } } // }}} + +// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: ?>