2 /***************************************************************************
3 * Copyright (C) 2003-2011 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 /** This module handles the "N N-10" operation, locally named "Delta10".
24 class DeltaTenModule
extends PLModule
29 'deltaten/search' => $this->make_hook('index', AUTH_COOKIE
, 'user'),
30 'deltaten' => $this->make_hook('index', AUTH_COOKIE
, 'user'),
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".
37 protected function isDeltaTenEnabled(User
$user, $role)
39 if (!$user->hasProfile()) {
42 return $user->profile()->isDeltaTenEnabled($role);
45 function handler_index($page, $action='', $subaction='')
48 if (!$this->isDeltaTenEnabled(S
::user(), Profile
::DELTATEN_YOUNG
)) {
49 $page->killError("Ta promotion ne participe pas à l'opération N N-10.");
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.");
57 $page->trigWarning("Tu ne participes pas encore à l'opération N N-10 en tant qu'ancien.");
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');
65 require_once 'ufbuilder.inc.php';
66 $ufb = new UFB_DeltaTenSearch();
67 $page->addJsLink('search.js');
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);
74 $ufc->addChild(new UFC_DeltaTen());
75 $ufc->addChild(new UFC_Promo('=', UserFilter
::GRADE_ING
, S
::user()->profile()->yearpromo() - 10));
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.");
90 $page->changeTpl('deltaten/index.tpl');
95 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: