Adds a static method for lazily marking a onebox as accepted directly from the IsCand...
authorVincent Zanotti <vincent.zanotti@m4x.org>
Sat, 16 May 2009 22:06:49 +0000 (00:06 +0200)
committerVincent Zanotti <vincent.zanotti@m4x.org>
Sat, 16 May 2009 22:12:41 +0000 (00:12 +0200)
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 <vincent.zanotti@m4x.org>
include/reminder.inc.php
include/reminder/email_warning.inc.php
include/reminder/no_redirection.inc.php

index 835fab0..5143842 100644 (file)
@@ -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]);
index 4e6689f..f20cdb5 100644 (file)
@@ -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;
     }
index 917c651..9555959 100644 (file)
@@ -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');
     }