+// {{{ 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 implements UserFilterCondition
+{
+ private $medal;
+ private $grade;
+
+ public function __construct($medal, $grade = null)
+ {
+ $this->medal = $medal;
+ $this->grade = $grade;
+ }
+
+ public function buildCondition(PlFilter &$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_Mentor_Expertise
+/** Filters users by mentoring expertise
+ * @param $expertise Domain of expertise
+ */
+class UFC_Mentor_Expertise implements UserFilterCondition
+{
+ private $expertise;
+
+ public function __construct($expertise)
+ {
+ $this->expertise = $expertise;
+ }
+
+ public function buildCondition(PlFilter &$uf)
+ {
+ $sub = $uf->addMentorFilter(UserFilter::MENTOR_EXPERTISE);
+ return $sub . '.expertise ' . XDB::formatWildcards(XDB::WILDCARD_CONTAINS, $this->expertise);
+ }
+}
+// }}}
+
+// {{{ class UFC_Mentor_Country
+/** Filters users by mentoring country
+ * @param $country Two-letters code of country being searched
+ */
+class UFC_Mentor_Country implements UserFilterCondition
+{
+ private $country;
+
+ public function __construct($country)
+ {
+ $this->country = $country;
+ }
+
+ public function buildCondition(PlFilter &$uf)
+ {
+ $sub = $uf->addMentorFilter(UserFilter::MENTOR_COUNTRY);
+ return $sub . '.country = ' . XDB::format('{?}', $this->country);
+ }
+}
+// }}}
+
+// {{{ class UFC_Mentor_Sectorization
+/** Filters users based on mentoring (sub|)sector
+ * @param $sector ID of (sub)sector
+ * @param $type Whether we are looking for a sector or a subsector
+ */
+class UFC_Mentor_Sectorization implements UserFilterCondition
+{
+ const SECTOR = 1;
+ const SUBSECTOR = 2;
+ private $sector;
+ private $type;
+
+ public function __construct($sector, $type = self::SECTOR)
+ {
+ $this->sector = $sector;
+ $this->type = $type;
+ }
+
+ public function buildCondition(PlFilter &$uf)
+ {
+ $sub = $uf->addMentorFilter(UserFilter::MENTOR_SECTOR);
+ if ($this->type == self::SECTOR) {
+ $field = 'sectorid';
+ } else {
+ $field = 'subsectorid';
+ }
+ return $sub . '.' . $field . ' = ' . XDB::format('{?}', $this->sector);
+ }
+}
+// }}}
+