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
;
53 private $valid = true
;
55 public function __construct($quick = false
, PlFilterCondition
$cond = null
)
61 $this->quick
= $quick;
64 $conds = new PFC_And();
65 } else if ($cond instanceof PFC_And
) {
68 $conds = new PFC_And($cond);
72 $this->getQuick($conds);
74 $this->getAdvanced($conds);
78 public function isValid()
83 /** Sets up the conditions for a Quick Search
84 * @param $conds Additional conds (as a PFC_And)
86 private function getQuick($conds)
89 Env
::kill('with_soundex');
92 require_once 'ufbuilder.inc.php';
93 $ufb = new UFB_QuickSearch();
95 if (!$ufb->isValid()) {
100 $ufc = $ufb->getUFC();
101 $conds->addChild($ufc);
103 $orders = $ufb->getOrders();
105 if (S
::logged() && Env
::has('nonins')) {
106 $conds = new PFC_And($conds,
107 new PFC_Not(new UFC_Dead()),
108 new PFC_Not(new UFC_Registered())
112 parent
::__construct($conds, $orders);
115 /** Sets up the conditions for an Advanced Search
116 * @param $conds Additional conds (as a PFC_And)
118 private function getAdvanced($conds)
120 $this->advanced
= true
;
121 require_once 'ufbuilder.inc.php';
122 $ufb = new UFB_AdvancedSearch();
124 if (!$ufb->isValid()) {
125 $this->valid
= false
;
129 $ufc = $ufb->getUFC();
130 $conds->addChild($ufc);
132 $orders = $ufb->getOrders();
134 parent
::__construct($conds, $orders);
137 /** Add a "rechercher=Chercher" field to the query to simulate the POST
140 public function args()
142 $args = parent
::args();
143 if (!isset($args['rechercher'])) {
144 $args['rechercher'] = 'Chercher';
149 protected function &getFilterResults(PlFilter
&$pf, PlLimit
$limit)
151 $profiles = $pf->getProfiles($limit, Profile
::FETCH_MINIFICHES
);
156 /** Simple set based on an array of User objects
158 class ArraySet
extends ProfileSet
160 public function __construct(array $users)
162 $hruids = User
::getBulkHruid($users, array('User', '_silent_user_callback'));
163 if (is_null($hruids) ||
count($hruids) == 0) {
164 $cond = new PFC_False();
166 $cond = new UFC_Hruid($hruids);
168 parent
::__construct($cond);
172 /** A multipage view for profiles
173 * Allows the display of bounds when sorting by name or promo.
175 abstract class ProfileView
extends MultipageView
177 protected function getBoundValue($obj)
179 if ($obj instanceof Profile
) {
180 switch ($this->bound_field
) {
182 $name = $obj->name('%l');
183 return strtoupper($name);
185 return $obj->promo();
193 public function bounds()
195 $order = Env
::v('order', $this->defaultkey
);
197 if (($order == "name") ||
($order == "-name")) {
198 $this->bound_field
= "name";
200 } elseif (($order == "promo") ||
($order == "-promo")) {
201 $this->bound_field
= "promo";
204 if ($order{0} == '-') {
205 $show_bounds = -$show_bounds;
211 /** An extended multipage view for profiles, as minifiches.
213 * - score (for a search query)
216 * - latest modification
218 * Paramaters for this view are:
219 * - with_score: whether to allow ordering by score (set only for a quick search)
220 * - starts_with: show only names beginning with the given letter
222 class MinificheView
extends ProfileView
224 public function __construct(PlSet
&$set, array $params)
227 $this->entriesPerPage
= $globals->search
->per_page
;
228 if (@$params['with_score']) {
229 $this->addSort(new PlViewOrder('score', array(
231 new UFO_ProfileUpdate(true
),
232 new UFO_Promo(UserFilter
::DISPLAY
, true
),
233 new UFO_Name(Profile
::DN_SORT
),
236 $this->addSort(new PlViewOrder(
238 array(new UFO_Name(Profile
::DN_SORT
)),
240 $this->addSort(new PlViewOrder('promo', array(
241 new UFO_Promo(UserFilter
::DISPLAY
, true
),
242 new UFO_Name(Profile
::DN_SORT
),
244 $this->addSort(new PlViewOrder('date_mod', array(
245 new UFO_ProfileUpdate(true
),
246 new UFO_Promo(UserFilter
::DISPLAY
, true
),
247 new UFO_Name(Profile
::DN_SORT
),
248 ), 'dernière modification'));
249 parent
::__construct($set, $params);
252 public function apply(PlPage
&$page)
254 if (array_key_exists('starts_with', $this->params
)
255 && $this->params
['starts_with'] != ""
256 && $this->params
['starts_with'] != null
) {
259 new UFC_Name(Profile
::LASTNAME
,
260 $this->params
['starts_with'], UFC_Name
::PREFIX
)
263 return parent
::apply($page);
266 public function templateName()
268 return 'include/plview.minifiche.tpl';
272 class MentorView
extends ProfileView
274 public function __construct(PlSet
&$set, array $params)
276 $this->entriesPerPage
= 10;
277 $this->addSort(new PlViewOrder('rand', array(new PFO_Random(S
::i('uid'))), 'aléatoirement'));
278 $this->addSort(new PlViewOrder('name', array(new UFO_Name(Profile
::DN_SORT
)), 'nom'));
279 $this->addSort(new PlViewOrder('promo', array(
280 new UFO_Promo(UserFilter
::DISPLAY
, true
),
281 new UFO_Name(Profile
::DN_SORT
),
283 $this->addSort(new PlViewOrder('date_mod', array(
284 new UFO_ProfileUpdate(true
),
285 new UFO_Promo(UserFilter
::DISPLAY
, true
),
286 new UFO_Name(Profile
::DN_SORT
),
287 ), 'dernière modification'));
288 parent
::__construct($set, $params);
291 public function templateName()
293 return 'include/plview.referent.tpl';
297 class TrombiView
extends ProfileView
299 public function __construct(PlSet
&$set, array $params)
301 $this->entriesPerPage
= 24;
302 $this->defaultkey
= 'name';
303 if (@$params['with_score']) {
304 $this->addSort(new PlViewOrder('score', array(
306 new UFO_ProfileUpdate(true
),
307 new UFO_Promo(UserFilter
::DISPLAY
, true
),
308 new UFO_Name(Profile
::DN_SORT
),
311 $set->addCond(new UFC_Photo());
312 $this->addSort(new PlViewOrder('name', array(new UFO_Name(Profile
::DN_SORT
)), 'nom'));
313 $this->addSort(new PlViewOrder('promo', array(
314 new UFO_Promo(UserFilter
::DISPLAY
, true
),
315 new UFO_Name(Profile
::DN_SORT
),
317 parent
::__construct($set, $params);
320 public function templateName()
322 return 'include/plview.trombi.tpl';
325 public function apply(PlPage
&$page)
327 if (!empty($GLOBALS['IS_XNET_SITE'])) {
329 $page->assign('mainsiteurl', 'https://' . $globals->core
->secure_domain
. '/');
331 return parent
::apply($page);
335 class GadgetView
implements PlView
337 public function __construct(PlSet
&$set, array $params)
342 public function apply(PlPage
&$page)
344 $page->assign_by_ref('set', $this->set
->get(new PlLimit(5, 0)));
347 public function args()
353 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: