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 group_members WHERE uid = {?} AND asso_id = (SELECT id FROM groups WHERE diminutif = {?})', $user->id(), $user->profile()->yearPromo()); $mlCount = $res->fetchOneCell(); if ($mlCount) { Reminder::MarkCandidateAsAccepted($user->id(), $candidate); } if ($mlCount == 0) { $mlist = MailingList::promo($user->profile()->yearPromo()); try { $mlist->getMembersLimit(0, 0); } catch (Exception $e) { return false; } } return false; }
function handler_lists($page) { function filter_owner($list) { return $list['own']; } function filter_member($list) { return $list['sub']; } $page->changeTpl('lists/index.tpl'); $page->setTitle('Listes de diffusion'); if (Get::has('del')) { S::assert_xsrf_token(); $mlist = $this->prepare_list(Get::v('del')); $mlist->unsubscribe(); pl_redirect('lists'); } if (Get::has('add')) { S::assert_xsrf_token(); $mlist = $this->prepare_list(Get::v('add')); $mlist->subscribe(); pl_redirect('lists'); } if (Post::has('promo_add')) { S::assert_xsrf_token(); $promo = Post::i('promo_add'); if ($promo >= 1900 and $promo < 2100) { $mlist = MailingList::promo($promo); $mlist->subscribe(); } else { $page->trigError("promo incorrecte, il faut une promo sur 4 chiffres."); } } $client = $this->prepare_client(); if (!is_null($listes = $client->get_lists())) { $owner = array_filter($listes, 'filter_owner'); $listes = array_diff_key($listes, $owner); $member = array_filter($listes, 'filter_member'); $listes = array_diff_key($listes, $member); foreach ($owner as $key => $liste) { $mlist = $this->prepare_list($liste['list']); list($subs, $mails) = $this->get_pending_ops($mlist); $owner[$key]['subscriptions'] = $subs; $owner[$key]['mails'] = $mails; } $page->register_modifier('hdc', 'list_header_decode'); $page->assign_by_ref('owner', $owner); $page->assign_by_ref('member', $member); $page->assign_by_ref('public', $listes); } }
public static function subscribePromo($promo, $user = null) { $mlist = MailingList::promo($promo, $user); return $mlist->subscribe(); }