X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=include%2Freminder.inc.php;h=aabd98971dc1ef4e759174c456fa04e4b87e3b0c;hb=3da338db27ff7e09b46cad976342aeb133a60aad;hp=a28d8393f0b3b845184b5d586ec2e5106ba1cb05;hpb=c3c43c0ebe734e2b43b5d5fdb6010d08358bc34b;p=platal.git diff --git a/include/reminder.inc.php b/include/reminder.inc.php index a28d839..aabd989 100644 --- a/include/reminder.inc.php +++ b/include/reminder.inc.php @@ -1,6 +1,6 @@ user = &$user; @@ -69,12 +69,12 @@ 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 static function UpdateStatus($user_id, $type_id, $status, $next_ask) + private static function UpdateStatus($uid, $type_id, $status, $next_ask) { - XDB::execute('REPLACE INTO reminder - SET uid = {?}, type_id = {?}, status = {?}, - remind_last = NOW(), remind_next = FROM_UNIXTIME({?})', - $user_id, $type_id, $status, + XDB::execute('INSERT INTO reminder (uid, type_id, status, remind_last, remind_next) + VALUES ({?}, {?}, {?}, NOW(), FROM_UNIXTIME({?})) + ON DUPLICATE KEY UPDATE status = VALUES(status), remind_last = VALUES(remind_last), remind_next = VALUES(remind_next)', + $uid, $type_id, $status, ($next_ask > 0 ? time() + $next_ask * 24 * 60 * 60 : null)); } @@ -101,17 +101,29 @@ abstract class Reminder // method below). abstract public function HandleAction($action); + // Displays a reduced version of the reminder and notifies that the action + // has been taken into account. + public function NotifiesAction($page) + { + pl_content_headers("text/html"); + $page->changeTpl('reminder/notification.tpl', NO_SKIN); + $page->assign('previous_reminder', $this->title()); + } + // Displays the reminder as a standalone html snippet. It should be used // when the reminder is the only output of a page. - public function DisplayStandalone(&$page) + public function DisplayStandalone($page, $previous_reminder = null) { - header('Content-Type: text/html; charset=utf-8'); + pl_content_headers("text/html"); $page->changeTpl('reminder/base.tpl', NO_SKIN); $this->Prepare($page); + if ($previous_reminder) { + $page->assign('previous_reminder', $previous_reminder); + } } // Prepares the display by assigning template variables. - public function Prepare(&$page) + public function Prepare($page) { $page->assign_by_ref('reminder', $this); } @@ -136,21 +148,24 @@ abstract class Reminder return 'ajax/reminder/' . $this->name; } + // Returns the url for the information page. + public function info() { return ''; } + // Static status update methods ------------------------------------------- - // Marks the candidate reminder as having been accepted for user |user_id|. + // Marks the candidate reminder as having been accepted for user |uid|. // 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) + protected static function MarkCandidateAsAccepted($uid, $candidate) { - Reminder::UpdateStatus($user_id, $candidate['type_id'], + Reminder::UpdateStatus($uid, $candidate['type_id'], 'yes', $candidate['remind_delay_yes']); } // Static factories ------------------------------------------------------- // Returns a chosen class using the user data from |user|, and from the database. - public static function GetCandidateReminder(User &$user) + public static function GetCandidateReminder(User $user) { $res = XDB::query('SELECT rt.*, r.status, r.remind_last FROM reminder_type AS rt @@ -179,7 +194,7 @@ abstract class Reminder // Returns an instantiation of the reminder class which name is |name|, using // user data from |user|, and from the database. - public static function GetByName(User &$user, $name) + public static function GetByName(User $user, $name) { if (!($class = self::GetClassName($name))) { return null; @@ -208,5 +223,5 @@ abstract class Reminder } -// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: +// vim:set et sw=4 sts=4 sws=4 foldmethod=marker fenc=utf-8: ?>