X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=include%2Fufbuilder.inc.php;h=59a8aec17f5d8c9e2bce98298c65755f858d4071;hb=28c20b86be8b40cecba0d83080879f81c49e07ad;hp=92e0841458b408309a3dc81bcf4eb7c050e395aa;hpb=3314838ec79d553b1575a2fb48e46d4fad3f8887;p=platal.git diff --git a/include/ufbuilder.inc.php b/include/ufbuilder.inc.php index 92e0841..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 { @@ -107,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 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 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'; } } // }}} @@ -280,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) { @@ -317,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; } @@ -340,7 +358,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 +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; } @@ -388,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; } } @@ -418,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); @@ -432,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; } @@ -449,12 +467,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,9 +487,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)) { - // TODO: create UFC_Ip -// $this->conds->addChild(new UFC_Ip($s)); - return; + return new UFC_Ip($s); } $conds = new PFC_And(); @@ -491,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) { @@ -501,11 +517,7 @@ 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->addOrder(new UFO_Score()); @@ -566,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')); } } // }}} @@ -586,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"); @@ -608,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); } } // }}} @@ -712,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); @@ -1052,4 +1064,6 @@ class UFBF_MentorExpertise extends UFBF_Text } } // }}} + +// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: ?>