* CONDITIONS
******************/
+// {{{ interface UserFilterCondition
interface UserFilterCondition
{
const COND_TRUE = 'TRUE';
*/
public function buildCondition(UserFilter &$uf);
}
+// }}}
+// {{{ class UFC_OneChild
abstract class UFC_OneChild implements UserFilterCondition
{
protected $child;
$this->child =& $cond;
}
}
+// }}}
+// {{{ class UFC_NChildren
abstract class UFC_NChildren implements UserFilterCondition
{
protected $children = array();
}
}
}
+// }}}
+// {{{ class UFC_True
class UFC_True implements UserFilterCondition
{
public function buildCondition(UserFilter &$uf)
return self::COND_TRUE;
}
}
+// }}}
+// {{{ class UFC_False
class UFC_False implements UserFilterCondition
{
public function buildCondition(UserFilter &$uf)
return self::COND_FALSE;
}
}
+// }}}
+// {{{ class UFC_Not
class UFC_Not extends UFC_OneChild
{
public function buildCondition(UserFilter &$uf)
}
}
}
+// }}}
+// {{{ class UFC_And
class UFC_And extends UFC_NChildren
{
public function buildCondition(UserFilter &$uf)
}
}
}
+// }}}
+// {{{ class UFC_Or
class UFC_Or extends UFC_NChildren
{
public function buildCondition(UserFilter &$uf)
}
}
}
+// }}}
+// {{{ class UFC_Profile
+/** Filters users who have a profile
+ */
class UFC_Profile implements UserFilterCondition
{
public function buildCondition(UserFilter &$uf)
return '$PID IS NOT NULL';
}
}
-
+// }}}
+
+// {{{ class UFC_Promo
+/** Filters users based on promo
+ * @param $comparison Comparison operator (>, =, ...)
+ * @param $grade Formation on which to restrict, UserFilter::DISPLAY for "any formation"
+ * @param $promo Promo on which the filter is based
+ */
class UFC_Promo implements UserFilterCondition
{
}
}
}
-
+// }}}
+
+// {{{ class UFC_Name
+/** Filters users based on name
+ * @param $type Type of name field on which filtering is done (firstname, lastname, ...)
+ * @param $text Text on which to filter
+ * @param $mode flag indicating search type (prefix, suffix, with particule, ...)
+ */
class UFC_Name implements UserFilterCondition
{
const PREFIX = 1;
return implode(' OR ', $conds);
}
}
+// }}}
+// {{{ class UFC_Dead
+/** Filters users based on death date
+ * @param $comparison Comparison operator
+ * @param $date Date to which death date should be compared
+ */
class UFC_Dead implements UserFilterCondition
{
private $comparison;
return $str;
}
}
-
+// }}}
+
+// {{{ class UFC_Registered
+/** Filters users based on registration state
+ * @param $active Whether we want to use only "active" users (i.e with a valid redirection)
+ * @param $comparison Comparison operator
+ * @param $date Date to which users registration date should be compared
+ */
class UFC_Registered implements UserFilterCondition
{
private $active;
return $date;
}
}
+// }}}
+// {{{ class UFC_ProfileUpdated
+/** Filters users based on profile update date
+ * @param $comparison Comparison operator
+ * @param $date Date to which profile update date must be compared
+ */
class UFC_ProfileUpdated implements UserFilterCondition
{
private $comparison;
return 'p.last_change ' . $this->comparison . XDB::format(' {?}', date('Y-m-d H:i:s', $this->date));
}
}
+// }}}
+// {{{ class UFC_Birthday
+/** Filters users based on next birthday date
+ * @param $comparison Comparison operator
+ * @param $date Date to which users next birthday date should be compared
+ */
class UFC_Birthday implements UserFilterCondition
{
private $comparison;
return 'p.next_birthday ' . $this->comparison . XDB::format(' {?}', date('Y-m-d', $this->date));
}
}
+// }}}
+// {{{ class UFC_Sex
+/** Filters users based on sex
+ * @parm $sex One of User::GENDER_MALE or User::GENDER_FEMALE, for selecting users
+ */
class UFC_Sex implements UserFilterCondition
{
private $sex;
}
}
}
+// }}}
+// {{{ class UFC_Group
+/** Filters users based on group membership
+ * @param $group Group whose member we are selecting
+ * @param $admin Whether to restrict selection to admins of that group
+ */
class UFC_Group implements UserFilterCondition
{
private $group;
return $where;
}
}
+// }}}
+// {{{ class UFC_Email
+/** Filters users based on email address
+ * @param $email Email whose owner we are looking for
+ */
class UFC_Email implements UserFilterCondition
{
private $email;
}
}
}
+// }}}
+// {{{ class UFC_EmailList
+/** Filters users base on an email list
+ * @param $emails List of emails whose owner must be selected
+ */
class UFC_EmailList implements UserFilterCondition
{
private $emails;
return '(' . implode(') OR (', $cond) . ')';
}
}
+// }}}
+
+// {{{ class UFC_Address
+/** Filters users based on their address
+ * @param $field Field of the address used for filtering (city, street, ...)
+ * @param $text Text for filter
+ * @param $mode Mode for search (PREFIX, SUFFIX, ...)
+ */
+class UFC_Address implements UserFilterCondition
+{
+ const PREFIX = 1;
+ const SUFFIX = 2;
+ const CONTAINS = 3;
+ private $field;
+ private $text;
+ private $mode;
+
+ public function __construct($field, $text, $mode)
+ {
+ $this->field = $field;
+ $this->text = $text;
+ $this->mode = $mode;
+ }
+
+ public function buildCondition(UserFilter &$uf)
+ {
+ $left = 'pa.' . $field;
+ $op = ' LIKE ';
+ if (($this->mode & self::CONTAINS) == 0) {
+ $right = XDB::format('{?}', $this->text);
+ $op = ' = ';
+ } else if (($this->mode & self::CONTAINS) == self::PREFIX) {
+ $right = XDB::format('CONCAT({?}, \'%\')', $this->text);
+ } else if (($this->mode & self::CONTAINS) == self::SUFFIX) {
+ $right = XDB::format('CONCAT(\'%\', {?})', $this->text);
+ } else {
+ $right = XDB::format('CONCAT(\'%\', {?}, \'%\')', $this->text);
+ }
+ $cond = $left . $op . $right;
+ $uf->addAddressFilter();
+ return $cond;
+ }
+}
+// }}}
+
+// {{{ class UFC_Corps
+/** Filters users based on the corps they belong to
+ * @param $corps Corps we are looking for (abbreviation)
+ * @param $type Whether we search for original or current corps
+ */
+class UFC_Corps implements UserFilterCondition
+{
+ const CURRENT=1;
+ const ORIGIN=2;
+
+ private $corps;
+ private $type;
+
+ 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 extends 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 extends 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 extends 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 extends 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_UserRelated
+/** Filters users based on a relation toward on user
+ * @param $user User to which searched users are related
+ */
abstract class UFC_UserRelated implements UserFilterCondition
{
protected $user;
$this->user =& $user;
}
}
+// }}}
+// {{{ class UFC_Contact
+/** Filters users who belongs to selected user's contacts
+ */
class UFC_Contact extends UFC_UserRelated
{
public function buildCondition(UserFilter &$uf)
return 'c' . $sub . '.contact IS NOT NULL';
}
}
+// }}}
+// {{{ class UFC_WatchRegistration
+/** Filters users being watched by selected user
+ */
class UFC_WatchRegistration extends UFC_UserRelated
{
public function buildCondition(UserFilter &$uf)
}
}
}
+// }}}
+// {{{ class UFC_WatchPromo
+/** Filters users belonging to a promo watched by selected user
+ * @param $user Selected user (the one watching promo)
+ * @param $grade Formation the user is watching
+ */
class UFC_WatchPromo extends UFC_UserRelated
{
private $grade;
}
}
}
+// }}}
+// {{{ class UFC_WatchContact
+/** Filters users watched by selected user
+ */
class UFC_WatchContact extends UFC_Contact
{
public function buildCondition(UserFilter &$uf)
return parent::buildCondition($uf);
}
}
+// }}}
/******************
* ORDERS
******************/
+// {{{ class UserFilterOrder
abstract class UserFilterOrder
{
protected $desc = false;
abstract protected function getSortTokens(UserFilter &$uf);
}
+// }}}
+// {{{ class UFO_Promo
+/** Orders users by promo
+ * @param $grade Formation whose promo users should be sorted by (restricts results to users of that formation)
+ * @param $desc Whether sort is descending
+ */
class UFO_Promo extends UserFilterOrder
{
private $grade;
}
}
}
-
+// }}}
+
+// {{{ class UFO_Name
+/** Sorts users by name
+ * @param $type Type of name on which to sort (firstname, ...)
+ * @param $variant Variant of that name to user (marital, ordinary, ...)
+ * @param $particle Set to true if particles should be included in the sorting order
+ * @param $desc If sort order should be descending
+ */
class UFO_Name extends UserFilterOrder
{
private $type;
}
}
}
+// }}}
+// {{{ class UFO_Registration
+/** Sorts users based on registration date
+ */
class UFO_Registration extends UserFilterOrder
{
protected function getSortTokens(UserFilter &$uf)
return 'a.registration_date';
}
}
+// }}}
+// {{{ class UFO_Birthday
+/** Sorts users based on next birthday date
+ */
class UFO_Birthday extends UserFilterOrder
{
protected function getSortTokens(UserFilter &$uf)
return 'p.next_birthday';
}
}
+// }}}
+// {{{ class UFO_ProfileUpdate
+/** Sorts users based on last profile update
+ */
class UFO_ProfileUpdate extends UserFilterOrder
{
protected function getSortTokens(UserFilter &$uf)
return 'p.last_change';
}
}
+// }}}
+// {{{ class UFO_Death
+/** Sorts users based on death date
+ */
class UFO_Death extends UserFilterOrder
{
protected function getSortTokens(UserFilter &$uf)
return 'p.deathdate';
}
}
+// }}}
/***********************************
*********************************
***********************************/
+// {{{ class UserFilter
class UserFilter
{
static private $joinMethods = array();
}
+ /** ADDRESSES
+ */
+ private $pa = false;
+ public function addAddressFilter()
+ {
+ $this->pa = true;
+ }
+
+ private function addressJoins()
+ {
+ $joins = array();
+ if ($this->pa) {
+ $joins['pa'] = array('left', 'profile_address', '$ME.PID = $PID');
+ }
+ return $joins;
+ }
+
+
+ /** CORPS
+ */
+
+ private $pc = false;
+ private $pce = array();
+ private $pcr = false;
+ public function addCorpsFilter($type)
+ {
+ $this->pc = true;
+ if ($type == UFC_Corps::CURRENT) {
+ $pce['pcec'] = 'current_corpsid';
+ return 'pcec';
+ } else if ($type == UFC_Corps::ORIGIN) {
+ $pce['pceo'] = 'original_corpsid';
+ return 'pceo';
+ }
+ }
+
+ public function addCorpsRankFilter()
+ {
+ $this->pc = true;
+ $this->pcr = true;
+ return 'pcr';
+ }
+
+ private function corpsJoins()
+ {
+ $joins = array();
+ if ($this->pc) {
+ $joins['pc'] = array('left', 'profile_corps', '$ME.uid = $UID');
+ }
+ if ($this->pcr) {
+ $joins['pcr'] = array('left', 'profile_corps_rank_enum', '$ME.id = pc.rankid');
+ }
+ foreach($this->pce as $sub => $field) {
+ $joins[$sub] = array('left', 'profile_corps_enum', '$ME.id = pc.' . $field);
+ }
+ return $joins;
+ }
+
+ /** JOBS
+ */
+
+ const JOB_SECTOR = 1;
+ const JOB_SUBSECTOR = 2;
+ const JOB_SUBSUBSECTOR = 4;
+ const JOB_ALTERNATES = 8;
+ const JOB_USERDEFINED = 16;
+
+ /** Joins :
+ * pj => profile_job
+ * pje => profile_job_enum
+ * pjse => profile_job_sector_enum
+ * pjsse => profile_job_subsector_enum
+ * pjssse => profile_job_subsubsector_enum
+ * pja => profile_job_alternates
+ */
+ private $with_pj = false;
+ private $with_pje = false;
+ private $with_pjse = false;
+ private $with_pjsse = false;
+ private $with_pjssse = false;
+ private $with_pja = false;
+
+ public function addJobFilter()
+ {
+ $this->with_pj = true;
+ return 'pj';
+ }
+
+ public function addJobCompanyFilter()
+ {
+ $this->addJobFilter();
+ $this->with_pje = true;
+ return 'pje';
+ }
+
+ public function addJobSectorizationFilter($type)
+ {
+ $this->addJobFilter();
+ if ($type == self::JOB_SECTOR) {
+ $this->with_pjse = true;
+ return 'pjse';
+ } else if ($type == self::JOB_SUBSECTOR) {
+ $this->with_pjsse = true;
+ return 'pjsse';
+ } else if ($type == self::JOB_SUBSUBSECTOR) {
+ $this->with_pjssse = true;
+ return 'pjssse';
+ } else if ($type == self::JOB_ALTERNATES) {
+ $this->with_pja = true;
+ return 'pja';
+ }
+ }
+
+ private function jobJoins()
+ {
+ $joins = array();
+ if ($this->with_pj) {
+ $joins['pj'] = array('left', 'profile_job', '$ME.uid = $UID');
+ }
+ if ($this->with_pje) {
+ $joins['pje'] = array('left', 'profile_job_enum', '$ME.id = pj.jobid');
+ }
+ if ($this->with_pjse) {
+ $joins['pjse'] = array('left', 'profile_job_sector_enum', '$ME.id = pj.sectorid');
+ }
+ if ($this->with_pjsse) {
+ $joins['pjsse'] = array('left', 'profile_job_subsector_enum', '$ME.id = pj.subsectorid');
+ }
+ if ($this->with_pjssse) {
+ $joins['pjssse'] = array('left', 'profile_job_subsubsector_enum', '$ME.id = pj.subsubsectorid');
+ }
+ if ($this->with_pja) {
+ $joins['pja'] = array('left', 'profile_job_alternates', '$ME.subsubsectorid = pj.subsubsectorid');
+ }
+ return $joins;
+ }
+
+ /** NETWORKING
+ */
+
+ private $with_pnw = false;
+ public function addNetworkingFilter()
+ {
+ $this->with_pnw = true;
+ return 'pnw';
+ }
+
+ private function networkingJoins()
+ {
+ $joins = array();
+ if ($this->with_pnw) {
+ $joins['pnw'] = array('left', 'profile_networking', '$ME.uid = $UID');
+ }
+ return $joins;
+ }
+
/** CONTACTS
*/
private $cts = array();
return $joins;
}
}
-
+// }}}
// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
?>