Commit | Line | Data |
---|---|---|
8c4a0c30 | 1 | <?php |
2 | /*************************************************************************** | |
9f5bd98e | 3 | * Copyright (C) 2003-2010 Polytechnique.org * |
8c4a0c30 | 4 | * http://opensource.polytechnique.org/ * |
5 | * * | |
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. * | |
10 | * * | |
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. * | |
15 | * * | |
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 * | |
18 | * Foundation, Inc., * | |
19 | * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * | |
20 | ***************************************************************************/ | |
21 | ||
8c4a0c30 | 22 | class UserSet extends PlSet |
23 | { | |
a7d9ab89 | 24 | public function __construct(PlFilterCondition &$cond, $orders = null) |
8c4a0c30 | 25 | { |
8e720253 | 26 | parent::__construct($cond, $orders); |
76cbe885 FB |
27 | } |
28 | ||
8e720253 | 29 | protected function buildFilter(PlFilterCondition &$cond, $orders) |
76cbe885 | 30 | { |
8e720253 | 31 | return new UserFilter($cond, $orders); |
8c4a0c30 | 32 | } |
33 | } | |
34 | ||
a7d9ab89 RB |
35 | class ProfileSet extends PlSet |
36 | { | |
37 | public function __construct(PlFilterCondition &$cond, $orders = null) | |
38 | { | |
39 | parent::__construct($cond, $orders); | |
40 | } | |
41 | ||
42 | protected function buildFilter(PlFilterCondition &$cond, $orders) | |
43 | { | |
44 | return new ProfileFilter($cond, $orders); | |
45 | } | |
46 | } | |
47 | ||
48 | class SearchSet extends ProfileSet | |
8c4a0c30 | 49 | { |
86b5c8f0 | 50 | public $advanced = false; |
8e720253 | 51 | private $score = null; |
8e720253 | 52 | private $quick = false; |
8c4a0c30 | 53 | |
8eb6931f | 54 | public function __construct($quick = false, PlFilterCondition $cond = null) |
8c4a0c30 | 55 | { |
8c4a0c30 | 56 | if ($no_search) { |
57 | return; | |
58 | } | |
59 | ||
60 | $this->quick = $quick; | |
8e720253 RB |
61 | |
62 | if (is_null($cond)) { | |
8eb6931f | 63 | $conds = new PFC_And(); |
8e720253 | 64 | } else if ($cond instanceof PFC_And) { |
8eb6931f | 65 | $conds = $cond; |
8e720253 | 66 | } else { |
8eb6931f | 67 | $conds = new PFC_And($cond); |
8e720253 RB |
68 | } |
69 | ||
8c4a0c30 | 70 | if ($quick) { |
8eb6931f | 71 | $this->getQuick($conds); |
8c4a0c30 | 72 | } else { |
8eb6931f | 73 | $this->getAdvanced($conds); |
8c4a0c30 | 74 | } |
75 | } | |
76 | ||
8eb6931f RB |
77 | /** Sets up the conditions for a Quick Search |
78 | * @param $conds Additional conds (as a PFC_And) | |
79 | */ | |
80 | private function getQuick($conds) | |
8c4a0c30 | 81 | { |
8c4a0c30 | 82 | if (!S::logged()) { |
83 | Env::kill('with_soundex'); | |
84 | } | |
8e720253 RB |
85 | |
86 | require_once 'ufbuilder.inc.php'; | |
87 | $ufb = new UFB_QuickSearch(); | |
88 | ||
89 | if (!$ufb->isValid()) { | |
90 | return; | |
3b2f9d11 | 91 | } |
8e720253 | 92 | |
3314838e | 93 | $ufc = $ufb->getUFC(); |
8eb6931f | 94 | $conds->addChild($ufc); |
8e720253 RB |
95 | |
96 | $orders = $ufb->getOrders(); | |
8e720253 | 97 | |
3b2f9d11 | 98 | if (S::logged() && Env::has('nonins')) { |
8eb6931f | 99 | $conds = new PFC_And($conds, |
669db4e9 RB |
100 | new PFC_Not(new UFC_Dead()), |
101 | new PFC_Not(new UFC_Registered()) | |
8e720253 | 102 | ); |
3b2f9d11 | 103 | } |
8c4a0c30 | 104 | |
8eb6931f | 105 | parent::__construct($conds, $orders); |
8c4a0c30 | 106 | } |
107 | ||
8eb6931f RB |
108 | /** Sets up the conditions for an Advanced Search |
109 | * @param $conds Additional conds (as a PFC_And) | |
110 | */ | |
111 | private function getAdvanced($conds) | |
8c4a0c30 | 112 | { |
86b5c8f0 | 113 | $this->advanced = true; |
8e720253 RB |
114 | require_once 'ufbuilder.inc.php'; |
115 | $ufb = new UFB_AdvancedSearch(); | |
116 | ||
117 | if (!$ufb->isValid()) { | |
118 | return; | |
8c4a0c30 | 119 | } |
8e720253 | 120 | |
8eb6931f RB |
121 | $ufc = $ufb->getUFC(); |
122 | $conds->addChild($ufc); | |
123 | ||
124 | $orders = $ufb->getOrders(); | |
125 | ||
126 | parent::__construct($conds, $orders); | |
8c4a0c30 | 127 | } |
35fa92e8 | 128 | |
8467def7 | 129 | protected function &getFilterResults(PlFilter &$pf, PlLimit $limit) |
35fa92e8 | 130 | { |
d667c548 SJ |
131 | $profiles = $pf->getProfiles($limit, Profile::FETCH_MINIFICHES); |
132 | return $profiles; | |
35fa92e8 | 133 | } |
8c4a0c30 | 134 | } |
135 | ||
8eb6931f RB |
136 | /** Simple set based on an array of User objects |
137 | */ | |
470d14f6 | 138 | class ArraySet extends ProfileSet |
1cc0afe7 | 139 | { |
140 | public function __construct(array $users) | |
141 | { | |
8e720253 RB |
142 | $hruids = User::getBulkHruid($users, array('User', '_silent_user_callback')); |
143 | if (is_null($hruids) || count($hruids) == 0) { | |
144 | $cond = new PFC_False(); | |
1cc0afe7 | 145 | } else { |
8e720253 | 146 | $cond = new UFC_Hruid($hruids); |
1cc0afe7 | 147 | } |
8e720253 | 148 | parent::__construct($cond); |
1cc0afe7 | 149 | } |
150 | } | |
151 | ||
8eb6931f RB |
152 | /** A multipage view for profiles |
153 | * Allows the display of bounds when sorting by name or promo. | |
154 | */ | |
169edfac RB |
155 | abstract class ProfileView extends MultipageView |
156 | { | |
157 | protected function getBoundValue($obj) | |
158 | { | |
159 | if ($obj instanceof Profile) { | |
160 | switch ($this->bound_field) { | |
161 | case 'name': | |
162 | $name = $obj->name('%l'); | |
163 | return strtoupper($name); | |
164 | case 'promo': | |
165 | return $obj->promo(); | |
166 | default: | |
167 | return null; | |
168 | } | |
169 | } | |
170 | return null; | |
171 | } | |
316120eb FB |
172 | |
173 | public function bounds() | |
174 | { | |
175 | $order = Env::v('order', $this->defaultkey); | |
176 | $show_bounds = 0; | |
177 | if (($order == "name") || ($order == "-name")) { | |
178 | $this->bound_field = "name"; | |
179 | $show_bounds = 1; | |
180 | } elseif (($order == "promo") || ($order == "-promo")) { | |
181 | $this->bound_field = "promo"; | |
182 | $show_bounds = -1; | |
183 | } | |
184 | if ($order{0} == '-') { | |
185 | $show_bounds = -$show_bounds; | |
186 | } | |
187 | return $show_bounds; | |
188 | } | |
169edfac RB |
189 | } |
190 | ||
8eb6931f RB |
191 | /** An extended multipage view for profiles, as minifiches. |
192 | * Allows to sort by: | |
193 | * - score (for a search query) | |
194 | * - name | |
195 | * - promo | |
196 | * - latest modification | |
197 | * | |
198 | * Paramaters for this view are: | |
199 | * - with_score: whether to allow ordering by score (set only for a quick search) | |
200 | * - starts_with: show only names beginning with the given letter | |
201 | */ | |
169edfac | 202 | class MinificheView extends ProfileView |
8c4a0c30 | 203 | { |
8eb6931f | 204 | public function __construct(PlSet &$set, array $params) |
8c4a0c30 | 205 | { |
8c4a0c30 | 206 | global $globals; |
207 | $this->entriesPerPage = $globals->search->per_page; | |
35fa92e8 | 208 | if (@$params['with_score']) { |
8e720253 RB |
209 | $this->addSort(new PlViewOrder('score', array( |
210 | new UFO_Score(true), | |
211 | new UFO_ProfileUpdate(true), | |
212 | new UFO_Promo(UserFilter::DISPLAY, true), | |
913a4e90 | 213 | new UFO_Name(Profile::DN_SORT), |
8e720253 | 214 | ), 'pertinence')); |
35fa92e8 | 215 | } |
8e720253 RB |
216 | $this->addSort(new PlViewOrder( |
217 | 'name', | |
913a4e90 | 218 | array(new UFO_Name(Profile::DN_SORT)), |
8e720253 RB |
219 | 'nom')); |
220 | $this->addSort(new PlViewOrder('promo', array( | |
221 | new UFO_Promo(UserFilter::DISPLAY, true), | |
913a4e90 | 222 | new UFO_Name(Profile::DN_SORT), |
8e720253 RB |
223 | ), 'promotion')); |
224 | $this->addSort(new PlViewOrder('date_mod', array( | |
225 | new UFO_ProfileUpdate(true), | |
226 | new UFO_Promo(UserFilter::DISPLAY, true), | |
913a4e90 | 227 | new UFO_Name(Profile::DN_SORT), |
8e720253 | 228 | ), 'dernière modification')); |
8eb6931f RB |
229 | parent::__construct($set, $params); |
230 | } | |
231 | ||
232 | public function apply(PlPage &$page) | |
233 | { | |
234 | if (array_key_exists('starts_with', $this->params) | |
235 | && $this->params['starts_with'] != "" | |
236 | && $this->params['starts_with'] != null) { | |
237 | ||
238 | $this->set->addCond( | |
239 | new UFC_Name(Profile::LASTNAME, | |
240 | $this->params['starts_with'], UFC_Name::PREFIX) | |
241 | ); | |
242 | } | |
243 | return parent::apply($page); | |
8c4a0c30 | 244 | } |
245 | ||
8c4a0c30 | 246 | public function templateName() |
247 | { | |
248 | return 'include/plview.minifiche.tpl'; | |
249 | } | |
250 | } | |
251 | ||
169edfac | 252 | class MentorView extends ProfileView |
ff3eb9b7 | 253 | { |
8eb6931f | 254 | public function __construct(PlSet &$set, array $params) |
ff3eb9b7 | 255 | { |
eaf30d86 | 256 | $this->entriesPerPage = 10; |
8e720253 | 257 | $this->addSort(new PlViewOrder('rand', array(new PFO_Random(S::i('uid'))), 'aléatoirement')); |
913a4e90 | 258 | $this->addSort(new PlViewOrder('name', array(new UFO_Name(Profile::DN_SORT)), 'nom')); |
8e720253 RB |
259 | $this->addSort(new PlViewOrder('promo', array( |
260 | new UFO_Promo(UserFilter::DISPLAY, true), | |
913a4e90 | 261 | new UFO_Name(Profile::DN_SORT), |
8e720253 RB |
262 | ), 'promotion')); |
263 | $this->addSort(new PlViewOrder('date_mod', array( | |
264 | new UFO_ProfileUpdate(true), | |
265 | new UFO_Promo(UserFilter::DISPLAY, true), | |
913a4e90 | 266 | new UFO_Name(Profile::DN_SORT), |
8e720253 | 267 | ), 'dernière modification')); |
8eb6931f | 268 | parent::__construct($set, $params); |
ff3eb9b7 | 269 | } |
270 | ||
ff3eb9b7 | 271 | public function templateName() |
272 | { | |
273 | return 'include/plview.referent.tpl'; | |
274 | } | |
275 | } | |
276 | ||
169edfac | 277 | class TrombiView extends ProfileView |
8c4a0c30 | 278 | { |
8eb6931f | 279 | public function __construct(PlSet &$set, array $params) |
8c4a0c30 | 280 | { |
281 | $this->entriesPerPage = 24; | |
316120eb | 282 | $this->defaultkey = 'name'; |
35fa92e8 | 283 | if (@$params['with_score']) { |
8e720253 RB |
284 | $this->addSort(new PlViewOrder('score', array( |
285 | new UFO_Score(true), | |
286 | new UFO_ProfileUpdate(true), | |
287 | new UFO_Promo(UserFilter::DISPLAY, true), | |
913a4e90 | 288 | new UFO_Name(Profile::DN_SORT), |
8e720253 | 289 | ), 'pertinence')); |
35fa92e8 | 290 | } |
316120eb | 291 | $set->addCond(new UFC_Photo()); |
913a4e90 | 292 | $this->addSort(new PlViewOrder('name', array(new UFO_Name(Profile::DN_SORT)), 'nom')); |
8e720253 RB |
293 | $this->addSort(new PlViewOrder('promo', array( |
294 | new UFO_Promo(UserFilter::DISPLAY, true), | |
913a4e90 | 295 | new UFO_Name(Profile::DN_SORT), |
8e720253 | 296 | ), 'promotion')); |
8eb6931f | 297 | parent::__construct($set, $params); |
8c4a0c30 | 298 | } |
299 | ||
8c4a0c30 | 300 | public function templateName() |
301 | { | |
302 | return 'include/plview.trombi.tpl'; | |
303 | } | |
304 | ||
04334c61 | 305 | public function apply(PlPage &$page) |
8c4a0c30 | 306 | { |
307 | if (!empty($GLOBALS['IS_XNET_SITE'])) { | |
308 | global $globals; | |
309 | $page->assign('mainsiteurl', 'https://' . $globals->core->secure_domain . '/'); | |
310 | } | |
311 | return parent::apply($page); | |
312 | } | |
313 | } | |
314 | ||
92e80560 VZ |
315 | class GadgetView implements PlView |
316 | { | |
8eb6931f | 317 | public function __construct(PlSet &$set, array $params) |
92e80560 VZ |
318 | { |
319 | $this->set =& $set; | |
320 | } | |
321 | ||
04334c61 | 322 | public function apply(PlPage &$page) |
92e80560 | 323 | { |
8e720253 | 324 | $page->assign_by_ref('set', $this->set->get(new PlLimit(5, 0))); |
92e80560 VZ |
325 | } |
326 | ||
327 | public function args() | |
328 | { | |
329 | return null; | |
330 | } | |
331 | } | |
332 | ||
8c4a0c30 | 333 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: |
334 | ?> |