Merge commit 'origin/master' into fusionax
[platal.git] / include / reminder / promotion_ml.inc.php
1 <?php
2 /***************************************************************************
3 * Copyright (C) 2003-2009 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 class ReminderPromotionMl extends Reminder
23 {
24 public function HandleAction($action)
25 {
26 switch ($action) {
27 case 'yes':
28 $res = XDB::query('SELECT id
29 FROM groupex.asso
30 WHERE diminutif = {?}',
31 S::v('promo'));
32 $asso_id = $res->fetchOneCell();
33 XDB::execute('REPLACE INTO groupex.membres (uid, asso_id)
34 VALUES ({?}, {?})',
35 S::v('uid'), $asso_id);
36 $mmlist = new MMList(S::v('uid'), S::v('password'));
37 $mmlist->subscribe('promo' . S::v('promo'));
38
39 $this->UpdateOnYes();
40 break;
41
42 case 'dismiss':
43 $this->UpdateOnDismiss();
44 break;
45
46 case 'no':
47 $this->UpdateOnNo();
48 break;
49 }
50 }
51
52 public function text()
53 {
54 return "La liste de diffusion de ta promotion permet de recevoir les
55 informations plus spécifiques de ta promotion pour pouvoir
56 participer plus facilement aux événements qu'elle organise. Tu
57 seras aussi inscrit dans le groupe de la promotion " .
58 $this->user->promo() . '.';
59 }
60 public function title()
61 {
62 return "Inscription à la liste de diffusion de ta promotion";
63 }
64
65 public static function IsCandidate(User &$user, $candidate)
66 {
67 // We only test if the user is in her promotion group for it is too
68 // expensive to check if she is in the corresponding ML as well.
69 $res = XDB::query('SELECT COUNT(*)
70 FROM groupex.membres
71 WHERE uid = {?} AND asso_id = (SELECT id
72 FROM groupex.asso
73 WHERE diminutif = {?})',
74 $user->id(), S::v('promo'));
75
76 $mlCount = $res->fetchOneCell();
77 if ($mlCount) {
78 Reminder::MarkCandidateAsAccepted($user->id(), $candidate);
79 }
80 return ($mlCount == 0);
81 }
82 }
83
84 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
85 ?>