Fix syntax errors.
[platal.git] / include / reminder / promotion_ml.inc.php
index aee6747..a49e4e7 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /***************************************************************************
- *  Copyright (C) 2003-2009 Polytechnique.org                              *
+ *  Copyright (C) 2003-2010 Polytechnique.org                              *
  *  http://opensource.polytechnique.org/                                   *
  *                                                                         *
  *  This program is free software; you can redistribute it and/or modify   *
@@ -23,18 +23,16 @@ class ReminderPromotionMl extends Reminder
 {
     public function HandleAction($action)
     {
+        $user = S::user();
         switch ($action) {
           case 'yes':
-            $res = XDB::query('SELECT  id
-                               FROM  groupex.asso
-                              WHERE  diminutif = {?}',
-                            S::v('promo'));
-            $asso_id = $res->fetchOneCell();
-            XDB::execute('REPLACE INTO  groupex.membres (uid, asso_id)
-                                VALUES  ({?}, {?})',
-                         S::v('uid'), $asso_id);
-            $mmlist = new MMList(S::v('uid'), S::v('password'));
-            $mmlist->subscribe('promo' . S::v('promo'));
+            XDB::execute('INSERT IGNORE INTO  group_members (uid, asso_id)
+                                      SELECT  {?}, id
+                                        FROM  groups
+                                       WHERE  diminutif = {?}',
+                         $user->id(), $user->profile()->yearPromo());
+            $mmlist = new MMList($user);
+            $mmlist->subscribe('promo' . $user->profile()->yearPromo());
 
             $this->UpdateOnYes();
             break;
@@ -49,31 +47,39 @@ class ReminderPromotionMl extends Reminder
         }
     }
 
-    protected function GetDisplayText()
+    public function text()
     {
         return "La liste de diffusion de ta promotion permet de recevoir les
             informations plus spécifiques de ta promotion pour pouvoir
             participer plus facilement aux événements qu'elle organise. Tu
             seras aussi inscrit dans le groupe de la promotion " .
-            S::user()->promo() . '.';
+            $this->user->promo() . '.';
+    }
+    public function title()
+    {
+        return "Inscription à la liste de diffusion de ta promotion";
     }
 
     public static function IsCandidate(User &$user, $candidate)
     {
+        $profile = $user->profile();
+        if (!$profile) {
+            return false;
+        }
+
         // We only test if the user is in her promotion group for it is too
         // expensive to check if she is in the corresponding ML as well.
         $res = XDB::query('SELECT  COUNT(*)
-                             FROM  groupex.membres
+                             FROM  group_members
                             WHERE  uid = {?} AND asso_id = (SELECT  id
-                                                              FROM  groupex.asso
+                                                              FROM  groups
                                                              WHERE  diminutif = {?})',
-                          $user->id(), S::v('promo'));
-
+                          $user->id(), $user->profile()->yearPromo());
         $mlCount = $res->fetchOneCell();
         if ($mlCount) {
             Reminder::MarkCandidateAsAccepted($user->id(), $candidate);
         }
-        return ($mlCount > 0);
+        return ($mlCount == 0);
     }
 }