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 | |
8467def7 | 118 | protected function &getFilterResults(PlFilter &$pf, PlLimit $limit) |
35fa92e8 | 119 | { |
8467def7 | 120 | return $pf->getProfiles($limit, Profile::FETCH_MINIFICHES); |
35fa92e8 | 121 | } |
8c4a0c30 | 122 | } |
123 | ||
470d14f6 | 124 | class ArraySet extends ProfileSet |
1cc0afe7 | 125 | { |
126 | public function __construct(array $users) | |
127 | { | |
8e720253 RB |
128 | $hruids = User::getBulkHruid($users, array('User', '_silent_user_callback')); |
129 | if (is_null($hruids) || count($hruids) == 0) { | |
130 | $cond = new PFC_False(); | |
1cc0afe7 | 131 | } else { |
8e720253 | 132 | $cond = new UFC_Hruid($hruids); |
1cc0afe7 | 133 | } |
8e720253 | 134 | parent::__construct($cond); |
1cc0afe7 | 135 | } |
136 | } | |
137 | ||
169edfac RB |
138 | abstract class ProfileView extends MultipageView |
139 | { | |
140 | protected function getBoundValue($obj) | |
141 | { | |
142 | if ($obj instanceof Profile) { | |
143 | switch ($this->bound_field) { | |
144 | case 'name': | |
145 | $name = $obj->name('%l'); | |
146 | return strtoupper($name); | |
147 | case 'promo': | |
148 | return $obj->promo(); | |
149 | default: | |
150 | return null; | |
151 | } | |
152 | } | |
153 | return null; | |
154 | } | |
316120eb FB |
155 | |
156 | public function bounds() | |
157 | { | |
158 | $order = Env::v('order', $this->defaultkey); | |
159 | $show_bounds = 0; | |
160 | if (($order == "name") || ($order == "-name")) { | |
161 | $this->bound_field = "name"; | |
162 | $show_bounds = 1; | |
163 | } elseif (($order == "promo") || ($order == "-promo")) { | |
164 | $this->bound_field = "promo"; | |
165 | $show_bounds = -1; | |
166 | } | |
167 | if ($order{0} == '-') { | |
168 | $show_bounds = -$show_bounds; | |
169 | } | |
170 | return $show_bounds; | |
171 | } | |
169edfac RB |
172 | } |
173 | ||
174 | class MinificheView extends ProfileView | |
8c4a0c30 | 175 | { |
176 | public function __construct(PlSet &$set, $data, array $params) | |
177 | { | |
f711b03f | 178 | require_once 'education.func.inc.php'; |
8c4a0c30 | 179 | global $globals; |
180 | $this->entriesPerPage = $globals->search->per_page; | |
35fa92e8 | 181 | if (@$params['with_score']) { |
8e720253 RB |
182 | $this->addSort(new PlViewOrder('score', array( |
183 | new UFO_Score(true), | |
184 | new UFO_ProfileUpdate(true), | |
185 | new UFO_Promo(UserFilter::DISPLAY, true), | |
913a4e90 | 186 | new UFO_Name(Profile::DN_SORT), |
8e720253 | 187 | ), 'pertinence')); |
35fa92e8 | 188 | } |
8e720253 RB |
189 | $this->addSort(new PlViewOrder( |
190 | 'name', | |
913a4e90 | 191 | array(new UFO_Name(Profile::DN_SORT)), |
8e720253 RB |
192 | 'nom')); |
193 | $this->addSort(new PlViewOrder('promo', array( | |
194 | new UFO_Promo(UserFilter::DISPLAY, true), | |
913a4e90 | 195 | new UFO_Name(Profile::DN_SORT), |
8e720253 RB |
196 | ), 'promotion')); |
197 | $this->addSort(new PlViewOrder('date_mod', array( | |
198 | new UFO_ProfileUpdate(true), | |
199 | new UFO_Promo(UserFilter::DISPLAY, true), | |
913a4e90 | 200 | new UFO_Name(Profile::DN_SORT), |
8e720253 | 201 | ), 'dernière modification')); |
8c4a0c30 | 202 | parent::__construct($set, $data, $params); |
203 | } | |
204 | ||
8c4a0c30 | 205 | public function templateName() |
206 | { | |
207 | return 'include/plview.minifiche.tpl'; | |
208 | } | |
209 | } | |
210 | ||
169edfac | 211 | class MentorView extends ProfileView |
ff3eb9b7 | 212 | { |
213 | public function __construct(PlSet &$set, $data, array $params) | |
214 | { | |
eaf30d86 | 215 | $this->entriesPerPage = 10; |
8e720253 | 216 | $this->addSort(new PlViewOrder('rand', array(new PFO_Random(S::i('uid'))), 'aléatoirement')); |
913a4e90 | 217 | $this->addSort(new PlViewOrder('name', array(new UFO_Name(Profile::DN_SORT)), 'nom')); |
8e720253 RB |
218 | $this->addSort(new PlViewOrder('promo', array( |
219 | new UFO_Promo(UserFilter::DISPLAY, true), | |
913a4e90 | 220 | new UFO_Name(Profile::DN_SORT), |
8e720253 RB |
221 | ), 'promotion')); |
222 | $this->addSort(new PlViewOrder('date_mod', array( | |
223 | new UFO_ProfileUpdate(true), | |
224 | new UFO_Promo(UserFilter::DISPLAY, true), | |
913a4e90 | 225 | new UFO_Name(Profile::DN_SORT), |
8e720253 | 226 | ), 'dernière modification')); |
eaf30d86 | 227 | parent::__construct($set, $data, $params); |
ff3eb9b7 | 228 | } |
229 | ||
ff3eb9b7 | 230 | public function templateName() |
231 | { | |
232 | return 'include/plview.referent.tpl'; | |
233 | } | |
234 | } | |
235 | ||
169edfac | 236 | class TrombiView extends ProfileView |
8c4a0c30 | 237 | { |
238 | public function __construct(PlSet &$set, $data, array $params) | |
239 | { | |
240 | $this->entriesPerPage = 24; | |
316120eb | 241 | $this->defaultkey = 'name'; |
35fa92e8 | 242 | if (@$params['with_score']) { |
8e720253 RB |
243 | $this->addSort(new PlViewOrder('score', array( |
244 | new UFO_Score(true), | |
245 | new UFO_ProfileUpdate(true), | |
246 | new UFO_Promo(UserFilter::DISPLAY, true), | |
913a4e90 | 247 | new UFO_Name(Profile::DN_SORT), |
8e720253 | 248 | ), 'pertinence')); |
35fa92e8 | 249 | } |
316120eb | 250 | $set->addCond(new UFC_Photo()); |
913a4e90 | 251 | $this->addSort(new PlViewOrder('name', array(new UFO_Name(Profile::DN_SORT)), 'nom')); |
8e720253 RB |
252 | $this->addSort(new PlViewOrder('promo', array( |
253 | new UFO_Promo(UserFilter::DISPLAY, true), | |
913a4e90 | 254 | new UFO_Name(Profile::DN_SORT), |
8e720253 | 255 | ), 'promotion')); |
8c4a0c30 | 256 | parent::__construct($set, $data, $params); |
257 | } | |
258 | ||
8c4a0c30 | 259 | public function templateName() |
260 | { | |
261 | return 'include/plview.trombi.tpl'; | |
262 | } | |
263 | ||
04334c61 | 264 | public function apply(PlPage &$page) |
8c4a0c30 | 265 | { |
266 | if (!empty($GLOBALS['IS_XNET_SITE'])) { | |
267 | global $globals; | |
268 | $page->assign('mainsiteurl', 'https://' . $globals->core->secure_domain . '/'); | |
269 | } | |
270 | return parent::apply($page); | |
271 | } | |
272 | } | |
273 | ||
92e80560 VZ |
274 | class GadgetView implements PlView |
275 | { | |
276 | public function __construct(PlSet &$set, $data, array $params) | |
277 | { | |
278 | $this->set =& $set; | |
279 | } | |
280 | ||
04334c61 | 281 | public function apply(PlPage &$page) |
92e80560 | 282 | { |
8e720253 | 283 | $page->assign_by_ref('set', $this->set->get(new PlLimit(5, 0))); |
92e80560 VZ |
284 | } |
285 | ||
286 | public function args() | |
287 | { | |
288 | return null; | |
289 | } | |
290 | } | |
291 | ||
8c4a0c30 | 292 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: |
293 | ?> |