From: Raphaël Barrois Date: Sun, 17 Jan 2010 11:45:48 +0000 (+0100) Subject: Add UFC_Medal X-Git-Tag: xorg/1.0.0~332^2~298 X-Git-Url: http://git.polytechnique.org/?a=commitdiff_plain;h=ceb512d24fe826623ac5ccd38f55a01e2bc3a3d7;p=platal.git Add UFC_Medal For filtering users by medal / grade Signed-off-by: Raphaël Barrois --- 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();