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 class GadgetView
implements PlView
307 public function __construct(PlSet
$set, array $params)
312 public function apply(PlPage
$page)
314 $page->assign_by_ref('set', $this->set
->get(new PlLimit(5, 0)));
317 public function args()
323 class AddressesView
implements PlView
327 public function __construct(PlSet
$set, array $params)
332 public function apply(PlPage
$page)
334 $pids = $this->set
->getIds(new PlLimit());
335 $visibility = new ProfileVisibility(ProfileVisibility
::VIS_AX
);
336 pl_cached_content_headers('text/x-csv', 1);
338 $csv = fopen('php://output', 'w');
339 fputcsv($csv, array('adresses'), ';');
340 $res = XDB
::query('SELECT pd.public_name, pa.postalText
341 FROM profile_addresses AS pa
342 INNER JOIN profile_display AS pd ON (pd.pid = pa.pid)
343 WHERE pa.type = \'home\' AND pa.pub IN (\'public\', \'ax\') AND FIND_IN_SET(\'mail\', pa.flags) AND pa.pid IN {?}
344 GROUP BY pa.pid', $pids);
345 foreach ($res->fetchAllAssoc() as $item) {
346 fputcsv($csv, $item, ';');
352 public function args()
354 return $this->set
->args();
358 class JSonView
implements PlView
363 public function __construct(PlSet
$set, array $params)
366 $this->params
= $params;
369 public function apply(PlPage
$page)
372 $start = isset($this->params
['offset']) ?
$this->params
['offset'] : 0;
373 $count = isset($this->params
['count']) ?
$this->params
['count'] : 10;
374 $profiles = $this->set
->get(new PlLimit($start, $count));
375 foreach ($profiles as $profile) {
376 $export[] = $profile->export();
378 $page->jsonAssign('profile_count', $this->set
->count());
379 $page->jsonAssign('profiles', $export);
382 public function args()
384 return $this->set
->args();
388 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: