Commit | Line | Data |
---|---|---|
cccf3cc0 SJ |
1 | <?php |
2 | /*************************************************************************** | |
ba6ae046 | 3 | * Copyright (C) 2003-2013 Polytechnique.org * |
cccf3cc0 SJ |
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 | { | |
5fb8451c | 26 | $user = S::user(); |
cccf3cc0 SJ |
27 | switch ($action) { |
28 | case 'yes': | |
00ba8a74 SJ |
29 | XDB::execute('INSERT IGNORE INTO group_members (uid, asso_id) |
30 | SELECT {?}, id | |
31 | FROM groups | |
61acb758 | 32 | WHERE diminutif = {?}', |
00ba8a74 | 33 | $user->id(), $user->profile()->yearPromo()); |
f04660bf | 34 | MailingList::subscribePromo($user->profile()->yearPromo()); |
cccf3cc0 SJ |
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 | ||
4b0cb388 | 49 | public function text() |
cccf3cc0 SJ |
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 " . | |
4b0cb388 VZ |
55 | $this->user->promo() . '.'; |
56 | } | |
57 | public function title() | |
58 | { | |
59 | return "Inscription à la liste de diffusion de ta promotion"; | |
cccf3cc0 SJ |
60 | } |
61 | ||
26ba053e | 62 | public static function IsCandidate(User $user, $candidate) |
cccf3cc0 | 63 | { |
1f64f1a7 FB |
64 | $profile = $user->profile(); |
65 | if (!$profile) { | |
66 | return false; | |
67 | } | |
68 | ||
cccf3cc0 SJ |
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(*) | |
eb41eda9 | 72 | FROM group_members |
cccf3cc0 | 73 | WHERE uid = {?} AND asso_id = (SELECT id |
eb41eda9 | 74 | FROM groups |
cccf3cc0 | 75 | WHERE diminutif = {?})', |
5fb8451c | 76 | $user->id(), $user->profile()->yearPromo()); |
700b1cf1 SJ |
77 | $mlCount = $res->fetchOneCell(); |
78 | if ($mlCount) { | |
79 | Reminder::MarkCandidateAsAccepted($user->id(), $candidate); | |
80 | } | |
50f5e460 | 81 | if ($mlCount == 0) { |
22c5024f | 82 | $mlist = MailingList::promo($user->profile()->yearPromo()); |
50f5e460 | 83 | try { |
92ac93ec | 84 | $mlist->getMembersLimit(0, 0); |
50f5e460 FB |
85 | } catch (Exception $e) { |
86 | return false; | |
87 | } | |
88 | } | |
89 | return false; | |
cccf3cc0 SJ |
90 | } |
91 | } | |
92 | ||
93 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: | |
94 | ?> |