Merge commit 'origin/fusionax' into account
[platal.git] / include / userset.inc.php
CommitLineData
8c4a0c30 1<?php
2/***************************************************************************
8d84c630 3 * Copyright (C) 2003-2009 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 22class UserSet extends PlSet
23{
76cbe885
FB
24 private $cond;
25
26 public function __construct($cond = null)
8c4a0c30 27 {
76cbe885
FB
28 $this->cond = new UFC_And();
29 if (!is_null($cond)) {
30 $this->cond->addChild($cond);
31 }
32 }
33
34 public function &get($fields, $joins, $where, $groupby, $order, $limitcount = null, $limitfrom = null)
35 {
36 $uf = new UserFilter($this->cond);
37 $users = $uf->getUsers($limitcount, $limitfrom);
38 $this->count = $uf->getTotalCount();
39 return $users;
8c4a0c30 40 }
41}
42
43class SearchSet extends UserSet
44{
86b5c8f0 45 public $advanced = false;
35fa92e8 46 private $score = null;
8c4a0c30 47 private $order = null;
48 private $quick = false;
49
a2aa8436 50 public function __construct($quick = false, $no_search = false, $join = '', $where = '')
8c4a0c30 51 {
adb07f6f 52 Platal::load('search', 'search.inc.php');
8c4a0c30 53 if ($no_search) {
54 return;
55 }
56
57 $this->quick = $quick;
58 if ($quick) {
a2aa8436 59 $this->getQuick($join, $where);
8c4a0c30 60 } else {
a2aa8436 61 $this->getAdvanced($join, $where);
8c4a0c30 62 }
63 }
64
a2aa8436 65 private function getQuick($join, $where)
8c4a0c30 66 {
adb07f6f 67 Platal::load('search', 'search.inc.php');
8c4a0c30 68 global $globals;
69 if (!S::logged()) {
70 Env::kill('with_soundex');
71 }
72 $qSearch = new QuickSearch('quick');
73 $fields = new SFieldGroup(true, array($qSearch));
74 if ($qSearch->isEmpty()) {
8d118e58 75 new ThrowError('Aucun critère de recherche n\'est spécifié.');
8c4a0c30 76 }
35fa92e8 77 $this->score = $qSearch->get_score_statement();
3b2f9d11 78 $pwhere = $fields->get_where_statement();
79 if (trim($pwhere)) {
80 if (trim($where)) {
81 $where .= ' AND ';
82 }
83 $where .= $pwhere;
84 }
85 if (S::logged() && Env::has('nonins')) {
86 if (trim($where)) {
87 $where .= ' AND ';
88 }
89 $where .= 'u.perms="pending" AND u.deces=0';
90 }
91 parent::__construct($join . ' ' . $fields->get_select_statement(), $where);
8c4a0c30 92
93 $this->order = implode(',',array_filter(array($fields->get_order_statement(),
94 'u.promo DESC, NomSortKey, prenom')));
95 }
96
63fac48e 97 private function getAdvanced($join, $where)
8c4a0c30 98 {
99 global $globals;
86b5c8f0 100 $this->advanced = true;
8c4a0c30 101 $fields = new SFieldGroup(true, advancedSearchFromInput());
102 if ($fields->too_large()) {
103 new ThrowError('Recherche trop générale.');
104 }
137e819f
FB
105 parent::__construct(@$join . ' ' . $fields->get_select_statement(),
106 @$where . ' ' . $fields->get_where_statement());
8c4a0c30 107 $this->order = implode(',',array_filter(array($fields->get_order_statement(),
108 'promo DESC, NomSortKey, prenom')));
109 }
35fa92e8 110
111 public function &get($fields, $joins, $where, $groupby, $order, $limitcount = null, $limitfrom = null)
112 {
113 if ($this->score) {
114 $fields .= ', ' . $this->score;
115 }
116 return parent::get($fields, $joins, $where, $groupby, $order, $limitcount, $limitfrom);
117 }
8c4a0c30 118}
119
1cc0afe7 120class ArraySet extends UserSet
121{
122 public function __construct(array $users)
123 {
124 $where = $this->getUids($users);
125 if ($where) {
7586ae0b 126 $where = "u.hruid IN ($where)";
1cc0afe7 127 } else {
128 $where = " 0 ";
129 }
130 parent::__construct('', $where);
131 }
132
133 private function getUids(array $users)
134 {
4f25bc90 135 $users = User::getBulkHruid($users, array('User', '_silent_user_callback'));
1cc0afe7 136 if (is_null($users)) {
137 return '';
138 }
139 return '\'' . implode('\', \'', $users) . '\'';
140 }
141}
142
8c4a0c30 143class MinificheView extends MultipageView
144{
145 public function __construct(PlSet &$set, $data, array $params)
146 {
f711b03f 147 require_once 'education.func.inc.php';
8c4a0c30 148 global $globals;
149 $this->entriesPerPage = $globals->search->per_page;
35fa92e8 150 if (@$params['with_score']) {
013dc429 151 $this->addSortKey('score', array('-score', '-date', '-d.promo', 'sort_name'), 'pertinence');
35fa92e8 152 }
dd6fce1e 153 $this->addSortKey('name', array('sort_name'), 'nom');
013dc429
SJ
154 $this->addSortKey('promo', array('-d.promo', 'sort_name'), 'promotion');
155 $this->addSortKey('date_mod', array('-date', '-d.promo', 'sort_name'), 'dernière modification');
8c4a0c30 156 parent::__construct($set, $data, $params);
157 }
158
76cbe885 159 public function bounds()
8c4a0c30 160 {
76cbe885 161 return null;
8c4a0c30 162 }
163
76cbe885 164 public function fields()
b71b2a36 165 {
76cbe885 166 return null;
b71b2a36
SJ
167 }
168
8c4a0c30 169 public function templateName()
170 {
171 return 'include/plview.minifiche.tpl';
172 }
173}
174
ff3eb9b7 175class MentorView extends MultipageView
176{
177 public function __construct(PlSet &$set, $data, array $params)
178 {
eaf30d86 179 $this->entriesPerPage = 10;
ff3eb9b7 180 $this->addSortKey('rand', array('RAND(' . S::i('uid') . ')'), 'aléatoirement');
dd6fce1e 181 $this->addSortKey('name', array('sort_name'), 'nom');
013dc429
SJ
182 $this->addSortKey('promo', array('-d.promo', 'sort_name'), 'promotion');
183 $this->addSortKey('date_mod', array('-date', '-d.promo', 'sort_name'), 'dernière modification');
eaf30d86 184 parent::__construct($set, $data, $params);
ff3eb9b7 185 }
186
187 public function fields()
188 {
d1319488 189 return "m.uid, d.promo, u.hruid,
5fecdf6d 190 m.expertise, mp.country, ms.sectorid, ms.subsectorid,
dd6fce1e 191 d.directory_name, d.sort_name";
cd5bd7dc
PC
192 }
193
194 public function joins()
195 {
dd6fce1e 196 return "INNER JOIN profile_display AS d ON (d.pid = u.user_id)";
ff3eb9b7 197 }
198
b71b2a36
SJ
199 public function bounds()
200 {
201 $order = Env::v('order', $this->defaultkey);
202 $show_bounds = 0;
203 if (($order == "name") || ($order == "-name")) {
204 $this->bound_field = "nom";
205 $show_bounds = 1;
206 } elseif (($order == "promo") || ($order == "-promo")) {
207 $this->bound_field = "promo";
208 $show_bounds = -1;
209 }
210 if ($order{0} == '-') {
211 $show_bounds = -$show_bounds;
212 }
213 return $show_bounds;
214 }
215
ff3eb9b7 216 public function templateName()
217 {
218 return 'include/plview.referent.tpl';
219 }
220}
221
8c4a0c30 222class TrombiView extends MultipageView
223{
224 public function __construct(PlSet &$set, $data, array $params)
225 {
226 $this->entriesPerPage = 24;
dd6fce1e 227 $this->order = explode(',', Env::v('order', 'sort_name'));
35fa92e8 228 if (@$params['with_score']) {
013dc429 229 $this->addSortKey('score', array('-score', '-watch_last', '-d.promo', 'sort_name'), 'pertinence');
35fa92e8 230 }
dd6fce1e 231 $this->addSortKey('name', array('sort_name'), 'nom');
013dc429 232 $this->addSortKey('promo', array('-d.promo', 'sort_name'), 'promotion');
8c4a0c30 233 parent::__construct($set, $data, $params);
234 }
235
236 public function fields()
237 {
dd6fce1e 238 return "u.user_id, d.directory_name, d.sort_name, u.promo, d.promo, u.hruid ";
8c4a0c30 239 }
240
241 public function joins()
242 {
dd6fce1e
SJ
243 return "INNER JOIN photo AS p ON (p.uid = u.user_id)
244 INNER JOIN profile_display AS d ON (d.pid = u.user_id)";
8c4a0c30 245 }
246
b71b2a36
SJ
247 public function bounds()
248 {
249 $order = Env::v('order', $this->defaultkey);
250 $show_bounds = 0;
251 if (($order == "name") || ($order == "-name")) {
252 $this->bound_field = "nom";
253 $show_bounds = 1;
254 } elseif (($order == "promo") || ($order == "-promo")) {
255 $this->bound_field = "promo";
256 $show_bounds = -1;
257 }
258 if ($order{0} == '-') {
259 $show_bounds = -$show_bounds;
260 }
261 return $show_bounds;
262 }
263
8c4a0c30 264 public function templateName()
265 {
266 return 'include/plview.trombi.tpl';
267 }
268
04334c61 269 public function apply(PlPage &$page)
8c4a0c30 270 {
271 if (!empty($GLOBALS['IS_XNET_SITE'])) {
272 global $globals;
273 $page->assign('mainsiteurl', 'https://' . $globals->core->secure_domain . '/');
274 }
275 return parent::apply($page);
276 }
277}
278
92e80560
VZ
279class GadgetView implements PlView
280{
281 public function __construct(PlSet &$set, $data, array $params)
282 {
283 $this->set =& $set;
284 }
285
286 public function fields()
287 {
7773d125 288 return "u.user_id AS id, u.*," .
92e80560
VZ
289 "u.perms != 'pending' AS inscrit,
290 u.perms != 'pending' AS wasinscrit,
291 u.deces != 0 AS dcd, u.deces,
292 FIND_IN_SET('femme', u.flags) AS sexe,
d6eb0554
SJ
293 " // adr.city, gr.name AS region
294 . "gc.iso_3166_1_a2, gc.countryFR AS countrytxt" .
92e80560
VZ
295 (S::logged() ? ", c.contact AS contact" : '');
296 }
297
298 public function joins()
299 {
e4cd7a1f
SJ
300 return "LEFT JOIN profile_addresses AS adr ON (u.user_id = adr.pid AND
301 FIND_IN_SET('current', adr.flags)"
302 . (S::logged() ? "" : "AND adr.pub = 'public'") . ")
303 LEFT JOIN geoloc_countries AS gc ON (adr.countryId = gc.iso_3166_1_a2)
304 LEFT JOIN geoloc_administrativeareas AS gr ON (adr.countryId = gr.country
305 AND adr.administrativeAreaId = gr.id)
306 " . (S::logged() ?
307 "LEFT JOIN contacts AS c ON (c.contact = u.user_id
308 AND c.uid = " . S::v('uid') . ")" : "");
92e80560
VZ
309 }
310
04334c61 311 public function apply(PlPage &$page)
92e80560
VZ
312 {
313 $page->assign_by_ref('set',
314 $this->set->get($this->fields(), $this->joins(), null, null, null, 5, 0));
315 }
316
317 public function args()
318 {
319 return null;
320 }
321}
322
8c4a0c30 323// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
324?>