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