From 6d62969e415678406e82ee638dc47c4e9e2378c4 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Rapha=C3=ABl=20Barrois?= Date: Sun, 17 Jan 2010 02:48:19 +0100 Subject: [PATCH] Add UFC_Phone MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit For filtering users by phone number Signed-off-by: Raphaël Barrois --- classes/userfilter.php | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/classes/userfilter.php b/classes/userfilter.php index 5470d05..943a0a4 100644 --- a/classes/userfilter.php +++ b/classes/userfilter.php @@ -776,6 +776,52 @@ class UFC_Networking extends UserFilterCondition } // }}} +// {{{ class UFC_Phone +/** Filters users based on their phone number + * @param $num_type Type of number (pro/user/home) + * @param $phone_type Type of phone (fixed/mobile/fax) + * @param $number Phone number + */ +class UFC_Phone extends UserFilterCondition +{ + const NUM_PRO = 'pro'; + const NUM_USER = 'user'; + const NUM_HOME = 'address'; + const NUM_ANY = 'any'; + + const PHONE_FIXED = 'fixed'; + const PHONE_MOBILE = 'mobile'; + const PHONE_FAX = 'fax'; + const PHONE_ANY = 'any'; + + private $num_type; + private $phone_type; + private $number; + + public function __construct($number, $num_type = self::NUM_ANY, $phone_type = self::PHONE_ANY) + { + require_once('profil.inc.php'); + $this->number = $number; + $this->num_type = $num_type; + $this->phone_type = format_phone_number($phone_type); + } + + public function buildCondition(UserFilter &$uf) + { + $sub = $uf->addPhoneFilter(); + $conds = array(); + $conds[] = $sub . '.search_tel = ' . XDB::format('{?}', $this->number); + if ($this->num_type != self::NUM_ANY) { + $conds[] = $sub . '.link_type = ' . XDB::format('{?}', $this->num_type); + } + if ($this->phone_type != self::PHONE_ANY) { + $conds[] = $sub . '.tel_type = ' . XDB::format('{?}', $this->phone_type); + } + return implode(' AND ', $conds); + } +} +// }}} + // {{{ class UFC_UserRelated /** Filters users based on a relation toward on user * @param $user User to which searched users are related @@ -1657,6 +1703,26 @@ class UserFilter return $joins; } + /** PHONE + */ + + private $with_phone = false; + + public function addPhoneFilter() + { + $this->with_phone = true; + return 'ptel'; + } + + private function phoneJoins() + { + $joins = array(); + if ($this->with_phone) { + $joins['ptel'] = array('left', 'profile_phone', '$ME.uid = $UID'); + } + return $joins; + } + /** CONTACTS */ private $cts = array(); -- 2.1.4