From efc272e2fe65652122302d354e223c0576fb2110 Mon Sep 17 00:00:00 2001 From: Vincent Zanotti Date: Sun, 17 May 2009 00:06:49 +0200 Subject: [PATCH] Adds a static method for lazily marking a onebox as accepted directly from the IsCandidate method. This should be used for subscription reminders (eg. the nl reminder: if the user is already subscribed to the newletter, the onebox should be marked as accepted). Signed-off-by: Vincent Zanotti --- include/reminder.inc.php | 26 ++++++++++++++++++++------ include/reminder/email_warning.inc.php | 2 +- include/reminder/no_redirection.inc.php | 2 +- 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/include/reminder.inc.php b/include/reminder.inc.php index 835fab0..5143842 100644 --- a/include/reminder.inc.php +++ b/include/reminder.inc.php @@ -69,27 +69,30 @@ abstract class Reminder // Updates (or creates) the reminder line for the pair (|user|, |reminder_id|) // using the |status| as status, and the |next_ask| as the delay between now // and the next ask (if any). - private function UpdateStatus($status, $next_ask) + private static function UpdateStatus($user_id, $type_id, $status, $next_ask) { XDB::execute('REPLACE INTO reminder SET uid = {?}, type_id = {?}, status = {?}, remind_last = NOW(), remind_next = FROM_UNIXTIME({?})', - $this->user->id(), $this->type_id, $status, + $user_id, $type_id, $status, ($next_ask > 0 ? time() + $next_ask * 24 * 60 * 60 : null)); } // Updates the status of the reminder for the current user. protected function UpdateOnYes() { - $this->UpdateStatus('yes', $this->remind_delay_yes); + $this->UpdateStatus($this->user->id(), $this->type_id, + 'yes', $this->remind_delay_yes); } protected function UpdateOnNo() { - $this->UpdateStatus('no', $this->remind_delay_no); + $this->UpdateStatus($this->user->id(), $this->type_id, + 'no', $this->remind_delay_no); } protected function UpdateOnDismiss() { - $this->UpdateStatus('dismiss', $this->remind_delay_dismiss); + $this->UpdateStatus($this->user->id(), $this->type_id, + 'dismiss', $this->remind_delay_dismiss); } // Display and http handling helpers -------------------------------------- @@ -127,6 +130,17 @@ abstract class Reminder return 'ajax/reminder/' . $this->name; } + // Static status update methods ------------------------------------------- + + // Marks the candidate reminder as having been accepted for user |user_id|. + // It is intended to be used when a reminder box has been bypassed, and when + // it should behave as if the user had clicked on 'yes'. + protected static function MarkCandidateAsAccepted($user_id, $candidate) + { + Reminder::UpdateStatus($user_id, $candidate['type_id'], + 'yes', $candidate['remind_delay_yes']); + } + // Static factories ------------------------------------------------------- // Returns a chosen class using the user data from |user|, and from the database. @@ -146,7 +160,7 @@ abstract class Reminder $position -= $candidate['weight']; if ($position <= 0) { $class = self::GetClassName($candidate['name']); - if ($class && call_user_func(array($class, 'IsCandidate'), $user)) { + if ($class && call_user_func(array($class, 'IsCandidate'), $user, $candidate)) { return new $class($user, $candidate); } unset($candidates[$key]); diff --git a/include/reminder/email_warning.inc.php b/include/reminder/email_warning.inc.php index 4e6689f..f20cdb5 100644 --- a/include/reminder/email_warning.inc.php +++ b/include/reminder/email_warning.inc.php @@ -37,7 +37,7 @@ class ReminderEmailWarning extends Reminder $page->assign('baseurl', $this->GetBaseUrl()); } - public static function IsCandidate(User &$user) + public static function IsCandidate(User &$user, $candidate) { return count(S::v('mx_failures', array())) > 0; } diff --git a/include/reminder/no_redirection.inc.php b/include/reminder/no_redirection.inc.php index 917c651..9555959 100644 --- a/include/reminder/no_redirection.inc.php +++ b/include/reminder/no_redirection.inc.php @@ -37,7 +37,7 @@ class ReminderNoRedirection extends Reminder $page->assign('baseurl', $this->GetBaseUrl()); } - public static function IsCandidate(User &$user) + public static function IsCandidate(User &$user, $candidate) { return S::v('no_redirect'); } -- 2.1.4