UserFilter::assertGrade($this->grade);
}
if ($this->grade == UserFilter::DISPLAY && $this->comparison != '=') {
- Platal::page()->killError('Comparison ' . $this->comparison . ' not allowed on displaid promo');
+ // XXX: we might try to guess the grade from the first char of the promo and forbid only '<= 2004', but allow '<= X2004'
+ Platal::page()->killError("Il n'est pas possible d'appliquer la comparaison '" . $this->comparison . "' aux promotions sans spécifier de formation (X/M/D)");
}
}
public function buildCondition(PlFilter &$uf)
{
$sub = $uf->addJobCompanyFilter();
- $cond = $sub . '.' . $this->type . ' = ' . XDB::format('{?}', $this->value);
+ $cond = $sub . '.' . $this->type . XDB::formatWildcards(XDB::WILDCARD_CONTAINS, $this->value);
return $cond;
}
}
$conds = array();
$conds[] = $sub . '.address ' . XDB::formatWildcards(XDB::WILDCARD_CONTAINS, $this->value);
if ($this->type != -1) {
- $conds[] = $sub . '.network_type = ' . XDB::format('{?}', $this->type);
+ $conds[] = $sub . '.nwid = ' . XDB::format('{?}', $this->type);
}
return implode(' AND ', $conds);
}
public function __construct($number, $num_type = self::NUM_ANY, $phone_type = self::PHONE_ANY)
{
- require_once('profil.func.inc.php');
- $this->number = $number;
+ $phone = new Phone(array('display' => $number));
+ $phone->format();
+ $this->number = $phone->search();
$this->num_type = $num_type;
- $this->phone_type = format_phone_number($phone_type);
+ $this->phone_type = $phone_type;
}
public function buildCondition(PlFilter &$uf)
* ORDERS
******************/
-// {{{ class UserFilterOrder
-/** Base class for ordering results of a query.
- * Parameters for the ordering must be given to the constructor ($desc for a
- * descending order).
- * The getSortTokens function is used to get actual ordering part of the query.
- */
-abstract class UserFilterOrder extends PlFilterOrder
-{
- /** This function must return the tokens to use for ordering
- * @param &$uf The UserFilter whose results must be ordered
- * @return The name of the field to use for ordering results
- */
-// abstract protected function getSortTokens(UserFilter &$uf);
-}
-// }}}
-
// {{{ class UFO_Promo
/** Orders users by promotion
* @param $grade Formation whose promotion users should be sorted by (restricts results to users of that formation)
* @param $desc Whether sort is descending
*/
-class UFO_Promo extends UserFilterOrder
+class UFO_Promo extends PlFilterGroupableOrder
{
private $grade;
* @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
+class UFO_Name extends PlFilterOrder
{
private $type;
private $variant;
{
if (Profile::isDisplayName($this->type)) {
$sub = $uf->addDisplayFilter();
- return 'pd' . $sub . '.' . $this->type;
+ $token = 'pd' . $sub . '.' . $this->type;
+ if ($uf->accountsRequired()) {
+ $account_token = Profile::getAccountEquivalentName($this->type);
+ return 'IFNULL(' . $token . ', a.' . $account_token . ')';
+ } else {
+ return $token;
+ }
} else {
$sub = $uf->addNameFilter($this->type, $this->variant);
if ($this->particle) {
// }}}
// {{{ class UFO_Score
-class UFO_Score extends UserFilterOrder
+class UFO_Score extends PlFilterOrder
{
protected function getSortTokens(PlFilter &$uf)
{
$toks = $uf->getNameTokens();
$scores = array();
+
+ // If there weren't any sort tokens, we shouldn't sort by score, sort by NULL instead
+ if (count($toks) == 0) {
+ return 'NULL';
+ }
+
foreach ($toks as $sub => $token) {
$scores[] = XDB::format('SUM(' . $sub . '.score + IF (' . $sub . '.token = {?}, 5, 0) )', $token);
}
// {{{ class UFO_Registration
/** Sorts users based on registration date
*/
-class UFO_Registration extends UserFilterOrder
+class UFO_Registration extends PlFilterOrder
{
protected function getSortTokens(PlFilter &$uf)
{
// {{{ class UFO_Birthday
/** Sorts users based on next birthday date
*/
-class UFO_Birthday extends UserFilterOrder
+class UFO_Birthday extends PlFilterOrder
{
protected function getSortTokens(PlFilter &$uf)
{
// {{{ class UFO_ProfileUpdate
/** Sorts users based on last profile update
*/
-class UFO_ProfileUpdate extends UserFilterOrder
+class UFO_ProfileUpdate extends PlFilterOrder
{
protected function getSortTokens(PlFilter &$uf)
{
// {{{ class UFO_Death
/** Sorts users based on death date
*/
-class UFO_Death extends UserFilterOrder
+class UFO_Death extends PlFilterOrder
{
protected function getSortTokens(PlFilter &$uf)
{
// {{{ class UFO_Uid
/** Sorts users based on their uid
*/
-class UFO_Uid extends UserFilterOrder
+class UFO_Uid extends PlFilterOrder
{
protected function getSortTokens(PlFilter &$uf)
{
// {{{ class UFO_Hruid
/** Sorts users based on their hruid
*/
-class UFO_Hruid extends UserFilterOrder
+class UFO_Hruid extends PlFilterOrder
{
protected function getSortTokens(PlFilter &$uf)
{
// {{{ class UFO_Pid
/** Sorts users based on their pid
*/
-class UFO_Pid extends UserFilterOrder
+class UFO_Pid extends PlFilterOrder
{
protected function getSortTokens(PlFilter &$uf)
{
// {{{ class UFO_Hrpid
/** Sorts users based on their hrpid
*/
-class UFO_Hrpid extends UserFilterOrder
+class UFO_Hrpid extends PlFilterOrder
{
protected function getSortTokens(PlFilter &$uf)
{
* when referring to the joined table.
*
* For example, if data from profile_job must be available to filter results,
- * the UFC object will call $uf-addJobFilter(), which will set the 'with_pj' var and
+ * the UFC object will call $uf-addJobFilter(), which will set the 'with_pj' var and
* return 'pj', the short name to use when referring to profile_job; when building
* the query, calling the jobJoins function will return an array containing a single
* row:
private $root;
private $sort = array();
+ private $grouper = null;
private $query = null;
private $orderby = null;
}
}
if (!is_null($sort)) {
- if ($sort instanceof UserFilterOrder) {
+ if ($sort instanceof PlFilterOrder) {
$this->addSort($sort);
} else if (is_array($sort)) {
foreach ($sort as $s) {
}
}
+ public function hasGroups()
+ {
+ return $this->grouper != null;
+ }
+
+ public function getGroups()
+ {
+ return $this->getUIDGroups();
+ }
+
+ public function getUIDGroups()
+ {
+ $this->requireAccounts();
+ $this->buildQuery();
+ $token = $this->grouper->getGroupToken($this);
+
+ $groups = XDB::fetchAllRow('SELECT ' . $token . ', COUNT(a.uid)
+ ' . $this->query . '
+ GROUP BY ' . $token,
+ 0);
+ return $groups;
+ }
+
+ public function getPIDGroups()
+ {
+ $this->requireProfiles();
+ $this->buildQuery();
+ $token = $this->grouper->getGroupToken($this);
+
+ $groups = XDB::fetchAllRow('SELECT ' . $token . ', COUNT(p.pid)
+ ' . $this->query . '
+ GROUP BY ' . $token,
+ 0);
+ return $groups;
+ }
+
private function getUIDList($uids = null, PlLimit &$limit)
{
$this->requireAccounts();
$this->buildQuery();
$lim = $limit->getSql();
$cond = '';
- if (!is_null($uids)) {
+ if (!empty($uids)) {
$cond = XDB::format(' AND a.uid IN {?}', $uids);
}
$fetched = XDB::fetchColumn('SELECT SQL_CALC_FOUND_ROWS a.uid
public function getUID($pos = 0)
{
- $uids =$this->getUIDList(null, new PlFilter(1, $pos));
+ $uids =$this->getUIDList(null, new PlLimit(1, $pos));
if (count($uids) == 0) {
return null;
} else {
public function getPID($pos = 0)
{
- $pids =$this->getPIDList(null, new PlFilter(1, $pos));
+ $pids =$this->getPIDList(null, new PlLimit(1, $pos));
if (count($pids) == 0) {
return null;
} else {
public function addSort(PlFilterOrder &$sort)
{
+ if (count($this->sort) == 0 && $sort instanceof PlFilterGroupableOrder)
+ {
+ $this->grouper = $sort;
+ }
$this->sort[] = $sort;
$this->orderby = null;
}
$this->with_accounts = true;
}
+ public function accountsRequired()
+ {
+ return $this->with_accounts;
+ }
+
public function requireProfiles()
{
$this->with_profiles = true;
}
+ public function profilesRequired()
+ {
+ return $this->with_profiles;
+ }
+
protected function accountJoins()
{
$joins = array();
if (!is_array($key)) {
$key = array($key);
}
- $joins['e' . $sub] = PlSqlJoin::left('emails', '$ME.uid = $UID AND $ME.flags != \'filter\'
- AND $ME.email IN {?}' . $key);
+ $joins['e' . $sub] = PlSqlJoin::left('emails', '$ME.uid = $UID AND $ME.flags != \'filter\'
+ AND $ME.email IN {?}', $key);
}
}
foreach ($this->al as $sub=>$key) {
if (!is_array($key)) {
$key = array($key);
}
- $joins['al' . $sub] = PlSqlJoin::left('aliases', '$ME.uid = $UID AND $ME.type IN (\'alias\', \'a_vie\')
+ $joins['al' . $sub] = PlSqlJoin::left('aliases', '$ME.uid = $UID AND $ME.type IN (\'alias\', \'a_vie\')
AND $ME.alias IN {?}', $key);
}
}
{
return $this->getTotalProfileCount();
}
+
+ public function getGroups()
+ {
+ return $this->getPIDGroups();
+ }
}
// }}}