Commit | Line | Data |
---|---|---|
080632c7 RB |
1 | <?php |
2 | /*************************************************************************** | |
3 | * Copyright (C) 2003-2011 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 | ||
22 | /** This module handles the "N N-10" operation, locally named "Delta10". | |
23 | */ | |
24 | class DeltaTenModule extends PLModule | |
25 | { | |
26 | function handlers() | |
27 | { | |
28 | return array( | |
e5ceaa8c RB |
29 | 'deltaten/search' => $this->make_hook('index', AUTH_COOKIE, 'user'), |
30 | 'deltaten' => $this->make_hook('index', AUTH_COOKIE, 'user'), | |
080632c7 RB |
31 | ); |
32 | } | |
33 | ||
34 | /** Check whether a given user is in a "DeltaTen" promo. | |
35 | * This is based on "has a profile, is an X, and is in a young enough promo". | |
36 | */ | |
37 | protected function isDeltaTenEnabled(User $user, $role) | |
38 | { | |
39 | if (!$user->hasProfile()) { | |
40 | return false; | |
41 | } | |
42 | return $user->profile()->isDeltaTenEnabled($role); | |
43 | } | |
44 | ||
45 | function handler_index($page, $action='', $subaction='') | |
46 | { | |
47 | global $globals; | |
48 | if (!$this->isDeltaTenEnabled(S::user(), Profile::DELTATEN_YOUNG)) { | |
49 | $page->killError("Ta promotion ne participe pas à l'opération N N-10."); | |
50 | } | |
51 | ||
52 | if ($this->isDeltaTenEnabled(S::user(), Profile::DELTATEN_OLD)) { | |
53 | $profile = S::user()->profile(); | |
54 | if ($profile->getDeltatenMessage()) { | |
55 | $page->trigSuccess("Tu participes bien à l'opération N N-10 en tant qu'ancien."); | |
56 | } else { | |
57 | $page->trigWarning("Tu ne participes pas encore à l'opération N N-10 en tant qu'ancien."); | |
58 | } | |
59 | } | |
60 | $page->setTitle("Opération N N-10"); | |
61 | $page->assign('deltaten_promo_old', S::user()->profile()->yearpromo() - 10); | |
62 | $wp = new PlWikiPage('Docs.Deltaten'); | |
63 | $wp->buildCache(); | |
64 | ||
65 | require_once 'ufbuilder.inc.php'; | |
66 | $ufb = new UFB_DeltaTenSearch(); | |
222195aa | 67 | $page->addJsLink('search.js'); |
080632c7 RB |
68 | if (!$ufb->isEmpty()) { |
69 | require_once 'userset.inc.php'; | |
70 | $ufc = $ufb->getUFC(); | |
71 | if (!$ufc instanceof PFC_And) { | |
72 | $ufc = new PFC_And($ufc); | |
73 | } | |
74 | $ufc->addChild(new UFC_DeltaTen()); | |
75 | $ufc->addChild(new UFC_Promo('=', UserFilter::GRADE_ING, S::user()->profile()->yearpromo() - 10)); | |
76 | ||
77 | $set = new ProfileSet($ufc); | |
78 | $set->addMod('minifiche', 'Opération N N-10'); | |
79 | $set->apply('deltaten/search', $page, $action, $subaction); | |
80 | $nb_tot = $set->count(); | |
81 | if ($nb_tot > $globals->search->private_max) { | |
82 | $page->assign('formulaire', 1); | |
83 | $page->trigError('Recherche trop générale.'); | |
84 | $page->assign('plset_count', 0); | |
85 | } else if ($nb_tot == 0) { | |
86 | $page->assign('formulaire', 1); | |
87 | $page->trigError("Il n'existe personne correspondant à ces critères dans la base."); | |
88 | } | |
89 | } | |
90 | $page->changeTpl('deltaten/index.tpl'); | |
91 | } | |
92 | } | |
93 | ||
94 | ||
95 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: | |
96 | ?> |