Typo.
[platal.git] / include / userset.inc.php
... / ...
CommitLineData
1<?php
2/***************************************************************************
3 * Copyright (C) 2003-2010 Polytechnique.org *
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
22class UserSet extends PlSet
23{
24 public function __construct(PlFilterCondition &$cond, $orders = null)
25 {
26 parent::__construct($cond, $orders);
27 }
28
29 protected function buildFilter(PlFilterCondition &$cond, $orders)
30 {
31 return new UserFilter($cond, $orders);
32 }
33}
34
35class 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
48class SearchSet extends ProfileSet
49{
50 public $advanced = false;
51 private $score = null;
52 private $quick = false;
53
54 public function __construct($quick = false, $no_search = false, PlFilterCondition $cond = null)
55 {
56 if ($no_search) {
57 return;
58 }
59
60 $this->quick = $quick;
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
70 if ($quick) {
71 $this->getQuick();
72 } else {
73 $this->getAdvanced();
74 }
75 }
76
77 private function getQuick()
78 {
79 if (!S::logged()) {
80 Env::kill('with_soundex');
81 }
82
83 require_once 'ufbuilder.inc.php';
84 $ufb = new UFB_QuickSearch();
85
86 if (!$ufb->isValid()) {
87 return;
88 }
89
90 $ufc = $ufb->getUFC();
91 $this->conds->addChild($ufc);
92
93 $orders = $ufb->getOrders();
94
95 if (S::logged() && Env::has('nonins')) {
96 $this->conds = new PFC_And($this->conds,
97 new PFC_Not(new UFC_Dead()),
98 new PFC_Not(new UFC_Registered())
99 );
100 }
101
102 parent::__construct($this->conds, $orders);
103 }
104
105 private function getAdvanced()
106 {
107 $this->advanced = true;
108 require_once 'ufbuilder.inc.php';
109 $ufb = new UFB_AdvancedSearch();
110
111 if (!$ufb->isValid()) {
112 return;
113 }
114
115 $this->conds->addChild($ufb->getUFC());
116 }
117
118 protected function &getFilterResults(PlFilter &$pf, PlLimit $limit)
119 {
120 $profiles = $pf->getProfiles($limit, Profile::FETCH_MINIFICHES);
121 return $profiles;
122 }
123}
124
125class ArraySet extends ProfileSet
126{
127 public function __construct(array $users)
128 {
129 $hruids = User::getBulkHruid($users, array('User', '_silent_user_callback'));
130 if (is_null($hruids) || count($hruids) == 0) {
131 $cond = new PFC_False();
132 } else {
133 $cond = new UFC_Hruid($hruids);
134 }
135 parent::__construct($cond);
136 }
137}
138
139abstract class ProfileView extends MultipageView
140{
141 protected function getBoundValue($obj)
142 {
143 if ($obj instanceof Profile) {
144 switch ($this->bound_field) {
145 case 'name':
146 $name = $obj->name('%l');
147 return strtoupper($name);
148 case 'promo':
149 return $obj->promo();
150 default:
151 return null;
152 }
153 }
154 return null;
155 }
156
157 public function bounds()
158 {
159 $order = Env::v('order', $this->defaultkey);
160 $show_bounds = 0;
161 if (($order == "name") || ($order == "-name")) {
162 $this->bound_field = "name";
163 $show_bounds = 1;
164 } elseif (($order == "promo") || ($order == "-promo")) {
165 $this->bound_field = "promo";
166 $show_bounds = -1;
167 }
168 if ($order{0} == '-') {
169 $show_bounds = -$show_bounds;
170 }
171 return $show_bounds;
172 }
173}
174
175class MinificheView extends ProfileView
176{
177 public function __construct(PlSet &$set, $data, array $params)
178 {
179 require_once 'education.func.inc.php';
180 global $globals;
181 $this->entriesPerPage = $globals->search->per_page;
182 if (@$params['with_score']) {
183 $this->addSort(new PlViewOrder('score', array(
184 new UFO_Score(true),
185 new UFO_ProfileUpdate(true),
186 new UFO_Promo(UserFilter::DISPLAY, true),
187 new UFO_Name(Profile::DN_SORT),
188 ), 'pertinence'));
189 }
190 $this->addSort(new PlViewOrder(
191 'name',
192 array(new UFO_Name(Profile::DN_SORT)),
193 'nom'));
194 $this->addSort(new PlViewOrder('promo', array(
195 new UFO_Promo(UserFilter::DISPLAY, true),
196 new UFO_Name(Profile::DN_SORT),
197 ), 'promotion'));
198 $this->addSort(new PlViewOrder('date_mod', array(
199 new UFO_ProfileUpdate(true),
200 new UFO_Promo(UserFilter::DISPLAY, true),
201 new UFO_Name(Profile::DN_SORT),
202 ), 'dernière modification'));
203 parent::__construct($set, $data, $params);
204 }
205
206 public function templateName()
207 {
208 return 'include/plview.minifiche.tpl';
209 }
210}
211
212class MentorView extends ProfileView
213{
214 public function __construct(PlSet &$set, $data, array $params)
215 {
216 $this->entriesPerPage = 10;
217 $this->addSort(new PlViewOrder('rand', array(new PFO_Random(S::i('uid'))), 'aléatoirement'));
218 $this->addSort(new PlViewOrder('name', array(new UFO_Name(Profile::DN_SORT)), 'nom'));
219 $this->addSort(new PlViewOrder('promo', array(
220 new UFO_Promo(UserFilter::DISPLAY, true),
221 new UFO_Name(Profile::DN_SORT),
222 ), 'promotion'));
223 $this->addSort(new PlViewOrder('date_mod', array(
224 new UFO_ProfileUpdate(true),
225 new UFO_Promo(UserFilter::DISPLAY, true),
226 new UFO_Name(Profile::DN_SORT),
227 ), 'dernière modification'));
228 parent::__construct($set, $data, $params);
229 }
230
231 public function templateName()
232 {
233 return 'include/plview.referent.tpl';
234 }
235}
236
237class TrombiView extends ProfileView
238{
239 public function __construct(PlSet &$set, $data, array $params)
240 {
241 $this->entriesPerPage = 24;
242 $this->defaultkey = 'name';
243 if (@$params['with_score']) {
244 $this->addSort(new PlViewOrder('score', array(
245 new UFO_Score(true),
246 new UFO_ProfileUpdate(true),
247 new UFO_Promo(UserFilter::DISPLAY, true),
248 new UFO_Name(Profile::DN_SORT),
249 ), 'pertinence'));
250 }
251 $set->addCond(new UFC_Photo());
252 $this->addSort(new PlViewOrder('name', array(new UFO_Name(Profile::DN_SORT)), 'nom'));
253 $this->addSort(new PlViewOrder('promo', array(
254 new UFO_Promo(UserFilter::DISPLAY, true),
255 new UFO_Name(Profile::DN_SORT),
256 ), 'promotion'));
257 parent::__construct($set, $data, $params);
258 }
259
260 public function templateName()
261 {
262 return 'include/plview.trombi.tpl';
263 }
264
265 public function apply(PlPage &$page)
266 {
267 if (!empty($GLOBALS['IS_XNET_SITE'])) {
268 global $globals;
269 $page->assign('mainsiteurl', 'https://' . $globals->core->secure_domain . '/');
270 }
271 return parent::apply($page);
272 }
273}
274
275class GadgetView implements PlView
276{
277 public function __construct(PlSet &$set, $data, array $params)
278 {
279 $this->set =& $set;
280 }
281
282 public function apply(PlPage &$page)
283 {
284 $page->assign_by_ref('set', $this->set->get(new PlLimit(5, 0)));
285 }
286
287 public function args()
288 {
289 return null;
290 }
291}
292
293// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
294?>