Removes dead code from modules/search/*.inc.php.
[platal.git] / include / userset.inc.php
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 UserSet extends PlSet
23 {
24 public function __construct(PlFilterCondition &$cond, $orders = null)
25 {
26 parent::__construct($cond, $orders);
27 }
28
29 protected function buildFilter(PlFilterCondition &$cond, $orders)
30 {
31 return new UserFilter($cond, $orders);
32 }
33 }
34
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
49 {
50 public $advanced = false;
51 private $score = null;
52 private $quick = false;
53
54 public function __construct($quick = false, $no_search = false, PlFilterCondition $cond = null)
55 {
56 if ($no_search) {
57 return;
58 }
59
60 $this->quick = $quick;
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
70 if ($quick) {
71 $this->getQuick();
72 } else {
73 $this->getAdvanced();
74 }
75 }
76
77 private function getQuick()
78 {
79 if (!S::logged()) {
80 Env::kill('with_soundex');
81 }
82
83 require_once 'ufbuilder.inc.php';
84 $ufb = new UFB_QuickSearch();
85
86 if (!$ufb->isValid()) {
87 return;
88 }
89
90 $ufc = $ufb->getUFC();
91 $this->conds->addChild($ufc);
92
93 $orders = $ufb->getOrders();
94 $orders[] = new UFO_Promo(UserFilter::DISPLAY, true);
95 $orders[] = new UFO_Name(Profile::DN_SORT);
96
97 if (S::logged() && Env::has('nonins')) {
98 $this->conds = new PFC_And($this->conds,
99 new PFC_Not(new UFC_Dead()),
100 new PFC_Not(new UFC_Registered())
101 );
102 }
103
104 parent::__construct($this->conds, $orders);
105 }
106
107 private function getAdvanced()
108 {
109 $this->advanced = true;
110 require_once 'ufbuilder.inc.php';
111 $ufb = new UFB_AdvancedSearch();
112
113 if (!$ufb->isValid()) {
114 return;
115 }
116
117 $this->conds->addChild($ufb->getUFC());
118 }
119
120 public function &get(PlLimit $limit = null, $orders = array())
121 {
122 $orders = array_merge($orders, $this->orders);
123
124 $uf = $this->buildFilter($this->conds, $orders);
125 if (is_null($limit)) {
126 $limit = new PlLimit(20, 0);
127 }
128 $it = $uf->getProfiles($limit);
129 $this->count = $uf->getTotalCount();
130 return $it;
131 }
132 }
133
134 class ArraySet extends UserSet
135 {
136 public function __construct(array $users)
137 {
138 $hruids = User::getBulkHruid($users, array('User', '_silent_user_callback'));
139 if (is_null($hruids) || count($hruids) == 0) {
140 $cond = new PFC_False();
141 } else {
142 $cond = new UFC_Hruid($hruids);
143 }
144 parent::__construct($cond);
145 }
146 }
147
148 class MinificheView extends MultipageView
149 {
150 public function __construct(PlSet &$set, $data, array $params)
151 {
152 require_once 'education.func.inc.php';
153 global $globals;
154 $this->entriesPerPage = $globals->search->per_page;
155 if (@$params['with_score']) {
156 $this->addSort(new PlViewOrder('score', array(
157 new UFO_Score(true),
158 new UFO_ProfileUpdate(true),
159 new UFO_Promo(UserFilter::DISPLAY, true),
160 new UFO_Name(Profile::DN_SORT),
161 ), 'pertinence'));
162 }
163 $this->addSort(new PlViewOrder(
164 'name',
165 array(new UFO_Name(Profile::DN_SORT)),
166 'nom'));
167 $this->addSort(new PlViewOrder('promo', array(
168 new UFO_Promo(UserFilter::DISPLAY, true),
169 new UFO_Name(Profile::DN_SORT),
170 ), 'promotion'));
171 $this->addSort(new PlViewOrder('date_mod', array(
172 new UFO_ProfileUpdate(true),
173 new UFO_Promo(UserFilter::DISPLAY, true),
174 new UFO_Name(Profile::DN_SORT),
175 ), 'dernière modification'));
176 parent::__construct($set, $data, $params);
177 }
178
179 protected function getBoundValue($obj)
180 {
181 if ($obj instanceof Profile) {
182 switch ($this->bound_field) {
183 case 'name':
184 $name = $obj->name('%l');
185 return strtoupper($name[0]);
186 case 'promo':
187 return $obj->promo();
188 default:
189 return null;
190 }
191 }
192 return null;
193 }
194
195 public function bounds()
196 {
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;
210 }
211
212 public function templateName()
213 {
214 return 'include/plview.minifiche.tpl';
215 }
216 }
217
218 class MentorView extends MultipageView
219 {
220 public function __construct(PlSet &$set, $data, array $params)
221 {
222 $this->entriesPerPage = 10;
223 $this->addSort(new PlViewOrder('rand', array(new PFO_Random(S::i('uid'))), 'aléatoirement'));
224 $this->addSort(new PlViewOrder('name', array(new UFO_Name(Profile::DN_SORT)), 'nom'));
225 $this->addSort(new PlViewOrder('promo', array(
226 new UFO_Promo(UserFilter::DISPLAY, true),
227 new UFO_Name(Profile::DN_SORT),
228 ), 'promotion'));
229 $this->addSort(new PlViewOrder('date_mod', array(
230 new UFO_ProfileUpdate(true),
231 new UFO_Promo(UserFilter::DISPLAY, true),
232 new UFO_Name(Profile::DN_SORT),
233 ), 'dernière modification'));
234 parent::__construct($set, $data, $params);
235 }
236
237 protected function getBoundValue($obj)
238 {
239 if ($obj instanceof Profile) {
240 switch ($this->bound_field) {
241 case 'name':
242 $name = $obj->name('%l');
243 return strtoupper($name[0]);
244 case 'promo':
245 return $obj->promo();
246 default:
247 return null;
248 }
249 }
250 return null;
251 }
252
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
270 public function templateName()
271 {
272 return 'include/plview.referent.tpl';
273 }
274 }
275
276 class TrombiView extends MultipageView
277 {
278 public function __construct(PlSet &$set, $data, array $params)
279 {
280 $this->entriesPerPage = 24;
281 if (@$params['with_score']) {
282 $this->addSort(new PlViewOrder('score', array(
283 new UFO_Score(true),
284 new UFO_ProfileUpdate(true),
285 new UFO_Promo(UserFilter::DISPLAY, true),
286 new UFO_Name(Profile::DN_SORT),
287 ), 'pertinence'));
288 }
289 $this->addSort(new PlViewOrder('name', array(new UFO_Name(Profile::DN_SORT)), 'nom'));
290 $this->addSort(new PlViewOrder('promo', array(
291 new UFO_Promo(UserFilter::DISPLAY, true),
292 new UFO_Name(Profile::DN_SORT),
293 ), 'promotion'));
294 parent::__construct($set, $data, $params);
295 }
296
297 protected function getBoundValue($obj)
298 {
299 if ($obj instanceof Profile) {
300 switch ($this->bound_field) {
301 case 'name':
302 $name = $obj->name('%l');
303 return strtoupper($name[0]);
304 case 'promo':
305 return $obj->promo();
306 default:
307 return null;
308 }
309 }
310 return null;
311 }
312
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
330 public function templateName()
331 {
332 return 'include/plview.trombi.tpl';
333 }
334
335 public function apply(PlPage &$page)
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
345 class GadgetView implements PlView
346 {
347 public function __construct(PlSet &$set, $data, array $params)
348 {
349 $this->set =& $set;
350 }
351
352 public function apply(PlPage &$page)
353 {
354 $page->assign_by_ref('set', $this->set->get(new PlLimit(5, 0)));
355 }
356
357 public function args()
358 {
359 return null;
360 }
361 }
362
363 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
364 ?>