+ public function __construct($corps, $type = self::CURRENT)
+ {
+ $this->corps = $corps;
+ $this->type = $type;
+ }
+
+ public function buildCondition(UserFilter &$uf)
+ {
+ /** Tables shortcuts:
+ * pc for profile_corps,
+ * pceo for profile_corps_enum - orginal
+ * pcec for profile_corps_enum - current
+ */
+ $sub = $uf->addCorpsFilter($this->type);
+ $cond = $sub . '.abbreviation = ' . $corps;
+ return $cond;
+ }
+}
+// }}}
+
+// {{{ class UFC_Corps_Rank
+/** Filters users based on their rank in the corps
+ * @param $rank Rank we are looking for (abbreviation)
+ */
+class UFC_Corps_Rank implements UserFilterCondition
+{
+ private $rank;
+ public function __construct($rank)
+ {
+ $this->rank = $rank;
+ }
+
+ public function buildCondition(UserFilter &$uf)
+ {
+ /** Tables shortcuts:
+ * pcr for profile_corps_rank
+ */
+ $sub = $uf->addCorpsRankFilter();
+ $cond = $sub . '.abbreviation = ' . $rank;
+ return $cond;
+ }
+}
+// }}}
+
+// {{{ class UFC_Job_Company
+/** Filters users based on the company they belong to
+ * @param $type The field being searched (self::JOBID, self::JOBNAME or self::JOBACRONYM)
+ * @param $value The searched value
+ */
+class UFC_Job_Company implements UserFilterCondition
+{
+ const JOBID = 'id';
+ const JOBNAME = 'name';
+ const JOBACRONYM = 'acronym';
+
+ private $type;
+ private $value;
+
+ public function __construct($type, $value)
+ {
+ $this->assertType($type);
+ $this->type = $type;
+ $this->value = $value;
+ }
+
+ private function assertType($type)
+ {
+ if ($type != self::JOBID && $type != self::JOBNAME && $type != self::JOBACRONYM) {
+ Platal::page()->killError("Type de recherche non valide.");
+ }
+ }
+
+ public function buildCondition(UserFilter &$uf)
+ {
+ $sub = $uf->addJobCompanyFilter();
+ $cond = $sub . '.' . $this->type . ' = ' . XDB::format('{?}', $this->value);
+ return $cond;
+ }
+}
+// }}}
+
+// {{{ class UFC_Job_Sectorization
+/** Filters users based on the ((sub)sub)sector they work in
+ * @param $sector The sector searched
+ * @param $subsector The subsector
+ * @param $subsubsector The subsubsector
+ */
+class UFC_Job_Sectorization implements UserFilterCondition
+{
+
+ private $sector;
+ private $subsector;
+ private $subsubsector;
+
+ public function __construct($sector = null, $subsector = null, $subsubsector = null)
+ {
+ $this->sector = $sector;
+ $this->subsector = $subsector;
+ $this->subsubsector = $subsubsector;
+ }
+
+ public function buildCondition(UserFilter &$uf)
+ {
+ // No need to add the JobFilter, it will be done by addJobSectorizationFilter
+ $conds = array();
+ if ($this->sector !== null) {
+ $sub = $uf->addJobSectorizationFilter(UserFilter::JOB_SECTOR);
+ $conds[] = $sub . '.id = ' . XDB::format('{?}', $this->sector);
+ }
+ if ($this->subsector !== null) {
+ $sub = $uf->addJobSectorizationFilter(UserFilter::JOB_SUBSECTOR);
+ $conds[] = $sub . '.id = ' . XDB::format('{?}', $this->subsector);
+ }
+ if ($this->subsubsector !== null) {
+ $sub = $uf->addJobSectorizationFilter(UserFilter::JOB_SUBSUBSECTOR);
+ $conds[] = $sub . '.id = ' . XDB::format('{?}', $this->subsubsector);
+ }
+ return implode(' AND ', $conds);
+ }
+}
+// }}}
+
+// {{{ class UFC_Job_Description
+/** Filters users based on their job description
+ * @param $description The text being searched for
+ * @param $fields The fields to search for (user-defined, ((sub|)sub|)sector)
+ */
+class UFC_Job_Description implements UserFilterCondition
+{
+
+ /** Meta-filters
+ * Built with binary OR on UserFilter::JOB_*
+ */
+ const ANY = 31;
+ const SECTORIZATION = 15;
+
+ private $description;
+ private $fields;
+
+ public function __construct($description)
+ {
+ $this->fields = $fields;
+ $this->description = $description;
+ }
+
+ public function buildCondition(UserFilter &$uf)
+ {
+ $conds = array();
+ if ($this->fields & UserFilter::JOB_USERDEFINED) {
+ $sub = $uf->addJobFilter();
+ $conds[] = $sub . '.description LIKE ' . XDB::format('CONCAT(\'%\', {?}, \'%\')', $this->description);
+ }
+ if ($this->fields & UserFilter::JOB_SECTOR) {
+ $sub = $uf->addJobSectorizationFilter(UserFilter::JOB_SECTOR);
+ $conds[] = $sub . '.name LIKE ' . XDB::format('CONCAT(\'%\', {?}, \'%\')', $this->description);
+ }
+ if ($this->fields & UserFilter::JOB_SUBSECTOR) {
+ $sub = $uf->addJobSectorizationFilter(UserFilter::JOB_SUBSECTOR);
+ $conds[] = $sub . '.name LIKE ' . XDB::format('CONCAT(\'%\', {?}, \'%\')', $this->description);
+ }
+ if ($this->fields & UserFilter::JOB_SUBSUBSECTOR) {
+ $sub = $uf->addJobSectorizationFilter(UserFilter::JOB_SUBSUBSECTOR);
+ $conds[] = $sub . '.name LIKE ' . XDB::format('CONCAT(\'%\', {?}, \'%\')', $this->description);
+ $sub = $uf->addJobSectorizationFilter(UserFilter::JOB_ALTERNATES);
+ $conds[] = $sub . '.name LIKE ' . XDB::format('CONCAT(\'%\', {?}, \'%\')', $this->description);
+ }
+ return implode(' OR ', $conds);
+ }
+}
+// }}}
+
+// {{{ class UFC_Networking
+/** Filters users based on network identity (IRC, ...)
+ * @param $type Type of network (-1 for any)
+ * @param $value Value to search
+ */
+class UFC_Networking implements UserFilterCondition
+{
+ private $type;
+ private $value;
+
+ public function __construct($type, $value)
+ {
+ $this->type = $type;
+ $this->value = $value;
+ }
+
+ public function buildCondition(UserFilter &$uf)
+ {
+ $sub = $uf->addNetworkingFilter();
+ $conds = array();
+ $conds[] = $sub . '.address = ' . XDB::format('CONCAT(\'%\', {?}, \'%\')', $this->value);
+ if ($this->type != -1) {
+ $conds[] = $sub . '.network_type = ' . XDB::format('{?}', $this->type);
+ }
+ return implode(' AND ', $conds);
+ }
+}
+// }}}
+
+// {{{ 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 implements 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_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(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_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(UserFilter &$uf)
+ {
+ $sub = $uf->addMentorFilter(UserFilter::MENTOR_EXPERTISE);
+ return $sub . '.expertise LIKE ' . XDB::format('CONCAT(\'%\', {?}, \'%\'', $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(UserFilter &$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 sector
+ * @param $subsector Subsector (null for any)
+ */
+class UFC_Mentor_Sectorization implements UserFilterCondition
+{
+ private $sector;
+ private $subsector;
+
+ public function __construct($sector, $subsector = null)
+ {
+ $this->sector = $sector;
+ $this->subsubsector = $subsector;
+ }
+
+ public function buildCondition(UserFilter &$uf)
+ {
+ $sub = $uf->addMentorFilter(UserFilter::MENTOR_SECTOR);
+ $conds = array();
+ $conds[] = $sub . '.sectorid = ' . XDB::format('{?}', $this->sector);
+ if ($this->subsector != null) {
+ $conds[] = $sub . '.subsectorid = ' . XDB::format('{?}', $this->subsector);
+ }
+ return implode(' AND ', $conds);
+ }
+}
+// }}}
+
+// {{{ class UFC_UserRelated
+/** Filters users based on a relation toward a user
+ * @param $user User to which searched users are related
+ */