Merge branch 'xorg/maint'
[platal.git] / include / reminder / promotion_ml.inc.php
1 <?php
2 /***************************************************************************
3 * Copyright (C) 2003-2014 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 $user = S::user();
27 switch ($action) {
28 case 'yes':
29 XDB::execute('INSERT IGNORE INTO group_members (uid, asso_id)
30 SELECT {?}, id
31 FROM groups
32 WHERE diminutif = {?}',
33 $user->id(), $user->profile()->yearPromo());
34 MailingList::subscribePromo($user->profile()->yearPromo());
35
36 $this->UpdateOnYes();
37 break;
38
39 case 'dismiss':
40 $this->UpdateOnDismiss();
41 break;
42
43 case 'no':
44 $this->UpdateOnNo();
45 break;
46 }
47 }
48
49 public function text()
50 {
51 return "La liste de diffusion de ta promotion permet de recevoir les
52 informations plus spécifiques de ta promotion pour pouvoir
53 participer plus facilement aux événements qu'elle organise. Tu
54 seras aussi inscrit dans le groupe de la promotion " .
55 $this->user->promo() . '.';
56 }
57 public function title()
58 {
59 return "Inscription à la liste de diffusion de ta promotion";
60 }
61
62 public static function IsCandidate(User $user, $candidate)
63 {
64 $profile = $user->profile();
65 if (!$profile) {
66 return false;
67 }
68
69 // We only test if the user is in her promotion group for it is too
70 // expensive to check if she is in the corresponding ML as well.
71 $res = XDB::query('SELECT COUNT(*)
72 FROM group_members
73 WHERE uid = {?} AND asso_id = (SELECT id
74 FROM groups
75 WHERE diminutif = {?})',
76 $user->id(), $user->profile()->yearPromo());
77 $mlCount = $res->fetchOneCell();
78 if ($mlCount) {
79 Reminder::MarkCandidateAsAccepted($user->id(), $candidate);
80 }
81 if ($mlCount == 0) {
82 $mlist = MailingList::promo($user->profile()->yearPromo());
83 try {
84 $mlist->getMembersLimit(0, 0);
85 } catch (Exception $e) {
86 return false;
87 }
88 }
89 return false;
90 }
91 }
92
93 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker fenc=utf-8:
94 ?>