1ff19eca552420913ec30eb438961377c2601527
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 emails
128 class UserArraySet
extends UserSet
130 public function __construct(array $emails)
132 parent
::__construct(new UFC_Email($emails));
136 /** Simple set based on an array of Profile emails
138 class ProfileArraySet
extends ProfileSet
140 public function __construct(array $emails)
142 parent
::__construct(new UFC_Email($emails));
147 /** A multipage view for profiles or users
148 * Allows the display of bounds when sorting by name or promo.
150 abstract class MixedView
extends MultipageView
152 protected function getBoundValue($obj)
154 if ($obj instanceof Profile
) {
155 switch ($this->bound_field
) {
157 $name = $obj->name('%l');
158 return strtoupper($name);
160 return $obj->promo();
164 } elseif ($obj instanceof User
) {
165 switch ($this->bound_field
) {
167 $name = $obj->lastName();
168 return strtoupper($name);
170 if ($obj->hasProfile()) {
171 return $obj->profile()->promo();
182 public function bounds()
184 $order = Env
::v('order', $this->defaultkey
);
186 if (($order == "name") ||
($order == "-name")) {
187 $this->bound_field
= "name";
189 } elseif (($order == "promo") ||
($order == "-promo")) {
190 $this->bound_field
= "promo";
193 if ($order{0} == '-') {
194 $show_bounds = -$show_bounds;
200 /** An extended multipage view for profiles, as minifiches.
202 * - score (for a search query)
205 * - latest modification
207 * Paramaters for this view are:
208 * - with_score: whether to allow ordering by score (set only for a quick search)
209 * - starts_with: show only names beginning with the given letter
211 class MinificheView
extends MixedView
213 public function __construct(PlSet
$set, array $params)
216 $this->entriesPerPage
= $globals->search
->per_page
;
217 if (@$params['with_score']) {
218 $this->addSort(new PlViewOrder('score', array(
220 new UFO_ProfileUpdate(true
),
221 new UFO_Promo(UserFilter
::DISPLAY
, true
),
225 $this->addSort(new PlViewOrder(
227 array(new UFO_Name()),
229 $this->addSort(new PlViewOrder('promo', array(
230 new UFO_Promo(UserFilter
::DISPLAY
, true
),
233 $this->addSort(new PlViewOrder('date_mod', array(
234 new UFO_ProfileUpdate(true
),
235 new UFO_Promo(UserFilter
::DISPLAY
, true
),
237 ), 'dernière modification'));
238 parent
::__construct($set, $params);
241 public function apply(PlPage
$page)
243 if (array_key_exists('starts_with', $this->params
)
244 && $this->params
['starts_with'] != ""
245 && $this->params
['starts_with'] != null
) {
248 new UFC_NameInitial($this->params
['starts_with'])
251 return parent
::apply($page);
254 public function templateName()
256 return 'include/plview.minifiche.tpl';
260 class MentorView
extends MixedView
262 public function __construct(PlSet
$set, array $params)
264 $this->entriesPerPage
= 10;
265 $this->addSort(new PlViewOrder('rand', array(new PFO_Random(S
::i('uid'))), 'aléatoirement'));
266 $this->addSort(new PlViewOrder('name', array(new UFO_Name()), 'nom'));
267 $this->addSort(new PlViewOrder('promo', array(
268 new UFO_Promo(UserFilter
::DISPLAY
, true
),
271 $this->addSort(new PlViewOrder('date_mod', array(
272 new UFO_ProfileUpdate(true
),
273 new UFO_Promo(UserFilter
::DISPLAY
, true
),
275 ), 'dernière modification'));
276 parent
::__construct($set, $params);
279 public function templateName()
281 return 'include/plview.referent.tpl';
285 class GroupMemberView
extends MixedView
287 public function __construct(PlSet
$set, array $params)
289 $this->entriesPerPage
= 20;
290 $this->addSort(new PlViewOrder('name', array(new UFO_Name()), 'nom'));
291 $this->addSort(new PlViewOrder('promo', array(
292 new UFO_Promo(UserFilter
::DISPLAY
, true
),
295 $this->addSort(new PlViewOrder('date_mod', array(
296 new UFO_ProfileUpdate(true
),
297 new UFO_Promo(UserFilter
::DISPLAY
, true
),
299 ), 'dernière modification'));
300 parent
::__construct($set, $params);
303 public function templateName()
305 return 'include/plview.groupmember.tpl';
309 class ListMemberView
extends MixedView
311 public function __construct(PlSet
$set, array $params)
313 $this->entriesPerPage
= 100;
314 $this->addSort(new PlViewOrder('name', array(new UFO_Name()), 'nom'));
315 $this->addSort(new PlViewOrder('promo', array(
316 new UFO_Promo(UserFilter
::DISPLAY
, true
),
319 parent
::__construct($set, $params);
322 public function templateName()
324 return 'include/plview.listmember.tpl';
328 class TrombiView
extends MixedView
330 public function __construct(PlSet
$set, array $params)
332 $this->entriesPerPage
= 24;
333 $this->defaultkey
= 'name';
334 if (@$params['with_score']) {
335 $this->addSort(new PlViewOrder('score', array(
337 new UFO_ProfileUpdate(true
),
338 new UFO_Promo(UserFilter
::DISPLAY
, true
),
342 $set->addCond(new UFC_Photo());
343 $this->addSort(new PlViewOrder('name', array(new UFO_Name()), 'nom'));
344 $this->addSort(new PlViewOrder('promo', array(
345 new UFO_Promo(UserFilter
::DISPLAY
, true
),
348 parent
::__construct($set, $params);
351 public function templateName()
353 return 'include/plview.trombi.tpl';
356 public function apply(PlPage
$page)
358 if (!empty($GLOBALS['IS_XNET_SITE'])) {
360 $page->assign('mainsiteurl', 'https://' . $globals->core
->secure_domain
. '/');
362 return parent
::apply($page);
366 class MapView
implements PlView
370 public function __construct(PlSet
$set, array $params)
375 public function apply(PlPage
$page)
377 Platal
::load('geoloc');
379 if (Get
::b('ajax')) {
380 $pids = $this->set
->getIds(new PlLimit());
381 GeolocModule
::assign_json_to_map($page, $pids);
385 $this->set
->getIds(new PlLimit());
386 GeolocModule
::prepare_map($page);
387 return 'geoloc/index.tpl';
391 public function args()
393 return $this->set
->args();
397 class GadgetView
implements PlView
399 public function __construct(PlSet
$set, array $params)
404 public function apply(PlPage
$page)
406 $page->assign_by_ref('set', $this->set
->get(new PlLimit(5, 0)));
409 public function args()
415 class AddressesView
implements PlView
419 public function __construct(PlSet
$set, array $params)
424 public function apply(PlPage
$page)
426 $pids = $this->set
->getIds(new PlLimit());
427 $visibility = Visibility
::defaultForRead(Visibility
::VIEW_AX
);
428 pl_cached_content_headers('text/x-csv', 1);
430 $csv = fopen('php://output', 'w');
431 fputcsv($csv, array('adresses'), ';');
433 $res = XDB
::query('SELECT pd.public_name, pa.postalText
434 FROM profile_addresses AS pa
435 INNER JOIN profile_display AS pd ON (pd.pid = pa.pid)
436 WHERE pa.type = \'home\' AND pa.pub IN (\'public\', \'ax\') AND FIND_IN_SET(\'mail\', pa.flags) AND pa.pid IN {?}
437 GROUP BY pa.pid', $pids);
438 foreach ($res->fetchAllAssoc() as $item) {
439 fputcsv($csv, $item, ';');
446 public function args()
448 return $this->set
->args();
452 class JSonView
implements PlView
457 public function __construct(PlSet
$set, array $params)
460 $this->params
= $params;
463 public function apply(PlPage
$page)
466 $start = isset($this->params
['offset']) ?
$this->params
['offset'] : 0;
467 $count = isset($this->params
['count']) ?
$this->params
['count'] : 10;
468 $profiles = $this->set
->get(new PlLimit($start, $count));
469 foreach ($profiles as $profile) {
470 $export[] = $profile->export();
472 $page->jsonAssign('profile_count', $this->set
->count());
473 $page->jsonAssign('profiles', $export);
476 public function args()
478 return $this->set
->args();
482 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: