X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=include%2Fufbuilder.inc.php;h=59a8aec17f5d8c9e2bce98298c65755f858d4071;hb=28c20b86be8b40cecba0d83080879f81c49e07ad;hp=41e1cf41aa5196aa449eb923f99c2e84ebce7f47;hpb=f3f800d85b3328e5a8f90806f9d265d2702cbca5;p=platal.git diff --git a/include/ufbuilder.inc.php b/include/ufbuilder.inc.php index 41e1cf4..59a8aec 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 { @@ -73,10 +71,21 @@ class UserFilterBuilder return $this->valid; } + public function isEmpty() + { + $this->buildUFC(); + foreach ($this->fields as $field) { + if (! $field->isEmpty()) { + return false; + } + } + return true; + } + /** Returns the built UFC * @return The UFC, or PFC_False() if an error happened */ - public function &getUFC() + public function getUFC() { $this->buildUFC(); if ($this->valid) { @@ -96,24 +105,44 @@ 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 i($key, $def = 0) { - return intval(trim(Env::i($this->envprefix . $key, $def))); + public function t($key, $def = '') + { + return Env::t($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 isOn($key) { - return (Env::has($this->envprefix . $key) && $this->s($key) == 'on'); + public function has($key) + { + return Env::has($this->envprefix . $key); + } + + public function blank($key, $strict = false) + { + return Env::blank($key, $strict); + } + + public function isOn($key) + { + return $this->has($key) && $this->t($key) == 'on'; } } // }}} @@ -158,9 +187,9 @@ class UFB_AdvancedSearch extends UserFilterBuilder new UFBF_Group('groupexTxt', 'groupex', 'Groupe X'), new UFBF_Section('sectionTxt', 'section', 'Section'), - new UFBF_Formation('schoolTxt', 'school', "École d'application"), - new UFBF_Diploma('diplomaTxt', 'diploma', 'Diplôme'), - new UFBF_StudiesDomain('fieldTxt', 'field', "Domaine d'études"), + new UFBF_EducationSchool('schoolTxt', 'school', "École d'application"), + new UFBF_EducationDegree('diplomaTxt', 'diploma', 'Diplôme'), + new UFBF_EducationField('fieldTxt', 'field', "Domaine d'études"), new UFBF_Comment('free', 'Commentaire'), new UFBF_Phone('phone_number', 'Téléphone'), @@ -171,6 +200,22 @@ class UFB_AdvancedSearch extends UserFilterBuilder } // }}} +// {{{ class UFB_MentorSearch +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_MentorExpertise('expertise'), + ); + parent::__construct($fields, $envprefix); + } +} +// }}} + // {{{ class UFB_Field abstract class UFB_Field { @@ -219,6 +264,11 @@ abstract class UFB_Field return true; } + public function isEmpty() + { + return $this->empty; + } + /** Create the UFC associated to the field; won't be called * if the field is "empty" * @param &$ufb UFB to which fields must be added @@ -248,12 +298,12 @@ 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) { @@ -285,7 +335,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; } @@ -308,9 +358,10 @@ 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); return true; } } @@ -332,7 +383,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; } @@ -355,12 +406,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; } } @@ -385,12 +436,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->blank($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); @@ -399,8 +450,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') ? DirEnumeration::MODE_EXACT : DirEnumeration::MODE_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; } @@ -416,31 +467,31 @@ 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; } protected function buildUFC(UserFilterBuilder &$ufb) { - $conds = new PFC_And(); - $s = $this->val; + $r = $s = $this->val; /** Admin: Email, IP */ if (S::admin() && strpos($s, '@') !== false) { - $conds->addChild(new UFC_Email($s)); - return $conds; + return new UFC_Email($s); } else if (S::admin() && preg_match('/[0-9]+\.([0-9]+|%)\.([0-9]+|%)\.([0-9]+|%)/', $s)) { - // TODO: create UFC_Ip -// $this->conds->addChild(new UFC_Ip($s)); - return $conds; + return new UFC_Ip($s); } + $conds = new PFC_And(); + /** Name */ $s = preg_replace('!\d+!', ' ', $s); @@ -456,7 +507,7 @@ class UFBF_Quick extends UFB_Field } else { $flags = array('public'); } - if ($ufb->i('soundex')) { + if ($ufb->b('with_soundex')) { $soundex = true; $st = array(); foreach ($strings as $string) { @@ -466,14 +517,10 @@ class UFBF_Quick extends UFB_Field $soundex = false; $st = $strings; } - if ($ufb->i('exact')) { - $exact = true; - } else { - $exact = false; - } + $exact =$ufb->b('exact'); $conds->addChild(new UFC_NameTokens($st, $flags, $soundex, $exact)); - $ufb->addSort(new UFO_Score()); + $ufb->addOrder(new UFO_Score()); } /** Promo ranges @@ -496,7 +543,7 @@ class UFBF_Quick extends UFB_Field } elseif (preg_match('!^<(\d{4})!', $r, $matches)) { $conds->addChild(new UFC_Promo('<=', UserFilter::DISPLAY, 'X' . $matches[1])); } elseif (preg_match('!^>(\d{4})!', $r, $matches)) { - $this->conds->addChild(new UFC_Promo('>=', UserFilter::DISPLAY, 'X' . $matches[1])); + $conds->addChild(new UFC_Promo('>=', UserFilter::DISPLAY, 'X' . $matches[1])); } } @@ -531,7 +578,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')); } } // }}} @@ -551,13 +598,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"); @@ -573,7 +620,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); } } // }}} @@ -677,7 +724,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); @@ -895,38 +942,38 @@ class UFBF_Section extends UFBF_Index } // }}} -// {{{ class UFBF_Formation -class UFBF_Formation extends UFBF_Mixed +// {{{ class UFBF_EducationSchool +class UFBF_EducationSchool extends UFBF_Mixed { - protected $direnum = DirEnum::SCHOOLS; + protected $direnum = DirEnum::EDUSCHOOLS; protected function buildUFC(UserFilterBuilder &$ufb) { - return new UFC_Formation($this->val); + return new UFC_EducationSchool($this->val); } } // }}} -// {{{ class UFBF_Diploma -class UFBF_Diploma extends UFBF_Mixed +// {{{ class UFBF_EducationDegree +class UFBF_EducationDegree extends UFBF_Mixed { - protected $direnum = DirEnum::DEGREES; + protected $direnum = DirEnum::EDUDEGREES; protected function buildUFC(UserFilterBuilder &$ufb) { - return new UFC_Diploma($this->val); + return new UFC_EducationDegree($this->val); } } // }}} -// {{{ class UFBF_StudiesDomain -class UFBF_StudiesDomain extends UFBF_Mixed +// {{{ class UFBF_EducationField +class UFBF_EducationField extends UFBF_Mixed { - protected $direnum = DirEnum::STUDIESDOMAINS; + protected $direnum = DirEnum::EDUFIELDS; protected function buildUFC(UserFilterBuilder &$ufb) { - return new UFC_StudyField($this->val); + return new UFC_EducationField($this->val); } } // }}} @@ -979,4 +1026,44 @@ class UFBF_Networking extends UFBF_Text } } // }}} + +// {{{ class UFBF_MentorCountry +class UFBF_MentorCountry extends UFBF_Index +{ + protected function buildUFC(UserFilterBuilder &$ufb) + { + return new UFC_Mentor_Country($this->val); + } +} +// }}} + +// {{{ class UFBF_MentorSectorization +class UFBF_MentorSectorization extends UFBF_Index +{ + protected $type; + + public function __construct($envfield, $formtext = '', $type = UFC_Mentor_Sectorization::SECTOR) + { + parent::__construct($envfield, $formtext); + $this->type = $type; + } + + protected function buildUFC(UserFilterBuilder &$ufb) + { + return new UFC_Mentor_Sectorization($this->val, $this->type); + } +} +// }}} + +// {{{ class UFBF_MentorExpertise +class UFBF_MentorExpertise extends UFBF_Text +{ + protected function buildUFC(UserFilterBuilder &$ufb) + { + return new UFC_Mentor_Expertise($this->val); + } +} +// }}} + +// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: ?>