| 1 | <?php |
| 2 | /*************************************************************************** |
| 3 | * Copyright (C) 2003-2010 Polytechnique.org * |
| 4 | * http://opensource.polytechnique.org/ * |
| 5 | * * |
| 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. * |
| 10 | * * |
| 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. * |
| 15 | * * |
| 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 * |
| 18 | * Foundation, Inc., * |
| 19 | * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * |
| 20 | ***************************************************************************/ |
| 21 | |
| 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 |
| 26 | */ |
| 27 | class UFO_Promo extends PlFilterGroupableOrder |
| 28 | { |
| 29 | private $grade; |
| 30 | |
| 31 | public function __construct($grade = null, $desc = false) |
| 32 | { |
| 33 | parent::__construct($desc); |
| 34 | $this->grade = $grade; |
| 35 | } |
| 36 | |
| 37 | protected function getSortTokens(PlFilter $uf) |
| 38 | { |
| 39 | if (UserFilter::isGrade($this->grade)) { |
| 40 | $sub = $uf->addEducationFilter($this->grade); |
| 41 | return 'pe' . $sub . '.' . UserFilter::promoYear($this->grade); |
| 42 | } else { |
| 43 | $sub = $uf->addDisplayFilter(); |
| 44 | return 'pd' . $sub . '.promo'; |
| 45 | } |
| 46 | } |
| 47 | } |
| 48 | // }}} |
| 49 | |
| 50 | // {{{ class UFO_Name |
| 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 |
| 56 | */ |
| 57 | class UFO_Name extends PlFilterOrder |
| 58 | { |
| 59 | private $type; |
| 60 | private $variant; |
| 61 | private $particle; |
| 62 | |
| 63 | public function __construct($type, $variant = null, $particle = false, $desc = false) |
| 64 | { |
| 65 | parent::__construct($desc); |
| 66 | $this->type = $type; |
| 67 | $this->variant = $variant; |
| 68 | $this->particle = $particle; |
| 69 | } |
| 70 | |
| 71 | protected function getSortTokens(PlFilter $uf) |
| 72 | { |
| 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 . ')'; |
| 79 | } else { |
| 80 | return $token; |
| 81 | } |
| 82 | } else { |
| 83 | $sub = $uf->addNameFilter($this->type, $this->variant); |
| 84 | if ($this->particle) { |
| 85 | return 'CONCAT(pn' . $sub . '.particle, \' \', pn' . $sub . '.name)'; |
| 86 | } else { |
| 87 | return 'pn' . $sub . '.name'; |
| 88 | } |
| 89 | } |
| 90 | } |
| 91 | } |
| 92 | // }}} |
| 93 | |
| 94 | // {{{ class UFO_Score |
| 95 | class UFO_Score extends PlFilterOrder |
| 96 | { |
| 97 | protected function getSortTokens(PlFilter $uf) |
| 98 | { |
| 99 | $toks = $uf->getNameTokens(); |
| 100 | $scores = array(); |
| 101 | |
| 102 | // If there weren't any sort tokens, we shouldn't sort by score, sort by NULL instead |
| 103 | if (count($toks) == 0) { |
| 104 | return 'NULL'; |
| 105 | } |
| 106 | |
| 107 | foreach ($toks as $sub => $token) { |
| 108 | $scores[] = XDB::format('SUM(' . $sub . '.score + IF (' . $sub . '.token = {?}, 5, 0) )', $token); |
| 109 | } |
| 110 | return implode(' + ', $scores); |
| 111 | } |
| 112 | } |
| 113 | // }}} |
| 114 | |
| 115 | // {{{ class UFO_Registration |
| 116 | /** Sorts users based on registration date |
| 117 | */ |
| 118 | class UFO_Registration extends PlFilterOrder |
| 119 | { |
| 120 | protected function getSortTokens(PlFilter $uf) |
| 121 | { |
| 122 | $uf->requireAccounts(); |
| 123 | return 'a.registration_date'; |
| 124 | } |
| 125 | } |
| 126 | // }}} |
| 127 | |
| 128 | // {{{ class UFO_Birthday |
| 129 | /** Sorts users based on next birthday date |
| 130 | */ |
| 131 | class UFO_Birthday extends PlFilterOrder |
| 132 | { |
| 133 | protected function getSortTokens(PlFilter $uf) |
| 134 | { |
| 135 | $uf->requireProfiles(); |
| 136 | return 'p.next_birthday'; |
| 137 | } |
| 138 | } |
| 139 | // }}} |
| 140 | |
| 141 | // {{{ class UFO_ProfileUpdate |
| 142 | /** Sorts users based on last profile update |
| 143 | */ |
| 144 | class UFO_ProfileUpdate extends PlFilterOrder |
| 145 | { |
| 146 | protected function getSortTokens(PlFilter $uf) |
| 147 | { |
| 148 | $uf->requireProfiles(); |
| 149 | return 'p.last_change'; |
| 150 | } |
| 151 | } |
| 152 | // }}} |
| 153 | |
| 154 | // {{{ class UFO_Death |
| 155 | /** Sorts users based on death date |
| 156 | */ |
| 157 | class UFO_Death extends PlFilterOrder |
| 158 | { |
| 159 | protected function getSortTokens(PlFilter $uf) |
| 160 | { |
| 161 | $uf->requireProfiles(); |
| 162 | return 'p.deathdate'; |
| 163 | } |
| 164 | } |
| 165 | // }}} |
| 166 | |
| 167 | // {{{ class UFO_Uid |
| 168 | /** Sorts users based on their uid |
| 169 | */ |
| 170 | class UFO_Uid extends PlFilterOrder |
| 171 | { |
| 172 | protected function getSortTokens(PlFilter $uf) |
| 173 | { |
| 174 | $uf->requireAccounts(); |
| 175 | return '$UID'; |
| 176 | } |
| 177 | } |
| 178 | // }}} |
| 179 | |
| 180 | // {{{ class UFO_Hruid |
| 181 | /** Sorts users based on their hruid |
| 182 | */ |
| 183 | class UFO_Hruid extends PlFilterOrder |
| 184 | { |
| 185 | protected function getSortTokens(PlFilter $uf) |
| 186 | { |
| 187 | $uf->requireAccounts(); |
| 188 | return 'a.hruid'; |
| 189 | } |
| 190 | } |
| 191 | // }}} |
| 192 | |
| 193 | // {{{ class UFO_Pid |
| 194 | /** Sorts users based on their pid |
| 195 | */ |
| 196 | class UFO_Pid extends PlFilterOrder |
| 197 | { |
| 198 | protected function getSortTokens(PlFilter $uf) |
| 199 | { |
| 200 | $uf->requireProfiles(); |
| 201 | return '$PID'; |
| 202 | } |
| 203 | } |
| 204 | // }}} |
| 205 | |
| 206 | // {{{ class UFO_Hrpid |
| 207 | /** Sorts users based on their hrpid |
| 208 | */ |
| 209 | class UFO_Hrpid extends PlFilterOrder |
| 210 | { |
| 211 | protected function getSortTokens(PlFilter $uf) |
| 212 | { |
| 213 | $uf->requireProfiles(); |
| 214 | return 'p.hrpid'; |
| 215 | } |
| 216 | } |
| 217 | // }}} |
| 218 | |
| 219 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: |
| 220 | ?> |