X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=include%2Fufbuilder.inc.php;h=37fa29b50a61693e5a02794c4b37bc7182f3c0a2;hb=1daa72c23026adf3e057c7b6c47d5d35837258b5;hp=ee8f3fd4b911494693f3299866eb40d8204202e5;hpb=684195f33b11e3067200dd3a9e14304bd7d04463;p=platal.git diff --git a/include/ufbuilder.inc.php b/include/ufbuilder.inc.php index ee8f3fd..37fa29b 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') ? 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 +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,8 +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)) { - $this->conds->addChild(new UFC_Ip($s)); - return; + return new UFC_Ip($s); } $conds = new PFC_And(); @@ -490,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) { @@ -500,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()); @@ -565,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')); } } // }}} @@ -585,7 +598,7 @@ 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; } @@ -1051,4 +1064,6 @@ class UFBF_MentorExpertise extends UFBF_Text } } // }}} + +// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: ?>