X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=include%2Fufbuilder.inc.php;h=ee8f3fd4b911494693f3299866eb40d8204202e5;hb=257ae4081d1b5da12c4458f0642b9d2b7843abee;hp=3f708a53f1300f15443d04d1bfdc3b87f013aecd;hpb=59c6cb70b7d8fa6264ff4468c3009fc07cf32efc;p=platal.git diff --git a/include/ufbuilder.inc.php b/include/ufbuilder.inc.php index 3f708a5..ee8f3fd 100644 --- a/include/ufbuilder.inc.php +++ b/include/ufbuilder.inc.php @@ -73,10 +73,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) { @@ -158,9 +169,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 +182,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 +246,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 @@ -236,14 +268,12 @@ abstract class UFB_Field // {{{ class UFBF_Text abstract class UFBF_Text extends UFB_Field { - private $forbiddenchars; private $minlength; private $maxlength; - public function __construct($envfield, $formtext = '', $forbiddenchars = '', $minlength = 2, $maxlength = 255) + public function __construct($envfield, $formtext = '', $minlength = 2, $maxlength = 255) { parent::__construct($envfield, $formtext); - $this->forbiddenchars = $forbiddenchars; $this->minlength = $minlength; $this->maxlength = $maxlength; } @@ -260,7 +290,10 @@ abstract class UFBF_Text extends UFB_Field 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)) { + return $this->raise('Le champ %s contient un caractère interdit rendant la recherche impossible.'); } + return true; } } @@ -310,6 +343,7 @@ abstract class UFBF_Index extends UFB_Field if (!$ufb->has($this->envfield)) { $this->empty = true; } + $this->val = $ufb->i($this->envfield); return true; } } @@ -399,7 +433,7 @@ 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); + $ufb->i('exact') ? XDB::WILDCARD_EXACT : XDB::WILDCARD_CONTAINS); if (count($indexes) == 0) { return false; } @@ -410,7 +444,7 @@ abstract class UFBF_Mixed extends UFB_Field } // }}} -// {{{ UFBF_Quick +// {{{ class UFBF_Quick class UFBF_Quick extends UFB_Field { protected function check(UserFilterBuilder &$ufb) @@ -421,25 +455,26 @@ class UFBF_Quick extends UFB_Field } $this->val = str_replace('*', '%', replace_accent($ufb->s($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; + $this->conds->addChild(new UFC_Ip($s)); + return; } + $conds = new PFC_And(); + /** Name */ $s = preg_replace('!\d+!', ' ', $s); @@ -472,7 +507,7 @@ class UFBF_Quick extends UFB_Field } $conds->addChild(new UFC_NameTokens($st, $flags, $soundex, $exact)); - $ufb->addSort(new UFO_Score()); + $ufb->addOrder(new UFO_Score()); } /** Promo ranges @@ -495,7 +530,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])); } } @@ -658,7 +693,7 @@ class UFBF_Town extends UFBF_Text { $this->type = $type; $this->onlycurrentfield = $onlycurrentfield; - parent::__construct($envfield, $formtext, '', 2, 30); + parent::__construct($envfield, $formtext, 2, 30); } protected function buildUFC(UserFilterBuilder &$ufb) @@ -894,38 +929,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); } } // }}} @@ -978,4 +1013,42 @@ 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); + } +} +// }}} ?>