2 /***************************************************************************
3 * Copyright (C) 2003-2010 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
)
60 $this->quick
= $quick;
63 $this->conds
= new PFC_And();
64 } else if ($cond instanceof PFC_And
) {
67 $this->conds
= new PFC_And($cond);
77 private function getQuick()
80 Env
::kill('with_soundex');
83 require_once 'ufbuilder.inc.php';
84 $ufb = new UFB_QuickSearch();
86 if (!$ufb->isValid()) {
90 $ufc = $ufb->getUFC();
91 $this->conds
->addChild($ufc);
93 $orders = $ufb->getOrders();
94 $orders[] = new UFO_Promo(UserFilter
::DISPLAY
, true
);
95 $orders[] = new UFO_Name(Profile
::DN_SORT
);
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())
104 parent
::__construct($this->conds
, $orders);
107 private function getAdvanced()
109 $this->advanced
= true
;
110 require_once 'ufbuilder.inc.php';
111 $ufb = new UFB_AdvancedSearch();
113 if (!$ufb->isValid()) {
117 $this->conds
->addChild($ufb->getUFC());
120 public function &get(PlLimit
$limit = null
, $orders = array())
122 $orders = array_merge($orders, $this->orders
);
124 $uf = $this->buildFilter($this->conds
, $orders);
125 if (is_null($limit)) {
126 $limit = new PlLimit(20, 0);
128 $it = $uf->getProfiles($limit);
129 $this->count
= $uf->getTotalCount();
134 class ArraySet
extends UserSet
136 public function __construct(array $users)
138 $hruids = User
::getBulkHruid($users, array('User', '_silent_user_callback'));
139 if (is_null($hruids) ||
count($hruids) == 0) {
140 $cond = new PFC_False();
142 $cond = new UFC_Hruid($hruids);
144 parent
::__construct($cond);
148 class MinificheView
extends MultipageView
150 public function __construct(PlSet
&$set, $data, array $params)
152 require_once 'education.func.inc.php';
154 $this->entriesPerPage
= $globals->search
->per_page
;
155 if (@$params['with_score']) {
156 $this->addSort(new PlViewOrder('score', array(
158 new UFO_ProfileUpdate(true
),
159 new UFO_Promo(UserFilter
::DISPLAY
, true
),
160 new UFO_Name(Profile
::DN_SORT
),
163 $this->addSort(new PlViewOrder(
165 array(new UFO_Name(Profile
::DN_SORT
)),
167 $this->addSort(new PlViewOrder('promo', array(
168 new UFO_Promo(UserFilter
::DISPLAY
, true
),
169 new UFO_Name(Profile
::DN_SORT
),
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);
179 protected function getBoundValue($obj)
181 if ($obj instanceof Profile
) {
182 switch ($this->bound_field
) {
184 $name = $obj->name('%l');
185 return strtoupper($name[0]);
187 return $obj->promo();
195 public function bounds()
197 $order = Env
::v('order', $this->defaultkey
);
199 if (($order == "name") ||
($order == "-name")) {
200 $this->bound_field
= "name";
202 } elseif (($order == "promo") ||
($order == "-promo")) {
203 $this->bound_field
= "promo";
206 if ($order{0} == '-') {
207 $show_bounds = -$show_bounds;
212 public function templateName()
214 return 'include/plview.minifiche.tpl';
218 class MentorView
extends MultipageView
220 public function __construct(PlSet
&$set, $data, array $params)
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
),
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);
237 protected function getBoundValue($obj)
239 if ($obj instanceof Profile
) {
240 switch ($this->bound_field
) {
242 $name = $obj->name('%l');
243 return strtoupper($name[0]);
245 return $obj->promo();
253 public function bounds()
255 $order = Env
::v('order', $this->defaultkey
);
257 if (($order == "name") ||
($order == "-name")) {
258 $this->bound_field
= "nom";
260 } elseif (($order == "promo") ||
($order == "-promo")) {
261 $this->bound_field
= "promo";
264 if ($order{0} == '-') {
265 $show_bounds = -$show_bounds;
270 public function templateName()
272 return 'include/plview.referent.tpl';
276 class TrombiView
extends MultipageView
278 public function __construct(PlSet
&$set, $data, array $params)
280 $this->entriesPerPage
= 24;
281 if (@$params['with_score']) {
282 $this->addSort(new PlViewOrder('score', array(
284 new UFO_ProfileUpdate(true
),
285 new UFO_Promo(UserFilter
::DISPLAY
, true
),
286 new UFO_Name(Profile
::DN_SORT
),
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
),
294 parent
::__construct($set, $data, $params);
297 protected function getBoundValue($obj)
299 if ($obj instanceof Profile
) {
300 switch ($this->bound_field
) {
302 $name = $obj->name('%l');
303 return strtoupper($name[0]);
305 return $obj->promo();
313 public function bounds()
315 $order = Env
::v('order', $this->defaultkey
);
317 if (($order == "name") ||
($order == "-name")) {
318 $this->bound_field
= "nom";
320 } elseif (($order == "promo") ||
($order == "-promo")) {
321 $this->bound_field
= "promo";
324 if ($order{0} == '-') {
325 $show_bounds = -$show_bounds;
330 public function templateName()
332 return 'include/plview.trombi.tpl';
335 public function apply(PlPage
&$page)
337 if (!empty($GLOBALS['IS_XNET_SITE'])) {
339 $page->assign('mainsiteurl', 'https://' . $globals->core
->secure_domain
. '/');
341 return parent
::apply($page);
345 class GadgetView
implements PlView
347 public function __construct(PlSet
&$set, $data, array $params)
352 public function apply(PlPage
&$page)
354 $page->assign_by_ref('set', $this->set
->get(new PlLimit(5, 0)));
357 public function args()
363 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: