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 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(PlFilterCondition
$cond = null
)
120 parent
::__construct(new UFB_AdvancedSearch(), $cond);
124 /** Simple set based on an array of User objects
126 class ArraySet
extends ProfileSet
128 public function __construct(array $users)
130 $hruids = User
::getBulkHruid($users, array('User', '_silent_user_callback'));
131 if (is_null($hruids) ||
count($hruids) == 0) {
132 $cond = new PFC_False();
134 $cond = new UFC_Hruid($hruids);
136 parent
::__construct($cond);
140 /** A multipage view for profiles
141 * Allows the display of bounds when sorting by name or promo.
143 abstract class ProfileView
extends MultipageView
145 protected function getBoundValue($obj)
147 if ($obj instanceof Profile
) {
148 switch ($this->bound_field
) {
150 $name = $obj->name('%l');
151 return strtoupper($name);
153 return $obj->promo();
161 public function bounds()
163 $order = Env
::v('order', $this->defaultkey
);
165 if (($order == "name") ||
($order == "-name")) {
166 $this->bound_field
= "name";
168 } elseif (($order == "promo") ||
($order == "-promo")) {
169 $this->bound_field
= "promo";
172 if ($order{0} == '-') {
173 $show_bounds = -$show_bounds;
179 /** An extended multipage view for profiles, as minifiches.
181 * - score (for a search query)
184 * - latest modification
186 * Paramaters for this view are:
187 * - with_score: whether to allow ordering by score (set only for a quick search)
188 * - starts_with: show only names beginning with the given letter
190 class MinificheView
extends ProfileView
192 public function __construct(PlSet
&$set, array $params)
195 $this->entriesPerPage
= $globals->search
->per_page
;
196 if (@$params['with_score']) {
197 $this->addSort(new PlViewOrder('score', array(
199 new UFO_ProfileUpdate(true
),
200 new UFO_Promo(UserFilter
::DISPLAY
, true
),
201 new UFO_Name(Profile
::DN_SORT
),
204 $this->addSort(new PlViewOrder(
206 array(new UFO_Name(Profile
::DN_SORT
)),
208 $this->addSort(new PlViewOrder('promo', array(
209 new UFO_Promo(UserFilter
::DISPLAY
, true
),
210 new UFO_Name(Profile
::DN_SORT
),
212 $this->addSort(new PlViewOrder('date_mod', array(
213 new UFO_ProfileUpdate(true
),
214 new UFO_Promo(UserFilter
::DISPLAY
, true
),
215 new UFO_Name(Profile
::DN_SORT
),
216 ), 'dernière modification'));
217 parent
::__construct($set, $params);
220 public function apply(PlPage
&$page)
222 if (array_key_exists('starts_with', $this->params
)
223 && $this->params
['starts_with'] != ""
224 && $this->params
['starts_with'] != null
) {
227 new UFC_Name(Profile
::LASTNAME
,
228 $this->params
['starts_with'], UFC_Name
::PREFIX
)
231 return parent
::apply($page);
234 public function templateName()
236 return 'include/plview.minifiche.tpl';
240 class MentorView
extends ProfileView
242 public function __construct(PlSet
&$set, array $params)
244 $this->entriesPerPage
= 10;
245 $this->addSort(new PlViewOrder('rand', array(new PFO_Random(S
::i('uid'))), 'aléatoirement'));
246 $this->addSort(new PlViewOrder('name', array(new UFO_Name(Profile
::DN_SORT
)), 'nom'));
247 $this->addSort(new PlViewOrder('promo', array(
248 new UFO_Promo(UserFilter
::DISPLAY
, true
),
249 new UFO_Name(Profile
::DN_SORT
),
251 $this->addSort(new PlViewOrder('date_mod', array(
252 new UFO_ProfileUpdate(true
),
253 new UFO_Promo(UserFilter
::DISPLAY
, true
),
254 new UFO_Name(Profile
::DN_SORT
),
255 ), 'dernière modification'));
256 parent
::__construct($set, $params);
259 public function templateName()
261 return 'include/plview.referent.tpl';
265 class TrombiView
extends ProfileView
267 public function __construct(PlSet
&$set, array $params)
269 $this->entriesPerPage
= 24;
270 $this->defaultkey
= 'name';
271 if (@$params['with_score']) {
272 $this->addSort(new PlViewOrder('score', array(
274 new UFO_ProfileUpdate(true
),
275 new UFO_Promo(UserFilter
::DISPLAY
, true
),
276 new UFO_Name(Profile
::DN_SORT
),
279 $set->addCond(new UFC_Photo());
280 $this->addSort(new PlViewOrder('name', array(new UFO_Name(Profile
::DN_SORT
)), 'nom'));
281 $this->addSort(new PlViewOrder('promo', array(
282 new UFO_Promo(UserFilter
::DISPLAY
, true
),
283 new UFO_Name(Profile
::DN_SORT
),
285 parent
::__construct($set, $params);
288 public function templateName()
290 return 'include/plview.trombi.tpl';
293 public function apply(PlPage
&$page)
295 if (!empty($GLOBALS['IS_XNET_SITE'])) {
297 $page->assign('mainsiteurl', 'https://' . $globals->core
->secure_domain
. '/');
299 return parent
::apply($page);
303 class GadgetView
implements PlView
305 public function __construct(PlSet
&$set, array $params)
310 public function apply(PlPage
&$page)
312 $page->assign_by_ref('set', $this->set
->get(new PlLimit(5, 0)));
315 public function args()
321 class AddressesView
implements PlView
325 public function __construct(PlSet
&$set, array $params)
330 public function apply(PlPage
&$page)
332 $pids = $this->set
->getIds(new PlLimit());
333 $visibility = new ProfileVisibility(ProfileVisibility
::VIS_AX
);
334 pl_content_headers('text/x-csv');
336 $csv = fopen('php://output', 'w');
337 fputcsv($csv, array('adresses'), ';');
338 $res = XDB
::query('SELECT pd.public_name, pa.postalText
339 FROM profile_addresses AS pa
340 INNER JOIN profile_display AS pd ON (pd.pid = pa.pid)
341 WHERE pa.type = \'home\' AND pa.pub IN (\'public\', \'ax\') AND FIND_IN_SET(\'mail\', pa.flags) AND pa.pid IN {?}
342 GROUP BY pa.pid', $pids);
343 foreach ($res->fetchAllAssoc() as $item) {
344 fputcsv($csv, $item, ';');
350 public function args()
352 return $this->set
->args();
356 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: