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 /** Add a "rechercher=Chercher" field to the query to simulate the POST
132 public function args()
134 $args = parent
::args();
135 if (!isset($args['rechercher'])) {
136 $args['rechercher'] = 'Chercher';
141 protected function &getFilterResults(PlFilter
&$pf, PlLimit
$limit)
143 $profiles = $pf->getProfiles($limit, Profile
::FETCH_MINIFICHES
);
148 /** Simple set based on an array of User objects
150 class ArraySet
extends ProfileSet
152 public function __construct(array $users)
154 $hruids = User
::getBulkHruid($users, array('User', '_silent_user_callback'));
155 if (is_null($hruids) ||
count($hruids) == 0) {
156 $cond = new PFC_False();
158 $cond = new UFC_Hruid($hruids);
160 parent
::__construct($cond);
164 /** A multipage view for profiles
165 * Allows the display of bounds when sorting by name or promo.
167 abstract class ProfileView
extends MultipageView
169 protected function getBoundValue($obj)
171 if ($obj instanceof Profile
) {
172 switch ($this->bound_field
) {
174 $name = $obj->name('%l');
175 return strtoupper($name);
177 return $obj->promo();
185 public function bounds()
187 $order = Env
::v('order', $this->defaultkey
);
189 if (($order == "name") ||
($order == "-name")) {
190 $this->bound_field
= "name";
192 } elseif (($order == "promo") ||
($order == "-promo")) {
193 $this->bound_field
= "promo";
196 if ($order{0} == '-') {
197 $show_bounds = -$show_bounds;
203 /** An extended multipage view for profiles, as minifiches.
205 * - score (for a search query)
208 * - latest modification
210 * Paramaters for this view are:
211 * - with_score: whether to allow ordering by score (set only for a quick search)
212 * - starts_with: show only names beginning with the given letter
214 class MinificheView
extends ProfileView
216 public function __construct(PlSet
&$set, array $params)
219 $this->entriesPerPage
= $globals->search
->per_page
;
220 if (@$params['with_score']) {
221 $this->addSort(new PlViewOrder('score', array(
223 new UFO_ProfileUpdate(true
),
224 new UFO_Promo(UserFilter
::DISPLAY
, true
),
225 new UFO_Name(Profile
::DN_SORT
),
228 $this->addSort(new PlViewOrder(
230 array(new UFO_Name(Profile
::DN_SORT
)),
232 $this->addSort(new PlViewOrder('promo', array(
233 new UFO_Promo(UserFilter
::DISPLAY
, true
),
234 new UFO_Name(Profile
::DN_SORT
),
236 $this->addSort(new PlViewOrder('date_mod', array(
237 new UFO_ProfileUpdate(true
),
238 new UFO_Promo(UserFilter
::DISPLAY
, true
),
239 new UFO_Name(Profile
::DN_SORT
),
240 ), 'dernière modification'));
241 parent
::__construct($set, $params);
244 public function apply(PlPage
&$page)
246 if (array_key_exists('starts_with', $this->params
)
247 && $this->params
['starts_with'] != ""
248 && $this->params
['starts_with'] != null
) {
251 new UFC_Name(Profile
::LASTNAME
,
252 $this->params
['starts_with'], UFC_Name
::PREFIX
)
255 return parent
::apply($page);
258 public function templateName()
260 return 'include/plview.minifiche.tpl';
264 class MentorView
extends ProfileView
266 public function __construct(PlSet
&$set, array $params)
268 $this->entriesPerPage
= 10;
269 $this->addSort(new PlViewOrder('rand', array(new PFO_Random(S
::i('uid'))), 'aléatoirement'));
270 $this->addSort(new PlViewOrder('name', array(new UFO_Name(Profile
::DN_SORT
)), 'nom'));
271 $this->addSort(new PlViewOrder('promo', array(
272 new UFO_Promo(UserFilter
::DISPLAY
, true
),
273 new UFO_Name(Profile
::DN_SORT
),
275 $this->addSort(new PlViewOrder('date_mod', array(
276 new UFO_ProfileUpdate(true
),
277 new UFO_Promo(UserFilter
::DISPLAY
, true
),
278 new UFO_Name(Profile
::DN_SORT
),
279 ), 'dernière modification'));
280 parent
::__construct($set, $params);
283 public function templateName()
285 return 'include/plview.referent.tpl';
289 class TrombiView
extends ProfileView
291 public function __construct(PlSet
&$set, array $params)
293 $this->entriesPerPage
= 24;
294 $this->defaultkey
= 'name';
295 if (@$params['with_score']) {
296 $this->addSort(new PlViewOrder('score', array(
298 new UFO_ProfileUpdate(true
),
299 new UFO_Promo(UserFilter
::DISPLAY
, true
),
300 new UFO_Name(Profile
::DN_SORT
),
303 $set->addCond(new UFC_Photo());
304 $this->addSort(new PlViewOrder('name', array(new UFO_Name(Profile
::DN_SORT
)), 'nom'));
305 $this->addSort(new PlViewOrder('promo', array(
306 new UFO_Promo(UserFilter
::DISPLAY
, true
),
307 new UFO_Name(Profile
::DN_SORT
),
309 parent
::__construct($set, $params);
312 public function templateName()
314 return 'include/plview.trombi.tpl';
317 public function apply(PlPage
&$page)
319 if (!empty($GLOBALS['IS_XNET_SITE'])) {
321 $page->assign('mainsiteurl', 'https://' . $globals->core
->secure_domain
. '/');
323 return parent
::apply($page);
327 class GadgetView
implements PlView
329 public function __construct(PlSet
&$set, array $params)
334 public function apply(PlPage
&$page)
336 $page->assign_by_ref('set', $this->set
->get(new PlLimit(5, 0)));
339 public function args()
345 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: