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