From ceb512d24fe826623ac5ccd38f55a01e2bc3a3d7 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Rapha=C3=ABl=20Barrois?= Date: Sun, 17 Jan 2010 12:45:48 +0100 Subject: [PATCH] Add UFC_Medal MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit For filtering users by medal / grade Signed-off-by: Raphaël Barrois --- classes/userfilter.php | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/classes/userfilter.php b/classes/userfilter.php index 943a0a4..738c702 100644 --- a/classes/userfilter.php +++ b/classes/userfilter.php @@ -822,6 +822,35 @@ class UFC_Phone extends UserFilterCondition } // }}} +// {{{ class UFC_Medal +/** Filters users based on their medals + * @param $medal ID of the medal + * @param $grade Grade of the medal (null for 'any') + */ +class UFC_Medal extends UserFilterCondition +{ + private $medal; + private $grade; + + public function __construct($medal, $grade = null) + { + $this->medal = $medal; + $this->grade = $grade; + } + + public function buildCondition(UserFilter &$uf) + { + $conds = array(); + $sub = $uf->addMedalFilter(); + $conds[] = $sub . '.mid = ' . XDB::format('{?}', $this->medal); + if ($this->grade != null) { + $conds[] = $sub . '.gid = ' . XDB::format('{?}', $this->grade); + } + 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 @@ -1723,6 +1752,25 @@ class UserFilter return $joins; } + /** MEDALS + */ + + private $with_medals = false; + public function addMedalFilter() + { + $this->with_medals = true; + return 'pmed'; + } + + private function medalJoins() + { + $joins = array(); + if ($this->with_medals) { + $joins['pmed'] = array('left', 'profile_medals_sub', '$ME.uid = $UID'); + } + return $joins; + } + /** CONTACTS */ private $cts = array(); -- 2.1.4