X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=include%2Freminder%2Fpromotion_ml.inc.php;h=c311e13ade6c63b53edf9ed5e6a7e9f22f9ac398;hb=b0b1718db4bbbfd3474f3fbc5c83e6a51862e266;hp=b67b59b6a3dd1633733a3d2488b6b16a5248c461;hpb=d1e6167749fdad08c81e23d09e1bbbf76e3b989b;p=platal.git diff --git a/include/reminder/promotion_ml.inc.php b/include/reminder/promotion_ml.inc.php index b67b59b..c311e13 100644 --- a/include/reminder/promotion_ml.inc.php +++ b/include/reminder/promotion_ml.inc.php @@ -1,6 +1,6 @@ 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; @@ -62,22 +60,35 @@ 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) { + 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); + if ($mlCount == 0) { + $mmlist = new MMList($user); + try { + $mmlist->get_members_limit('promo' + $user->profile()->yearPromo(), + 0, 0); + } catch (Exception $e) { + return false; + } + } + return false; } }