Commit | Line | Data |
---|---|---|
cccf3cc0 SJ |
1 | <?php |
2 | /*************************************************************************** | |
12262f13 | 3 | * Copyright (C) 2003-2011 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()); |
5fb8451c FB |
34 | $mmlist = new MMList($user); |
35 | $mmlist->subscribe('promo' . $user->profile()->yearPromo()); | |
cccf3cc0 SJ |
36 | |
37 | $this->UpdateOnYes(); | |
38 | break; | |
39 | ||
40 | case 'dismiss': | |
41 | $this->UpdateOnDismiss(); | |
42 | break; | |
43 | ||
44 | case 'no': | |
45 | $this->UpdateOnNo(); | |
46 | break; | |
47 | } | |
48 | } | |
49 | ||
4b0cb388 | 50 | public function text() |
cccf3cc0 SJ |
51 | { |
52 | return "La liste de diffusion de ta promotion permet de recevoir les | |
53 | informations plus spécifiques de ta promotion pour pouvoir | |
54 | participer plus facilement aux événements qu'elle organise. Tu | |
55 | seras aussi inscrit dans le groupe de la promotion " . | |
4b0cb388 VZ |
56 | $this->user->promo() . '.'; |
57 | } | |
58 | public function title() | |
59 | { | |
60 | return "Inscription à la liste de diffusion de ta promotion"; | |
cccf3cc0 SJ |
61 | } |
62 | ||
26ba053e | 63 | public static function IsCandidate(User $user, $candidate) |
cccf3cc0 | 64 | { |
1f64f1a7 FB |
65 | $profile = $user->profile(); |
66 | if (!$profile) { | |
67 | return false; | |
68 | } | |
69 | ||
cccf3cc0 SJ |
70 | // We only test if the user is in her promotion group for it is too |
71 | // expensive to check if she is in the corresponding ML as well. | |
72 | $res = XDB::query('SELECT COUNT(*) | |
eb41eda9 | 73 | FROM group_members |
cccf3cc0 | 74 | WHERE uid = {?} AND asso_id = (SELECT id |
eb41eda9 | 75 | FROM groups |
cccf3cc0 | 76 | WHERE diminutif = {?})', |
5fb8451c | 77 | $user->id(), $user->profile()->yearPromo()); |
700b1cf1 SJ |
78 | $mlCount = $res->fetchOneCell(); |
79 | if ($mlCount) { | |
80 | Reminder::MarkCandidateAsAccepted($user->id(), $candidate); | |
81 | } | |
50f5e460 FB |
82 | if ($mlCount == 0) { |
83 | $mmlist = new MMList($user); | |
84 | try { | |
85 | $mmlist->get_members_limit('promo' + $user->profile()->yearPromo(), | |
86 | 0, 0); | |
87 | } catch (Exception $e) { | |
88 | return false; | |
89 | } | |
90 | } | |
91 | return false; | |
cccf3cc0 SJ |
92 | } |
93 | } | |
94 | ||
95 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: | |
96 | ?> |