0eb0033dbd40f58a42fd8d2298ed750ba5e2617e
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)) {
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 GeolocView
implements PlView
285 public function __construct(PlSet
&$set, $data, array $params)
287 $this->params
= $params;
292 private function use_map()
294 return is_file(dirname(__FILE__
) . '/../modules/geoloc/dynamap.swf') &&
295 is_file(dirname(__FILE__
) . '/../modules/geoloc/icon.swf');
298 public function args()
300 $args = $this->set
->args();
301 unset($args['initfile']);
302 unset($args['mapid']);
306 public function apply(PlPage
&$page)
308 require_once 'geoloc.inc.php';
309 require_once '../modules/search/search.inc.php';
311 switch ($this->type
) {
313 header("Content-type: application/x-shockwave-flash");
315 readfile(dirname(__FILE__
).'/../modules/geoloc/icon.swf');
319 header("Content-type: application/x-shockwave-flash");
321 readfile(dirname(__FILE__
).'/../modules/geoloc/dynamap.swf');
325 $page->changeTpl('geoloc/init.tpl', NO_SKIN
);
326 header('Content-Type: text/xml');
328 if (!empty($GLOBALS['IS_XNET_SITE'])) {
329 $page->assign('background', 0xF2E9D0);
334 $page->changeTpl('geoloc/city.tpl', NO_SKIN
);
335 header('Content-Type: text/xml');
337 $only_current = Env
::v('only_current', false
)?
' AND FIND_IN_SET(\'active\', adrf.statut)' : '';
338 $it =& $this->set
->get('u.user_id AS id, u.prenom, u.nom, d.promo, al.alias',
339 "INNER JOIN adresses AS adrf ON (adrf.uid = u.user_id $only_current)
340 INNER JOIN profile_display AS d ON (d.pid = u.user_id)
341 LEFT JOIN aliases AS al ON (u.user_id = al.id
342 AND FIND_IN_SET('bestalias', al.flags))
343 INNER JOIN adresses AS avg ON (" . getadr_join('avg') . ")",
344 'adrf.cityid = ' . Env
::i('cityid'), null
, null
, 11);
345 $page->assign('users', $it);
349 if (Env
::has('debug')) {
350 $page->changeTpl('geoloc/country.tpl', SIMPLE
);
352 $page->changeTpl('geoloc/country.tpl', NO_SKIN
);
353 header('Content-Type: text/xml');
356 $mapid = Env
::has('mapid') ? Env
::i('mapid', -2) : false
;
357 list($countries, $cities) = geoloc_getData_subcountries($mapid, $this->set
, 10);
358 $page->assign('countries', $countries);
359 $page->assign('cities', $cities);
364 if (!$this->use_map()) {
365 $page->assign('request_geodesix', true
);
367 $page->assign('annu', @$this->params
['with_annu']);
368 $page->assign('protocole', @$_SERVER['HTTPS'] ?
'https' : 'http');
369 $this->set
->get('u.user_id', null
, "u.perms != 'pending' AND u.deces = 0", "u.user_id", null
);
370 return 'include/plview.geoloc.tpl';
375 class GadgetView
implements PlView
377 public function __construct(PlSet
&$set, $data, array $params)
382 public function fields()
384 return "u.user_id AS id, u.*," .
385 "u.perms != 'pending' AS inscrit,
386 u.perms != 'pending' AS wasinscrit,
387 u.deces != 0 AS dcd, u.deces,
388 FIND_IN_SET('femme', u.flags) AS sexe,
389 adr.city, gp.a2, gp.pays AS countrytxt, gr.name AS region" .
390 (S
::logged() ?
", c.contact AS contact" : '');
393 public function joins()
395 return "LEFT JOIN adresses AS adr ON (u.user_id = adr.uid AND FIND_IN_SET('active', adr.statut)".(S
::logged() ?
"" : "
396 AND adr.pub = 'public'").")
397 LEFT JOIN geoloc_pays AS gp ON (adr.country = gp.a2)
398 LEFT JOIN geoloc_region AS gr ON (adr.country = gr.a2 AND adr.region = gr.region)" .
400 "LEFT JOIN contacts AS c ON (c.contact = u.user_id AND c.uid = " . S
::v('uid') . ")"
404 public function apply(PlPage
&$page)
406 $page->assign_by_ref('set',
407 $this->set
->get($this->fields(), $this->joins(), null
, null
, null
, 5, 0));
410 public function args()
416 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: