2 /***************************************************************************
3 * Copyright (C) 2003-2009 Polytechnique.org *
4 * http://opensource.polytechnique.org/ *
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. *
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. *
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 *
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
20 ***************************************************************************/
22 class UserSet
extends PlSet
26 public function __construct($cond = null
)
28 $this->cond
= new UFC_And();
29 if (!is_null($cond) && ($cond instanceof UserFilterCondition
)) {
30 $this->cond
->addChild($cond);
34 public function &get($fields, $joins, $where, $groupby, $order, $limitcount = null
, $limitfrom = null
)
36 $uf = new UserFilter($this->cond
);
37 $users = $uf->getUsers($limitcount, $limitfrom);
38 $this->count
= $uf->getTotalCount();
43 class SearchSet
extends UserSet
45 public $advanced = false
;
46 private $score = null
;
47 private $order = null
;
48 private $quick = false
;
50 public function __construct($quick = false
, $no_search = false
, $join = '', $where = '')
52 Platal
::load('search', 'search.inc.php');
57 $this->quick
= $quick;
59 $this->getQuick($join, $where);
61 $this->getAdvanced($join, $where);
65 private function getQuick($join, $where)
67 Platal
::load('search', 'search.inc.php');
70 Env
::kill('with_soundex');
72 $qSearch = new QuickSearch('quick');
73 $fields = new SFieldGroup(true
, array($qSearch));
74 if ($qSearch->isEmpty()) {
75 new ThrowError('Aucun critère de recherche n\'est spécifié.');
77 $this->score
= $qSearch->get_score_statement();
78 $pwhere = $fields->get_where_statement();
85 if (S
::logged() && Env
::has('nonins')) {
89 $where .= 'u.perms="pending" AND u.deces=0';
91 parent
::__construct($join . ' ' . $fields->get_select_statement(), $where);
93 $this->order
= implode(',',array_filter(array($fields->get_order_statement(),
94 'u.promo DESC, NomSortKey, prenom')));
97 private function getAdvanced($join, $where)
100 $this->advanced
= true
;
101 $fields = new SFieldGroup(true
, advancedSearchFromInput());
102 if ($fields->too_large()) {
103 new ThrowError('Recherche trop générale.');
105 parent
::__construct(@$join . ' ' . $fields->get_select_statement(),
106 @$where . ' ' . $fields->get_where_statement());
107 $this->order
= implode(',',array_filter(array($fields->get_order_statement(),
108 'promo DESC, NomSortKey, prenom')));
111 public function &get($fields, $joins, $where, $groupby, $order, $limitcount = null
, $limitfrom = null
)
114 $fields .= ', ' . $this->score
;
116 return parent
::get($fields, $joins, $where, $groupby, $order, $limitcount, $limitfrom);
120 class ArraySet
extends UserSet
122 public function __construct(array $users)
124 $where = $this->getUids($users);
126 $where = "u.hruid IN ($where)";
130 parent
::__construct('', $where);
133 private function getUids(array $users)
135 $users = User
::getBulkHruid($users, array('User', '_silent_user_callback'));
136 if (is_null($users)) {
139 return '\'' . implode('\', \'', $users) . '\'';
143 class MinificheView
extends MultipageView
145 public function __construct(PlSet
&$set, $data, array $params)
147 require_once 'education.func.inc.php';
149 $this->entriesPerPage
= $globals->search
->per_page
;
150 if (@$params['with_score']) {
151 $this->addSortKey('score', array('-score', '-date', '-d.promo', 'sort_name'), 'pertinence');
153 $this->addSortKey('name', array('sort_name'), 'nom');
154 $this->addSortKey('promo', array('-d.promo', 'sort_name'), 'promotion');
155 $this->addSortKey('date_mod', array('-date', '-d.promo', 'sort_name'), 'dernière modification');
156 parent
::__construct($set, $data, $params);
159 public function bounds()
164 public function fields()
169 public function templateName()
171 return 'include/plview.minifiche.tpl';
175 class MentorView
extends MultipageView
177 public function __construct(PlSet
&$set, $data, array $params)
179 $this->entriesPerPage
= 10;
180 $this->addSortKey('rand', array('RAND(' . S
::i('uid') . ')'), 'aléatoirement');
181 $this->addSortKey('name', array('sort_name'), 'nom');
182 $this->addSortKey('promo', array('-d.promo', 'sort_name'), 'promotion');
183 $this->addSortKey('date_mod', array('-date', '-d.promo', 'sort_name'), 'dernière modification');
184 parent
::__construct($set, $data, $params);
187 public function fields()
189 return "m.uid, d.promo, u.hruid,
190 m.expertise, mp.country, ms.sectorid, ms.subsectorid,
191 d.directory_name, d.sort_name";
194 public function joins()
196 return "INNER JOIN profile_display AS d ON (d.pid = u.user_id)";
199 public function bounds()
201 $order = Env
::v('order', $this->defaultkey
);
203 if (($order == "name") ||
($order == "-name")) {
204 $this->bound_field
= "nom";
206 } elseif (($order == "promo") ||
($order == "-promo")) {
207 $this->bound_field
= "promo";
210 if ($order{0} == '-') {
211 $show_bounds = -$show_bounds;
216 public function templateName()
218 return 'include/plview.referent.tpl';
222 class TrombiView
extends MultipageView
224 public function __construct(PlSet
&$set, $data, array $params)
226 $this->entriesPerPage
= 24;
227 $this->order
= explode(',', Env
::v('order', 'sort_name'));
228 if (@$params['with_score']) {
229 $this->addSortKey('score', array('-score', '-watch_last', '-d.promo', 'sort_name'), 'pertinence');
231 $this->addSortKey('name', array('sort_name'), 'nom');
232 $this->addSortKey('promo', array('-d.promo', 'sort_name'), 'promotion');
233 parent
::__construct($set, $data, $params);
236 public function fields()
238 return "u.user_id, d.directory_name, d.sort_name, u.promo, d.promo, u.hruid ";
241 public function joins()
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)";
247 public function bounds()
249 $order = Env
::v('order', $this->defaultkey
);
251 if (($order == "name") ||
($order == "-name")) {
252 $this->bound_field
= "nom";
254 } elseif (($order == "promo") ||
($order == "-promo")) {
255 $this->bound_field
= "promo";
258 if ($order{0} == '-') {
259 $show_bounds = -$show_bounds;
264 public function templateName()
266 return 'include/plview.trombi.tpl';
269 public function apply(PlPage
&$page)
271 if (!empty($GLOBALS['IS_XNET_SITE'])) {
273 $page->assign('mainsiteurl', 'https://' . $globals->core
->secure_domain
. '/');
275 return parent
::apply($page);
279 class GadgetView
implements PlView
281 public function __construct(PlSet
&$set, $data, array $params)
286 public function fields()
288 return "u.user_id AS id, u.*," .
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,
293 " // adr.city, gr.name AS region
294 . "gc.iso_3166_1_a2, gc.countryFR AS countrytxt" .
295 (S
::logged() ?
", c.contact AS contact" : '');
298 public function joins()
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)
307 "LEFT JOIN contacts AS c ON (c.contact = u.user_id
308 AND c.uid = " . S
::v('uid') . ")" : "");
311 public function apply(PlPage
&$page)
313 $page->assign_by_ref('set',
314 $this->set
->get($this->fields(), $this->joins(), null
, null
, null
, 5, 0));
317 public function args()
323 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: