e4631a201351acaaae0c905954421295b7a7db52
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
, PlFilterCondition
$cond = null
)
60 $this->quick
= $quick;
63 $conds = new PFC_And();
64 } else if ($cond instanceof PFC_And
) {
67 $conds = new PFC_And($cond);
71 $this->getQuick($conds);
73 $this->getAdvanced($conds);
77 /** Sets up the conditions for a Quick Search
78 * @param $conds Additional conds (as a PFC_And)
80 private function getQuick($conds)
83 Env
::kill('with_soundex');
86 require_once 'ufbuilder.inc.php';
87 $ufb = new UFB_QuickSearch();
89 if (!$ufb->isValid()) {
93 $ufc = $ufb->getUFC();
94 $conds->addChild($ufc);
96 $orders = $ufb->getOrders();
98 if (S
::logged() && Env
::has('nonins')) {
99 $conds = new PFC_And($conds,
100 new PFC_Not(new UFC_Dead()),
101 new PFC_Not(new UFC_Registered())
105 parent
::__construct($conds, $orders);
108 /** Sets up the conditions for an Advanced Search
109 * @param $conds Additional conds (as a PFC_And)
111 private function getAdvanced($conds)
113 $this->advanced
= true
;
114 require_once 'ufbuilder.inc.php';
115 $ufb = new UFB_AdvancedSearch();
117 if (!$ufb->isValid()) {
121 $ufc = $ufb->getUFC();
122 $conds->addChild($ufc);
124 $orders = $ufb->getOrders();
126 parent
::__construct($conds, $orders);
129 protected function &getFilterResults(PlFilter
&$pf, PlLimit
$limit)
131 $profiles = $pf->getProfiles($limit, Profile
::FETCH_MINIFICHES
);
136 /** Simple set based on an array of User objects
138 class ArraySet
extends ProfileSet
140 public function __construct(array $users)
142 $hruids = User
::getBulkHruid($users, array('User', '_silent_user_callback'));
143 if (is_null($hruids) ||
count($hruids) == 0) {
144 $cond = new PFC_False();
146 $cond = new UFC_Hruid($hruids);
148 parent
::__construct($cond);
152 /** A multipage view for profiles
153 * Allows the display of bounds when sorting by name or promo.
155 abstract class ProfileView
extends MultipageView
157 protected function getBoundValue($obj)
159 if ($obj instanceof Profile
) {
160 switch ($this->bound_field
) {
162 $name = $obj->name('%l');
163 return strtoupper($name);
165 return $obj->promo();
173 public function bounds()
175 $order = Env
::v('order', $this->defaultkey
);
177 if (($order == "name") ||
($order == "-name")) {
178 $this->bound_field
= "name";
180 } elseif (($order == "promo") ||
($order == "-promo")) {
181 $this->bound_field
= "promo";
184 if ($order{0} == '-') {
185 $show_bounds = -$show_bounds;
191 /** An extended multipage view for profiles, as minifiches.
193 * - score (for a search query)
196 * - latest modification
198 * Paramaters for this view are:
199 * - with_score: whether to allow ordering by score (set only for a quick search)
200 * - starts_with: show only names beginning with the given letter
202 class MinificheView
extends ProfileView
204 public function __construct(PlSet
&$set, array $params)
207 $this->entriesPerPage
= $globals->search
->per_page
;
208 if (@$params['with_score']) {
209 $this->addSort(new PlViewOrder('score', array(
211 new UFO_ProfileUpdate(true
),
212 new UFO_Promo(UserFilter
::DISPLAY
, true
),
213 new UFO_Name(Profile
::DN_SORT
),
216 $this->addSort(new PlViewOrder(
218 array(new UFO_Name(Profile
::DN_SORT
)),
220 $this->addSort(new PlViewOrder('promo', array(
221 new UFO_Promo(UserFilter
::DISPLAY
, true
),
222 new UFO_Name(Profile
::DN_SORT
),
224 $this->addSort(new PlViewOrder('date_mod', array(
225 new UFO_ProfileUpdate(true
),
226 new UFO_Promo(UserFilter
::DISPLAY
, true
),
227 new UFO_Name(Profile
::DN_SORT
),
228 ), 'dernière modification'));
229 parent
::__construct($set, $params);
232 public function apply(PlPage
&$page)
234 if (array_key_exists('starts_with', $this->params
)
235 && $this->params
['starts_with'] != ""
236 && $this->params
['starts_with'] != null
) {
239 new UFC_Name(Profile
::LASTNAME
,
240 $this->params
['starts_with'], UFC_Name
::PREFIX
)
243 return parent
::apply($page);
246 public function templateName()
248 return 'include/plview.minifiche.tpl';
252 class MentorView
extends ProfileView
254 public function __construct(PlSet
&$set, array $params)
256 $this->entriesPerPage
= 10;
257 $this->addSort(new PlViewOrder('rand', array(new PFO_Random(S
::i('uid'))), 'aléatoirement'));
258 $this->addSort(new PlViewOrder('name', array(new UFO_Name(Profile
::DN_SORT
)), 'nom'));
259 $this->addSort(new PlViewOrder('promo', array(
260 new UFO_Promo(UserFilter
::DISPLAY
, true
),
261 new UFO_Name(Profile
::DN_SORT
),
263 $this->addSort(new PlViewOrder('date_mod', array(
264 new UFO_ProfileUpdate(true
),
265 new UFO_Promo(UserFilter
::DISPLAY
, true
),
266 new UFO_Name(Profile
::DN_SORT
),
267 ), 'dernière modification'));
268 parent
::__construct($set, $params);
271 public function templateName()
273 return 'include/plview.referent.tpl';
277 class TrombiView
extends ProfileView
279 public function __construct(PlSet
&$set, array $params)
281 $this->entriesPerPage
= 24;
282 $this->defaultkey
= 'name';
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(Profile
::DN_SORT
),
291 $set->addCond(new UFC_Photo());
292 $this->addSort(new PlViewOrder('name', array(new UFO_Name(Profile
::DN_SORT
)), 'nom'));
293 $this->addSort(new PlViewOrder('promo', array(
294 new UFO_Promo(UserFilter
::DISPLAY
, true
),
295 new UFO_Name(Profile
::DN_SORT
),
297 parent
::__construct($set, $params);
300 public function templateName()
302 return 'include/plview.trombi.tpl';
305 public function apply(PlPage
&$page)
307 if (!empty($GLOBALS['IS_XNET_SITE'])) {
309 $page->assign('mainsiteurl', 'https://' . $globals->core
->secure_domain
. '/');
311 return parent
::apply($page);
315 class GadgetView
implements PlView
317 public function __construct(PlSet
&$set, array $params)
322 public function apply(PlPage
&$page)
324 $page->assign_by_ref('set', $this->set
->get(new PlLimit(5, 0)));
327 public function args()
333 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: