be7564db8ff4b53f52db6f639a067011fa8cb9a2
2 /***************************************************************************
3 * Copyright (C) 2003-2011 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 require_once "ufbuilder.inc.php";
50 class SearchSet
extends ProfileSet
52 protected $score = null
;
53 protected $valid = true
;
55 public function __construct(UserFilterBuilder
$ufb, PlFilterCondition
$cond = null
)
58 $conds = new PFC_And();
59 } else if ($cond instanceof PFC_And
) {
62 $conds = new PFC_And($cond);
65 if (!$ufb->isValid()) {
70 $ufc = $ufb->getUFC();
71 $conds->addChild($ufc);
73 $orders = $ufb->getOrders();
75 parent
::__construct($conds, $orders);
78 public function isValid()
83 /** Add a "rechercher=Chercher" field to the query to simulate the POST
86 public function args()
88 $args = parent
::args();
89 if (!isset($args['rechercher'])) {
90 $args['rechercher'] = 'Chercher';
95 protected function &getFilterResults(PlFilter
$pf, PlLimit
$limit)
97 $profiles = $pf->getProfiles($limit, Profile
::FETCH_MINIFICHES
);
102 // Specialized SearchSet for quick search.
103 class QuickSearchSet
extends SearchSet
105 public function __construct(PlFilterCondition
$cond = null
)
108 Env
::kill('with_soundex');
111 parent
::__construct(new UFB_QuickSearch(), $cond);
115 // Specialized SearchSet for advanced search.
116 class AdvancedSearchSet
extends SearchSet
118 public function __construct($xorg_admin_fields, $ax_admin_fields,
119 PlFilterCondition
$cond = null
)
121 parent
::__construct(new UFB_AdvancedSearch($xorg_admin_fields, $ax_admin_fields),
126 /** Simple set based on an array of User objects
128 class ArraySet
extends ProfileSet
130 public function __construct(array $users)
132 $hruids = User
::getBulkHruid($users, array('User', '_silent_user_callback'));
133 if (is_null($hruids) ||
count($hruids) == 0) {
134 $cond = new PFC_False();
136 $cond = new UFC_Hruid($hruids);
138 parent
::__construct($cond);
142 /** A multipage view for profiles
143 * Allows the display of bounds when sorting by name or promo.
145 abstract class ProfileView
extends MultipageView
147 protected function getBoundValue($obj)
149 if ($obj instanceof Profile
) {
150 switch ($this->bound_field
) {
152 $name = $obj->name('%l');
153 return strtoupper($name);
155 return $obj->promo();
163 public function bounds()
165 $order = Env
::v('order', $this->defaultkey
);
167 if (($order == "name") ||
($order == "-name")) {
168 $this->bound_field
= "name";
170 } elseif (($order == "promo") ||
($order == "-promo")) {
171 $this->bound_field
= "promo";
174 if ($order{0} == '-') {
175 $show_bounds = -$show_bounds;
181 /** An extended multipage view for profiles, as minifiches.
183 * - score (for a search query)
186 * - latest modification
188 * Paramaters for this view are:
189 * - with_score: whether to allow ordering by score (set only for a quick search)
190 * - starts_with: show only names beginning with the given letter
192 class MinificheView
extends ProfileView
194 public function __construct(PlSet
$set, array $params)
197 $this->entriesPerPage
= $globals->search
->per_page
;
198 if (@$params['with_score']) {
199 $this->addSort(new PlViewOrder('score', array(
201 new UFO_ProfileUpdate(true
),
202 new UFO_Promo(UserFilter
::DISPLAY
, true
),
203 new UFO_Name(Profile
::DN_SORT
),
206 $this->addSort(new PlViewOrder(
208 array(new UFO_Name(Profile
::DN_SORT
)),
210 $this->addSort(new PlViewOrder('promo', array(
211 new UFO_Promo(UserFilter
::DISPLAY
, true
),
212 new UFO_Name(Profile
::DN_SORT
),
214 $this->addSort(new PlViewOrder('date_mod', array(
215 new UFO_ProfileUpdate(true
),
216 new UFO_Promo(UserFilter
::DISPLAY
, true
),
217 new UFO_Name(Profile
::DN_SORT
),
218 ), 'dernière modification'));
219 parent
::__construct($set, $params);
222 public function apply(PlPage
$page)
224 if (array_key_exists('starts_with', $this->params
)
225 && $this->params
['starts_with'] != ""
226 && $this->params
['starts_with'] != null
) {
229 new UFC_Name(Profile
::LASTNAME
,
230 $this->params
['starts_with'], UFC_Name
::PREFIX
)
233 return parent
::apply($page);
236 public function templateName()
238 return 'include/plview.minifiche.tpl';
242 class MentorView
extends ProfileView
244 public function __construct(PlSet
$set, array $params)
246 $this->entriesPerPage
= 10;
247 $this->addSort(new PlViewOrder('rand', array(new PFO_Random(S
::i('uid'))), 'aléatoirement'));
248 $this->addSort(new PlViewOrder('name', array(new UFO_Name(Profile
::DN_SORT
)), 'nom'));
249 $this->addSort(new PlViewOrder('promo', array(
250 new UFO_Promo(UserFilter
::DISPLAY
, true
),
251 new UFO_Name(Profile
::DN_SORT
),
253 $this->addSort(new PlViewOrder('date_mod', array(
254 new UFO_ProfileUpdate(true
),
255 new UFO_Promo(UserFilter
::DISPLAY
, true
),
256 new UFO_Name(Profile
::DN_SORT
),
257 ), 'dernière modification'));
258 parent
::__construct($set, $params);
261 public function templateName()
263 return 'include/plview.referent.tpl';
267 class TrombiView
extends ProfileView
269 public function __construct(PlSet
$set, array $params)
271 $this->entriesPerPage
= 24;
272 $this->defaultkey
= 'name';
273 if (@$params['with_score']) {
274 $this->addSort(new PlViewOrder('score', array(
276 new UFO_ProfileUpdate(true
),
277 new UFO_Promo(UserFilter
::DISPLAY
, true
),
278 new UFO_Name(Profile
::DN_SORT
),
281 $set->addCond(new UFC_Photo());
282 $this->addSort(new PlViewOrder('name', array(new UFO_Name(Profile
::DN_SORT
)), 'nom'));
283 $this->addSort(new PlViewOrder('promo', array(
284 new UFO_Promo(UserFilter
::DISPLAY
, true
),
285 new UFO_Name(Profile
::DN_SORT
),
287 parent
::__construct($set, $params);
290 public function templateName()
292 return 'include/plview.trombi.tpl';
295 public function apply(PlPage
$page)
297 if (!empty($GLOBALS['IS_XNET_SITE'])) {
299 $page->assign('mainsiteurl', 'https://' . $globals->core
->secure_domain
. '/');
301 return parent
::apply($page);
305 /** A multipage view for users
306 * Allows the display of bounds when sorting by name or promo.
308 abstract class UserView
extends MultipageView
310 protected function getBoundValue($user)
312 if ($user instanceof User
) {
313 switch ($this->bound_field
) {
315 $name = $user->lastName();
316 return strtoupper($name);
318 if ($user->hasProfile()) {
319 return $user->profile()->promo();
330 public function bounds()
332 $order = Env
::v('order', $this->defaultkey
);
334 if (($order == "name") ||
($order == "-name")) {
335 $this->bound_field
= "name";
337 } elseif (($order == "promo") ||
($order == "-promo")) {
338 $this->bound_field
= "promo";
341 if ($order{0} == '-') {
342 $show_bounds = -$show_bounds;
348 class XnetFicheView
extends UserView
350 public function __construct(PlSet
$set, array $params)
352 $this->entriesPerPage
= 20;
353 $this->addSort(new PlViewOrder('name', array(new UFO_Name(Profile
::DN_SORT
)), 'nom'));
354 $this->addSort(new PlViewOrder('promo', array(
355 new UFO_Promo(UserFilter
::DISPLAY
, true
),
356 new UFO_Name(Profile
::DN_SORT
),
358 parent
::__construct($set, $params);
361 public function templateName()
363 return 'include/plview.xnetuser.tpl';
367 class GadgetView
implements PlView
369 public function __construct(PlSet
$set, array $params)
374 public function apply(PlPage
$page)
376 $page->assign_by_ref('set', $this->set
->get(new PlLimit(5, 0)));
379 public function args()
385 class AddressesView
implements PlView
389 public function __construct(PlSet
$set, array $params)
394 public function apply(PlPage
$page)
396 $pids = $this->set
->getIds(new PlLimit());
397 $visibility = new ProfileVisibility(ProfileVisibility
::VIS_AX
);
398 pl_cached_content_headers('text/x-csv', 1);
400 $csv = fopen('php://output', 'w');
401 fputcsv($csv, array('adresses'), ';');
402 $res = XDB
::query('SELECT pd.public_name, pa.postalText
403 FROM profile_addresses AS pa
404 INNER JOIN profile_display AS pd ON (pd.pid = pa.pid)
405 WHERE pa.type = \'home\' AND pa.pub IN (\'public\', \'ax\') AND FIND_IN_SET(\'mail\', pa.flags) AND pa.pid IN {?}
406 GROUP BY pa.pid', $pids);
407 foreach ($res->fetchAllAssoc() as $item) {
408 fputcsv($csv, $item, ';');
414 public function args()
416 return $this->set
->args();
420 class JSonView
implements PlView
425 public function __construct(PlSet
$set, array $params)
428 $this->params
= $params;
431 public function apply(PlPage
$page)
434 $start = isset($this->params
['offset']) ?
$this->params
['offset'] : 0;
435 $count = isset($this->params
['count']) ?
$this->params
['count'] : 10;
436 $profiles = $this->set
->get(new PlLimit($start, $count));
437 foreach ($profiles as $profile) {
438 $export[] = $profile->export();
440 $page->jsonAssign('profile_count', $this->set
->count());
441 $page->jsonAssign('profiles', $export);
444 public function args()
446 return $this->set
->args();
450 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: