Commit | Line | Data |
---|---|---|
8c4a0c30 | 1 | <?php |
2 | /*************************************************************************** | |
8d84c630 | 3 | * Copyright (C) 2003-2009 Polytechnique.org * |
8c4a0c30 | 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 | ||
8c4a0c30 | 22 | class UserSet extends PlSet |
23 | { | |
8e720253 | 24 | public function __construct(PlFilterCondition &$cond, $orders) |
8c4a0c30 | 25 | { |
8e720253 | 26 | parent::__construct($cond, $orders); |
76cbe885 FB |
27 | } |
28 | ||
8e720253 | 29 | protected function buildFilter(PlFilterCondition &$cond, $orders) |
76cbe885 | 30 | { |
8e720253 | 31 | return new UserFilter($cond, $orders); |
8c4a0c30 | 32 | } |
33 | } | |
34 | ||
35 | class SearchSet extends UserSet | |
36 | { | |
86b5c8f0 | 37 | public $advanced = false; |
8e720253 RB |
38 | private $score = null; |
39 | private $conds = null; | |
40 | private $orders = null; | |
41 | private $quick = false; | |
8c4a0c30 | 42 | |
8e720253 | 43 | public function __construct($quick = false, $no_search = false, PlFilterCondition $cond = null) |
8c4a0c30 | 44 | { |
adb07f6f | 45 | Platal::load('search', 'search.inc.php'); |
8e720253 | 46 | |
8c4a0c30 | 47 | if ($no_search) { |
48 | return; | |
49 | } | |
50 | ||
51 | $this->quick = $quick; | |
8e720253 RB |
52 | |
53 | if (is_null($cond)) { | |
54 | $this->conds = new PFC_And(); | |
55 | } else if ($cond instanceof PFC_And) { | |
56 | $this->conds = $cond; | |
57 | } else { | |
58 | $this->conds = new PFC_And($cond); | |
59 | } | |
60 | ||
8c4a0c30 | 61 | if ($quick) { |
8e720253 | 62 | $this->getQuick(); |
8c4a0c30 | 63 | } else { |
8e720253 | 64 | $this->getAdvanced(); |
8c4a0c30 | 65 | } |
66 | } | |
67 | ||
8e720253 | 68 | private function getQuick() |
8c4a0c30 | 69 | { |
8c4a0c30 | 70 | if (!S::logged()) { |
71 | Env::kill('with_soundex'); | |
72 | } | |
8e720253 RB |
73 | |
74 | require_once 'ufbuilder.inc.php'; | |
75 | $ufb = new UFB_QuickSearch(); | |
76 | ||
77 | if (!$ufb->isValid()) { | |
78 | return; | |
3b2f9d11 | 79 | } |
8e720253 RB |
80 | |
81 | $this->conds->addChild($ufb->getUFC()); | |
82 | ||
83 | $orders = $ufb->getOrders(); | |
84 | $orders[] = new UFO_Promo(UserFilter::DISPLAY, true); | |
85 | $orders[] = new UFO_Promo(UserFilter::DN_SORT); | |
86 | ||
3b2f9d11 | 87 | if (S::logged() && Env::has('nonins')) { |
8e720253 RB |
88 | $this->conds = new PFC_And($this->conds, |
89 | new UFC_Not(new UFC_Dead()), | |
90 | new UFC_Registered() | |
91 | ); | |
3b2f9d11 | 92 | } |
8c4a0c30 | 93 | |
8e720253 | 94 | parent::__construct($this->conds, $orders); |
8c4a0c30 | 95 | } |
96 | ||
8e720253 | 97 | private function getAdvanced() |
8c4a0c30 | 98 | { |
86b5c8f0 | 99 | $this->advanced = true; |
8e720253 RB |
100 | require_once 'ufbuilder.inc.php'; |
101 | $ufb = new UFB_AdvancedSearch(); | |
102 | ||
103 | if (!$ufb->isValid()) { | |
104 | return; | |
8c4a0c30 | 105 | } |
8e720253 RB |
106 | |
107 | $this->conds->addChild($ufb->getUFC()); | |
8c4a0c30 | 108 | } |
35fa92e8 | 109 | |
8e720253 | 110 | public function &get(PlLimit $limit = null) |
35fa92e8 | 111 | { |
8e720253 RB |
112 | $uf = $this->buildFilter($this->conds, $this->orders); |
113 | if (is_null($limit)) { | |
114 | $limit = new PlLimit(20, 0); | |
35fa92e8 | 115 | } |
8e720253 RB |
116 | $it = $uf->getProfiles($limit); |
117 | $this->count = $uf->getTotalCount(); | |
118 | return $it; | |
35fa92e8 | 119 | } |
8c4a0c30 | 120 | } |
121 | ||
1cc0afe7 | 122 | class ArraySet extends UserSet |
123 | { | |
124 | public function __construct(array $users) | |
125 | { | |
8e720253 RB |
126 | $hruids = User::getBulkHruid($users, array('User', '_silent_user_callback')); |
127 | if (is_null($hruids) || count($hruids) == 0) { | |
128 | $cond = new PFC_False(); | |
1cc0afe7 | 129 | } else { |
8e720253 | 130 | $cond = new UFC_Hruid($hruids); |
1cc0afe7 | 131 | } |
8e720253 | 132 | parent::__construct($cond); |
1cc0afe7 | 133 | } |
134 | } | |
135 | ||
8c4a0c30 | 136 | class MinificheView extends MultipageView |
137 | { | |
138 | public function __construct(PlSet &$set, $data, array $params) | |
139 | { | |
f711b03f | 140 | require_once 'education.func.inc.php'; |
8c4a0c30 | 141 | global $globals; |
142 | $this->entriesPerPage = $globals->search->per_page; | |
35fa92e8 | 143 | if (@$params['with_score']) { |
8e720253 RB |
144 | $this->addSort(new PlViewOrder('score', array( |
145 | new UFO_Score(true), | |
146 | new UFO_ProfileUpdate(true), | |
147 | new UFO_Promo(UserFilter::DISPLAY, true), | |
148 | new UFO_Name(UserFilter::DN_SORT), | |
149 | ), 'pertinence')); | |
35fa92e8 | 150 | } |
8e720253 RB |
151 | $this->addSort(new PlViewOrder( |
152 | 'name', | |
153 | array(new UFO_Name(UserFilter::DN_SORT)), | |
154 | 'nom')); | |
155 | $this->addSort(new PlViewOrder('promo', array( | |
156 | new UFO_Promo(UserFilter::DISPLAY, true), | |
157 | new UFO_Name(UserFilter::DN_SORT), | |
158 | ), 'promotion')); | |
159 | $this->addSort(new PlViewOrder('date_mod', array( | |
160 | new UFO_ProfileUpdate(true), | |
161 | new UFO_Promo(UserFilter::DISPLAY, true), | |
162 | new UFO_Name(UserFilter::DN_SORT), | |
163 | ), 'dernière modification')); | |
8c4a0c30 | 164 | parent::__construct($set, $data, $params); |
165 | } | |
166 | ||
8e720253 | 167 | protected function getBoundValue($obj) |
8c4a0c30 | 168 | { |
8e720253 RB |
169 | if ($obj instanceof Profile) { |
170 | switch ($this->bound_field) { | |
171 | case 'name': | |
172 | $name = $obj->name('%l'); | |
173 | return strtoupper($name[0]); | |
174 | case 'promo': | |
175 | return $obj->promo(); | |
176 | default: | |
177 | return null; | |
178 | } | |
179 | } | |
76cbe885 | 180 | return null; |
8c4a0c30 | 181 | } |
182 | ||
8e720253 | 183 | public function bounds() |
b71b2a36 | 184 | { |
8e720253 RB |
185 | $order = Env::v('order', $this->defaultkey); |
186 | $show_bounds = 0; | |
187 | if (($order == "name") || ($order == "-name")) { | |
188 | $this->bound_field = "name"; | |
189 | $show_bounds = 1; | |
190 | } elseif (($order == "promo") || ($order == "-promo")) { | |
191 | $this->bound_field = "promo"; | |
192 | $show_bounds = -1; | |
193 | } | |
194 | if ($order{0} == '-') { | |
195 | $show_bounds = -$show_bounds; | |
196 | } | |
197 | return $show_bounds; | |
b71b2a36 SJ |
198 | } |
199 | ||
8c4a0c30 | 200 | public function templateName() |
201 | { | |
202 | return 'include/plview.minifiche.tpl'; | |
203 | } | |
204 | } | |
205 | ||
ff3eb9b7 | 206 | class MentorView extends MultipageView |
207 | { | |
208 | public function __construct(PlSet &$set, $data, array $params) | |
209 | { | |
eaf30d86 | 210 | $this->entriesPerPage = 10; |
8e720253 RB |
211 | $this->addSort(new PlViewOrder('rand', array(new PFO_Random(S::i('uid'))), 'aléatoirement')); |
212 | $this->addSort(new PlViewOrder('name', array(new UFO_Name(UserFilter::DN_SORT)), 'nom')); | |
213 | $this->addSort(new PlViewOrder('promo', array( | |
214 | new UFO_Promo(UserFilter::DISPLAY, true), | |
215 | new UFO_Name(UserFilter::DN_SORT), | |
216 | ), 'promotion')); | |
217 | $this->addSort(new PlViewOrder('date_mod', array( | |
218 | new UFO_ProfileUpdate(true), | |
219 | new UFO_Promo(UserFilter::DISPLAY, true), | |
220 | new UFO_Name(UserFilter::DN_SORT), | |
221 | ), 'dernière modification')); | |
eaf30d86 | 222 | parent::__construct($set, $data, $params); |
ff3eb9b7 | 223 | } |
224 | ||
8e720253 | 225 | protected function getBoundValue($obj) |
cd5bd7dc | 226 | { |
8e720253 RB |
227 | if ($obj instanceof Profile) { |
228 | switch ($this->bound_field) { | |
229 | case 'name': | |
230 | $name = $obj->name('%l'); | |
231 | return strtoupper($name[0]); | |
232 | case 'promo': | |
233 | return $obj->promo(); | |
234 | default: | |
235 | return null; | |
236 | } | |
237 | } | |
238 | return null; | |
ff3eb9b7 | 239 | } |
240 | ||
b71b2a36 SJ |
241 | public function bounds() |
242 | { | |
243 | $order = Env::v('order', $this->defaultkey); | |
244 | $show_bounds = 0; | |
245 | if (($order == "name") || ($order == "-name")) { | |
246 | $this->bound_field = "nom"; | |
247 | $show_bounds = 1; | |
248 | } elseif (($order == "promo") || ($order == "-promo")) { | |
249 | $this->bound_field = "promo"; | |
250 | $show_bounds = -1; | |
251 | } | |
252 | if ($order{0} == '-') { | |
253 | $show_bounds = -$show_bounds; | |
254 | } | |
255 | return $show_bounds; | |
256 | } | |
257 | ||
ff3eb9b7 | 258 | public function templateName() |
259 | { | |
260 | return 'include/plview.referent.tpl'; | |
261 | } | |
262 | } | |
263 | ||
8c4a0c30 | 264 | class TrombiView extends MultipageView |
265 | { | |
266 | public function __construct(PlSet &$set, $data, array $params) | |
267 | { | |
268 | $this->entriesPerPage = 24; | |
35fa92e8 | 269 | if (@$params['with_score']) { |
8e720253 RB |
270 | $this->addSort(new PlViewOrder('score', array( |
271 | new UFO_Score(true), | |
272 | new UFO_ProfileUpdate(true), | |
273 | new UFO_Promo(UserFilter::DISPLAY, true), | |
274 | new UFO_Name(UserFilter::DN_SORT), | |
275 | ), 'pertinence')); | |
35fa92e8 | 276 | } |
8e720253 RB |
277 | $this->addSort(new PlViewOrder('name', array(new UFO_Name(UserFilter::DN_SORT)), 'nom')); |
278 | $this->addSort(new PlViewOrder('promo', array( | |
279 | new UFO_Promo(UserFilter::DISPLAY, true), | |
280 | new UFO_Name(UserFilter::DN_SORT), | |
281 | ), 'promotion')); | |
8c4a0c30 | 282 | parent::__construct($set, $data, $params); |
283 | } | |
284 | ||
8e720253 | 285 | protected function getBoundValue($obj) |
8c4a0c30 | 286 | { |
8e720253 RB |
287 | if ($obj instanceof Profile) { |
288 | switch ($this->bound_field) { | |
289 | case 'name': | |
290 | $name = $obj->name('%l'); | |
291 | return strtoupper($name[0]); | |
292 | case 'promo': | |
293 | return $obj->promo(); | |
294 | default: | |
295 | return null; | |
296 | } | |
297 | } | |
298 | return null; | |
8c4a0c30 | 299 | } |
300 | ||
b71b2a36 SJ |
301 | public function bounds() |
302 | { | |
303 | $order = Env::v('order', $this->defaultkey); | |
304 | $show_bounds = 0; | |
305 | if (($order == "name") || ($order == "-name")) { | |
306 | $this->bound_field = "nom"; | |
307 | $show_bounds = 1; | |
308 | } elseif (($order == "promo") || ($order == "-promo")) { | |
309 | $this->bound_field = "promo"; | |
310 | $show_bounds = -1; | |
311 | } | |
312 | if ($order{0} == '-') { | |
313 | $show_bounds = -$show_bounds; | |
314 | } | |
315 | return $show_bounds; | |
316 | } | |
317 | ||
8c4a0c30 | 318 | public function templateName() |
319 | { | |
320 | return 'include/plview.trombi.tpl'; | |
321 | } | |
322 | ||
04334c61 | 323 | public function apply(PlPage &$page) |
8c4a0c30 | 324 | { |
325 | if (!empty($GLOBALS['IS_XNET_SITE'])) { | |
326 | global $globals; | |
327 | $page->assign('mainsiteurl', 'https://' . $globals->core->secure_domain . '/'); | |
328 | } | |
329 | return parent::apply($page); | |
330 | } | |
331 | } | |
332 | ||
92e80560 VZ |
333 | class GadgetView implements PlView |
334 | { | |
335 | public function __construct(PlSet &$set, $data, array $params) | |
336 | { | |
337 | $this->set =& $set; | |
338 | } | |
339 | ||
04334c61 | 340 | public function apply(PlPage &$page) |
92e80560 | 341 | { |
8e720253 | 342 | $page->assign_by_ref('set', $this->set->get(new PlLimit(5, 0))); |
92e80560 VZ |
343 | } |
344 | ||
345 | public function args() | |
346 | { | |
347 | return null; | |
348 | } | |
349 | } | |
350 | ||
8c4a0c30 | 351 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: |
352 | ?> |