X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;ds=sidebyside;f=include%2Fufbuilder.inc.php;h=9385cb15d117b0330302993e5541b5cce9a65e01;hb=a19178e9a93c4eb3eb750845e85f87f2294ed1e4;hp=92e0841458b408309a3dc81bcf4eb7c050e395aa;hpb=3314838ec79d553b1575a2fb48e46d4fad3f8887;p=platal.git diff --git a/include/ufbuilder.inc.php b/include/ufbuilder.inc.php index 92e0841..9385cb1 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 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 v($key, $def = null) { + public function i($key, $def = 0) + { + return Env::i($this->envprefix . $key, $def); + } + + 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 isOn($key) { - return (Env::has($this->envprefix . $key) && $this->s($key) == 'on'); + 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,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)) { - // TODO: create UFC_Ip -// $this->conds->addChild(new UFC_Ip($s)); + $this->conds->addChild(new UFC_Ip($s)); return; } @@ -491,7 +508,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 +518,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 +579,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,7 +599,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; } @@ -1052,4 +1065,6 @@ class UFBF_MentorExpertise extends UFBF_Text } } // }}} + +// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: ?>