2 /***************************************************************************
3 * Copyright (C) 2003-2010 Polytechnique.org *
4 * http://opensource.polytechnique.org/ *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the Free Software *
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
20 ***************************************************************************/
22 // {{{ class UFO_Promo
23 /** Orders users by promotion
24 * @param $grade Formation whose promotion users should be sorted by (restricts results to users of that formation)
25 * @param $desc Whether sort is descending
27 class UFO_Promo
extends PlFilterGroupableOrder
31 public function __construct($grade = null
, $desc = false
)
33 parent
::__construct($desc);
34 $this->grade
= $grade;
37 protected function getSortTokens(PlFilter
$uf)
39 if (UserFilter
::isGrade($this->grade
)) {
40 $sub = $uf->addEducationFilter($this->grade
);
41 return 'pe' . $sub . '.' . UserFilter
::promoYear($this->grade
);
43 $sub = $uf->addDisplayFilter();
44 return 'pd' . $sub . '.promo';
51 /** Sorts users by name
52 * @param $type Type of name on which to sort (firstname...)
53 * @param $variant Variant of that name to use (marital, ordinary...)
54 * @param $particle Set to true if particles should be included in the sorting order
55 * @param $desc If sort order should be descending
57 class UFO_Name
extends PlFilterOrder
63 public function __construct($type, $variant = null
, $particle = false
, $desc = false
)
65 parent
::__construct($desc);
67 $this->variant
= $variant;
68 $this->particle
= $particle;
71 protected function getSortTokens(PlFilter
$uf)
73 if (Profile
::isDisplayName($this->type
)) {
74 $sub = $uf->addDisplayFilter();
75 $token = 'pd' . $sub . '.' . $this->type
;
76 if ($uf->accountsRequired()) {
77 $account_token = Profile
::getAccountEquivalentName($this->type
);
78 return 'IFNULL(' . $token . ', a.' . $account_token . ')';
83 $sub = $uf->addNameFilter($this->type
, $this->variant
);
84 if ($this->particle
) {
85 return 'CONCAT(pn' . $sub . '.particle, \' \', pn' . $sub . '.name)';
87 return 'pn' . $sub . '.name';
94 // {{{ class UFO_Score
95 class UFO_Score
extends PlFilterOrder
97 protected function getSortTokens(PlFilter
$uf)
99 $toks = $uf->getNameTokens();
102 // If there weren't any sort tokens, we shouldn't sort by score, sort by NULL instead
103 if (count($toks) == 0) {
107 foreach ($toks as $sub => $token) {
108 $scores[] = XDB
::format('SUM(' . $sub . '.score + IF (' . $sub . '.token = {?}, 5, 0) )', $token);
110 return implode(' + ', $scores);
115 // {{{ class UFO_Registration
116 /** Sorts users based on registration date
118 class UFO_Registration
extends PlFilterOrder
120 protected function getSortTokens(PlFilter
$uf)
122 $uf->requireAccounts();
123 return 'a.registration_date';
128 // {{{ class UFO_Birthday
129 /** Sorts users based on next birthday date
131 class UFO_Birthday
extends PlFilterOrder
133 protected function getSortTokens(PlFilter
$uf)
135 $uf->requireProfiles();
136 return 'p.next_birthday';
141 // {{{ class UFO_ProfileUpdate
142 /** Sorts users based on last profile update
144 class UFO_ProfileUpdate
extends PlFilterOrder
146 protected function getSortTokens(PlFilter
$uf)
148 $uf->requireProfiles();
149 return 'p.last_change';
154 // {{{ class UFO_Death
155 /** Sorts users based on death date
157 class UFO_Death
extends PlFilterOrder
159 protected function getSortTokens(PlFilter
$uf)
161 $uf->requireProfiles();
162 return 'p.deathdate';
168 /** Sorts users based on their uid
170 class UFO_Uid
extends PlFilterOrder
172 protected function getSortTokens(PlFilter
$uf)
174 $uf->requireAccounts();
180 // {{{ class UFO_Hruid
181 /** Sorts users based on their hruid
183 class UFO_Hruid
extends PlFilterOrder
185 protected function getSortTokens(PlFilter
$uf)
187 $uf->requireAccounts();
194 /** Sorts users based on their pid
196 class UFO_Pid
extends PlFilterOrder
198 protected function getSortTokens(PlFilter
$uf)
200 $uf->requireProfiles();
206 // {{{ class UFO_Hrpid
207 /** Sorts users based on their hrpid
209 class UFO_Hrpid
extends PlFilterOrder
211 protected function getSortTokens(PlFilter
$uf)
213 $uf->requireProfiles();
219 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: