Happy New Year!
[platal.git] / include / reminder / promotion_ml.inc.php
index ffc33b2..62b151a 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /***************************************************************************
- *  Copyright (C) 2003-2010 Polytechnique.org                              *
+ *  Copyright (C) 2003-2014 Polytechnique.org                              *
  *  http://opensource.polytechnique.org/                                   *
  *                                                                         *
  *  This program is free software; you can redistribute it and/or modify   *
@@ -26,16 +26,12 @@ class ReminderPromotionMl extends Reminder
         $user = S::user();
         switch ($action) {
           case 'yes':
-            $res = XDB::query('SELECT  id
-                                 FROM  groups
-                                WHERE  diminutif = {?}',
-                              $user->profile()->yearPromo());
-            $asso_id = $res->fetchOneCell();
-            XDB::execute('REPLACE INTO  group_members (uid, asso_id)
-                                VALUES  ({?}, {?})',
-                         $user->id(), $asso_id);
-            $mmlist = new MMList($user);
-            $mmlist->subscribe('promo' . $user->profile()->yearPromo());
+            XDB::execute('INSERT IGNORE INTO  group_members (uid, asso_id)
+                                      SELECT  {?}, id
+                                        FROM  groups
+                                       WHERE  diminutif = {?}',
+                         $user->id(), $user->profile()->yearPromo());
+            MailingList::subscribePromo($user->profile()->yearPromo());
 
             $this->UpdateOnYes();
             break;
@@ -63,7 +59,7 @@ class ReminderPromotionMl extends Reminder
         return "Inscription à la liste de diffusion de ta promotion";
     }
 
-    public static function IsCandidate(User &$user, $candidate)
+    public static function IsCandidate(User $user, $candidate)
     {
         $profile = $user->profile();
         if (!$profile) {
@@ -82,7 +78,15 @@ class ReminderPromotionMl extends Reminder
         if ($mlCount) {
             Reminder::MarkCandidateAsAccepted($user->id(), $candidate);
         }
-        return ($mlCount == 0);
+        if ($mlCount == 0) {
+            $mlist = MailingList::promo($user->profile()->yearPromo());
+            try {
+                $mlist->getMembersLimit(0, 0);
+            } catch (Exception $e) {
+                return false;
+            }
+        }
+        return false;
     }
 }