2 /***************************************************************************
3 * Copyright (C) 2003-2009 Polytechnique.org *
4 * http://opensource.polytechnique.org/ *
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. *
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. *
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 *
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
20 ***************************************************************************/
22 class UserSet
extends PlSet
24 public function __construct(PlFilterCondition
&$cond, $orders = null
)
26 parent
::__construct($cond, $orders);
29 protected function buildFilter(PlFilterCondition
&$cond, $orders)
31 return new UserFilter($cond, $orders);
35 class ProfileSet
extends PlSet
37 public function __construct(PlFilterCondition
&$cond, $orders = null
)
39 parent
::__construct($cond, $orders);
42 protected function buildFilter(PlFilterCondition
&$cond, $orders)
44 return new ProfileFilter($cond, $orders);
48 class SearchSet
extends ProfileSet
50 public $advanced = false
;
51 private $score = null
;
52 private $quick = false
;
54 public function __construct($quick = false
, $no_search = false
, PlFilterCondition
$cond = null
)
56 Platal
::load('search', 'search.inc.php');
62 $this->quick
= $quick;
65 $this->conds
= new PFC_And();
66 } else if ($cond instanceof PFC_And
) {
69 $this->conds
= new PFC_And($cond);
79 private function getQuick()
82 Env
::kill('with_soundex');
85 require_once 'ufbuilder.inc.php';
86 $ufb = new UFB_QuickSearch();
88 if (!$ufb->isValid()) {
92 $ufc = $ufb->getUFC();
93 $this->conds
->addChild($ufc);
95 $orders = $ufb->getOrders();
96 $orders[] = new UFO_Promo(UserFilter
::DISPLAY
, true
);
97 $orders[] = new UFO_Promo(UserFilter
::DN_SORT
);
99 if (S
::logged() && Env
::has('nonins')) {
100 $this->conds
= new PFC_And($this->conds
,
101 new UFC_Not(new UFC_Dead()),
106 parent
::__construct($this->conds
, $orders);
109 private function getAdvanced()
111 $this->advanced
= true
;
112 require_once 'ufbuilder.inc.php';
113 $ufb = new UFB_AdvancedSearch();
115 if (!$ufb->isValid()) {
119 $this->conds
->addChild($ufb->getUFC());
122 public function &get(PlLimit
$limit = null
, $orders = array())
124 $orders = array_merge($orders, $this->orders
);
126 $uf = $this->buildFilter($this->conds
, $orders);
127 if (is_null($limit)) {
128 $limit = new PlLimit(20, 0);
130 $it = $uf->getProfiles($limit);
131 $this->count
= $uf->getTotalCount();
136 class ArraySet
extends UserSet
138 public function __construct(array $users)
140 $hruids = User
::getBulkHruid($users, array('User', '_silent_user_callback'));
141 if (is_null($hruids) ||
count($hruids) == 0) {
142 $cond = new PFC_False();
144 $cond = new UFC_Hruid($hruids);
146 parent
::__construct($cond);
150 class MinificheView
extends MultipageView
152 public function __construct(PlSet
&$set, $data, array $params)
154 require_once 'education.func.inc.php';
156 $this->entriesPerPage
= $globals->search
->per_page
;
157 if (@$params['with_score']) {
158 $this->addSort(new PlViewOrder('score', array(
160 new UFO_ProfileUpdate(true
),
161 new UFO_Promo(UserFilter
::DISPLAY
, true
),
162 new UFO_Name(UserFilter
::DN_SORT
),
165 $this->addSort(new PlViewOrder(
167 array(new UFO_Name(UserFilter
::DN_SORT
)),
169 $this->addSort(new PlViewOrder('promo', array(
170 new UFO_Promo(UserFilter
::DISPLAY
, true
),
171 new UFO_Name(UserFilter
::DN_SORT
),
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'));
178 parent
::__construct($set, $data, $params);
181 protected function getBoundValue($obj)
183 if ($obj instanceof Profile
) {
184 switch ($this->bound_field
) {
186 $name = $obj->name('%l');
187 return strtoupper($name[0]);
189 return $obj->promo();
197 public function bounds()
199 $order = Env
::v('order', $this->defaultkey
);
201 if (($order == "name") ||
($order == "-name")) {
202 $this->bound_field
= "name";
204 } elseif (($order == "promo") ||
($order == "-promo")) {
205 $this->bound_field
= "promo";
208 if ($order{0} == '-') {
209 $show_bounds = -$show_bounds;
214 public function templateName()
216 return 'include/plview.minifiche.tpl';
220 class MentorView
extends MultipageView
222 public function __construct(PlSet
&$set, $data, array $params)
224 $this->entriesPerPage
= 10;
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
),
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'));
236 parent
::__construct($set, $data, $params);
239 protected function getBoundValue($obj)
241 if ($obj instanceof Profile
) {
242 switch ($this->bound_field
) {
244 $name = $obj->name('%l');
245 return strtoupper($name[0]);
247 return $obj->promo();
255 public function bounds()
257 $order = Env
::v('order', $this->defaultkey
);
259 if (($order == "name") ||
($order == "-name")) {
260 $this->bound_field
= "nom";
262 } elseif (($order == "promo") ||
($order == "-promo")) {
263 $this->bound_field
= "promo";
266 if ($order{0} == '-') {
267 $show_bounds = -$show_bounds;
272 public function templateName()
274 return 'include/plview.referent.tpl';
278 class TrombiView
extends MultipageView
280 public function __construct(PlSet
&$set, $data, array $params)
282 $this->entriesPerPage
= 24;
283 if (@$params['with_score']) {
284 $this->addSort(new PlViewOrder('score', array(
286 new UFO_ProfileUpdate(true
),
287 new UFO_Promo(UserFilter
::DISPLAY
, true
),
288 new UFO_Name(UserFilter
::DN_SORT
),
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
),
296 parent
::__construct($set, $data, $params);
299 protected function getBoundValue($obj)
301 if ($obj instanceof Profile
) {
302 switch ($this->bound_field
) {
304 $name = $obj->name('%l');
305 return strtoupper($name[0]);
307 return $obj->promo();
315 public function bounds()
317 $order = Env
::v('order', $this->defaultkey
);
319 if (($order == "name") ||
($order == "-name")) {
320 $this->bound_field
= "nom";
322 } elseif (($order == "promo") ||
($order == "-promo")) {
323 $this->bound_field
= "promo";
326 if ($order{0} == '-') {
327 $show_bounds = -$show_bounds;
332 public function templateName()
334 return 'include/plview.trombi.tpl';
337 public function apply(PlPage
&$page)
339 if (!empty($GLOBALS['IS_XNET_SITE'])) {
341 $page->assign('mainsiteurl', 'https://' . $globals->core
->secure_domain
. '/');
343 return parent
::apply($page);
347 class GadgetView
implements PlView
349 public function __construct(PlSet
&$set, $data, array $params)
354 public function apply(PlPage
&$page)
356 $page->assign_by_ref('set', $this->set
->get(new PlLimit(5, 0)));
359 public function args()
365 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: