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 | |
8e720253 | 54 | public function __construct($quick = false, $no_search = 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)) { | |
63 | $this->conds = new PFC_And(); | |
64 | } else if ($cond instanceof PFC_And) { | |
65 | $this->conds = $cond; | |
66 | } else { | |
67 | $this->conds = new PFC_And($cond); | |
68 | } | |
69 | ||
8c4a0c30 | 70 | if ($quick) { |
8e720253 | 71 | $this->getQuick(); |
8c4a0c30 | 72 | } else { |
8e720253 | 73 | $this->getAdvanced(); |
8c4a0c30 | 74 | } |
75 | } | |
76 | ||
8e720253 | 77 | private function getQuick() |
8c4a0c30 | 78 | { |
8c4a0c30 | 79 | if (!S::logged()) { |
80 | Env::kill('with_soundex'); | |
81 | } | |
8e720253 RB |
82 | |
83 | require_once 'ufbuilder.inc.php'; | |
84 | $ufb = new UFB_QuickSearch(); | |
85 | ||
86 | if (!$ufb->isValid()) { | |
87 | return; | |
3b2f9d11 | 88 | } |
8e720253 | 89 | |
3314838e RB |
90 | $ufc = $ufb->getUFC(); |
91 | $this->conds->addChild($ufc); | |
8e720253 RB |
92 | |
93 | $orders = $ufb->getOrders(); | |
8e720253 | 94 | |
3b2f9d11 | 95 | if (S::logged() && Env::has('nonins')) { |
8e720253 | 96 | $this->conds = new PFC_And($this->conds, |
669db4e9 RB |
97 | new PFC_Not(new UFC_Dead()), |
98 | new PFC_Not(new UFC_Registered()) | |
8e720253 | 99 | ); |
3b2f9d11 | 100 | } |
8c4a0c30 | 101 | |
8e720253 | 102 | parent::__construct($this->conds, $orders); |
8c4a0c30 | 103 | } |
104 | ||
8e720253 | 105 | private function getAdvanced() |
8c4a0c30 | 106 | { |
86b5c8f0 | 107 | $this->advanced = true; |
8e720253 RB |
108 | require_once 'ufbuilder.inc.php'; |
109 | $ufb = new UFB_AdvancedSearch(); | |
110 | ||
111 | if (!$ufb->isValid()) { | |
112 | return; | |
8c4a0c30 | 113 | } |
8e720253 RB |
114 | |
115 | $this->conds->addChild($ufb->getUFC()); | |
8c4a0c30 | 116 | } |
35fa92e8 | 117 | |
a7d9ab89 | 118 | public function &get(PlLimit $limit = null, $orders = array()) |
35fa92e8 | 119 | { |
a7d9ab89 RB |
120 | $orders = array_merge($orders, $this->orders); |
121 | ||
122 | $uf = $this->buildFilter($this->conds, $orders); | |
8e720253 RB |
123 | if (is_null($limit)) { |
124 | $limit = new PlLimit(20, 0); | |
35fa92e8 | 125 | } |
8e720253 RB |
126 | $it = $uf->getProfiles($limit); |
127 | $this->count = $uf->getTotalCount(); | |
128 | return $it; | |
35fa92e8 | 129 | } |
8c4a0c30 | 130 | } |
131 | ||
1cc0afe7 | 132 | class ArraySet extends UserSet |
133 | { | |
134 | public function __construct(array $users) | |
135 | { | |
8e720253 RB |
136 | $hruids = User::getBulkHruid($users, array('User', '_silent_user_callback')); |
137 | if (is_null($hruids) || count($hruids) == 0) { | |
138 | $cond = new PFC_False(); | |
1cc0afe7 | 139 | } else { |
8e720253 | 140 | $cond = new UFC_Hruid($hruids); |
1cc0afe7 | 141 | } |
8e720253 | 142 | parent::__construct($cond); |
1cc0afe7 | 143 | } |
144 | } | |
145 | ||
169edfac RB |
146 | abstract class ProfileView extends MultipageView |
147 | { | |
148 | protected function getBoundValue($obj) | |
149 | { | |
150 | if ($obj instanceof Profile) { | |
151 | switch ($this->bound_field) { | |
152 | case 'name': | |
153 | $name = $obj->name('%l'); | |
154 | return strtoupper($name); | |
155 | case 'promo': | |
156 | return $obj->promo(); | |
157 | default: | |
158 | return null; | |
159 | } | |
160 | } | |
161 | return null; | |
162 | } | |
163 | } | |
164 | ||
165 | class MinificheView extends ProfileView | |
8c4a0c30 | 166 | { |
167 | public function __construct(PlSet &$set, $data, array $params) | |
168 | { | |
f711b03f | 169 | require_once 'education.func.inc.php'; |
8c4a0c30 | 170 | global $globals; |
171 | $this->entriesPerPage = $globals->search->per_page; | |
35fa92e8 | 172 | if (@$params['with_score']) { |
8e720253 RB |
173 | $this->addSort(new PlViewOrder('score', array( |
174 | new UFO_Score(true), | |
175 | new UFO_ProfileUpdate(true), | |
176 | new UFO_Promo(UserFilter::DISPLAY, true), | |
913a4e90 | 177 | new UFO_Name(Profile::DN_SORT), |
8e720253 | 178 | ), 'pertinence')); |
35fa92e8 | 179 | } |
8e720253 RB |
180 | $this->addSort(new PlViewOrder( |
181 | 'name', | |
913a4e90 | 182 | array(new UFO_Name(Profile::DN_SORT)), |
8e720253 RB |
183 | 'nom')); |
184 | $this->addSort(new PlViewOrder('promo', array( | |
185 | new UFO_Promo(UserFilter::DISPLAY, true), | |
913a4e90 | 186 | new UFO_Name(Profile::DN_SORT), |
8e720253 RB |
187 | ), 'promotion')); |
188 | $this->addSort(new PlViewOrder('date_mod', array( | |
189 | new UFO_ProfileUpdate(true), | |
190 | new UFO_Promo(UserFilter::DISPLAY, true), | |
913a4e90 | 191 | new UFO_Name(Profile::DN_SORT), |
8e720253 | 192 | ), 'dernière modification')); |
8c4a0c30 | 193 | parent::__construct($set, $data, $params); |
194 | } | |
195 | ||
8e720253 | 196 | public function bounds() |
b71b2a36 | 197 | { |
8e720253 RB |
198 | $order = Env::v('order', $this->defaultkey); |
199 | $show_bounds = 0; | |
200 | if (($order == "name") || ($order == "-name")) { | |
201 | $this->bound_field = "name"; | |
202 | $show_bounds = 1; | |
203 | } elseif (($order == "promo") || ($order == "-promo")) { | |
204 | $this->bound_field = "promo"; | |
205 | $show_bounds = -1; | |
206 | } | |
207 | if ($order{0} == '-') { | |
208 | $show_bounds = -$show_bounds; | |
209 | } | |
210 | return $show_bounds; | |
b71b2a36 SJ |
211 | } |
212 | ||
8c4a0c30 | 213 | public function templateName() |
214 | { | |
215 | return 'include/plview.minifiche.tpl'; | |
216 | } | |
217 | } | |
218 | ||
169edfac | 219 | class MentorView extends ProfileView |
ff3eb9b7 | 220 | { |
221 | public function __construct(PlSet &$set, $data, array $params) | |
222 | { | |
eaf30d86 | 223 | $this->entriesPerPage = 10; |
8e720253 | 224 | $this->addSort(new PlViewOrder('rand', array(new PFO_Random(S::i('uid'))), 'aléatoirement')); |
913a4e90 | 225 | $this->addSort(new PlViewOrder('name', array(new UFO_Name(Profile::DN_SORT)), 'nom')); |
8e720253 RB |
226 | $this->addSort(new PlViewOrder('promo', array( |
227 | new UFO_Promo(UserFilter::DISPLAY, true), | |
913a4e90 | 228 | new UFO_Name(Profile::DN_SORT), |
8e720253 RB |
229 | ), 'promotion')); |
230 | $this->addSort(new PlViewOrder('date_mod', array( | |
231 | new UFO_ProfileUpdate(true), | |
232 | new UFO_Promo(UserFilter::DISPLAY, true), | |
913a4e90 | 233 | new UFO_Name(Profile::DN_SORT), |
8e720253 | 234 | ), 'dernière modification')); |
eaf30d86 | 235 | parent::__construct($set, $data, $params); |
ff3eb9b7 | 236 | } |
237 | ||
b71b2a36 SJ |
238 | public function bounds() |
239 | { | |
240 | $order = Env::v('order', $this->defaultkey); | |
241 | $show_bounds = 0; | |
242 | if (($order == "name") || ($order == "-name")) { | |
243 | $this->bound_field = "nom"; | |
244 | $show_bounds = 1; | |
245 | } elseif (($order == "promo") || ($order == "-promo")) { | |
246 | $this->bound_field = "promo"; | |
247 | $show_bounds = -1; | |
248 | } | |
249 | if ($order{0} == '-') { | |
250 | $show_bounds = -$show_bounds; | |
251 | } | |
252 | return $show_bounds; | |
253 | } | |
254 | ||
ff3eb9b7 | 255 | public function templateName() |
256 | { | |
257 | return 'include/plview.referent.tpl'; | |
258 | } | |
259 | } | |
260 | ||
169edfac | 261 | class TrombiView extends ProfileView |
8c4a0c30 | 262 | { |
263 | public function __construct(PlSet &$set, $data, array $params) | |
264 | { | |
265 | $this->entriesPerPage = 24; | |
35fa92e8 | 266 | if (@$params['with_score']) { |
8e720253 RB |
267 | $this->addSort(new PlViewOrder('score', array( |
268 | new UFO_Score(true), | |
269 | new UFO_ProfileUpdate(true), | |
270 | new UFO_Promo(UserFilter::DISPLAY, true), | |
913a4e90 | 271 | new UFO_Name(Profile::DN_SORT), |
8e720253 | 272 | ), 'pertinence')); |
35fa92e8 | 273 | } |
913a4e90 | 274 | $this->addSort(new PlViewOrder('name', array(new UFO_Name(Profile::DN_SORT)), 'nom')); |
8e720253 RB |
275 | $this->addSort(new PlViewOrder('promo', array( |
276 | new UFO_Promo(UserFilter::DISPLAY, true), | |
913a4e90 | 277 | new UFO_Name(Profile::DN_SORT), |
8e720253 | 278 | ), 'promotion')); |
8c4a0c30 | 279 | parent::__construct($set, $data, $params); |
280 | } | |
281 | ||
b71b2a36 SJ |
282 | public function bounds() |
283 | { | |
284 | $order = Env::v('order', $this->defaultkey); | |
285 | $show_bounds = 0; | |
286 | if (($order == "name") || ($order == "-name")) { | |
287 | $this->bound_field = "nom"; | |
288 | $show_bounds = 1; | |
289 | } elseif (($order == "promo") || ($order == "-promo")) { | |
290 | $this->bound_field = "promo"; | |
291 | $show_bounds = -1; | |
292 | } | |
293 | if ($order{0} == '-') { | |
294 | $show_bounds = -$show_bounds; | |
295 | } | |
296 | return $show_bounds; | |
297 | } | |
298 | ||
8c4a0c30 | 299 | public function templateName() |
300 | { | |
301 | return 'include/plview.trombi.tpl'; | |
302 | } | |
303 | ||
04334c61 | 304 | public function apply(PlPage &$page) |
8c4a0c30 | 305 | { |
306 | if (!empty($GLOBALS['IS_XNET_SITE'])) { | |
307 | global $globals; | |
308 | $page->assign('mainsiteurl', 'https://' . $globals->core->secure_domain . '/'); | |
309 | } | |
310 | return parent::apply($page); | |
311 | } | |
312 | } | |
313 | ||
92e80560 VZ |
314 | class GadgetView implements PlView |
315 | { | |
316 | public function __construct(PlSet &$set, $data, array $params) | |
317 | { | |
318 | $this->set =& $set; | |
319 | } | |
320 | ||
04334c61 | 321 | public function apply(PlPage &$page) |
92e80560 | 322 | { |
8e720253 | 323 | $page->assign_by_ref('set', $this->set->get(new PlLimit(5, 0))); |
92e80560 VZ |
324 | } |
325 | ||
326 | public function args() | |
327 | { | |
328 | return null; | |
329 | } | |
330 | } | |
331 | ||
8c4a0c30 | 332 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: |
333 | ?> |