From: Florent Bruneau Date: Sun, 30 May 2010 07:14:40 +0000 (+0200) Subject: Several fixes in carnet notification selection. X-Git-Tag: xorg/1.0.0~226 X-Git-Url: http://git.polytechnique.org/?a=commitdiff_plain;h=e7ffcfd4e56316c1b22db06dc64a5ade6bec8f8a;p=platal.git Several fixes in carnet notification selection. -> show birthday notification only from (promo - 1) to (promo + 1) -> fix watch_last update not taken into account after marking notifications has viewed. -> count of unread notifications limited to the last week (same limitation as the content carnet/panel) - (Closes #1055). Signed-off-by: Florent Bruneau --- diff --git a/classes/xorgsession.php b/classes/xorgsession.php index 011b6b5..4bb2d16 100644 --- a/classes/xorgsession.php +++ b/classes/xorgsession.php @@ -312,7 +312,11 @@ class XorgSession extends PlSession { require_once 'notifs.inc.php'; $user = S::user(); - $n = Watch::getCount($user); + $date = null; + if (S::has('watch_last')) { + $date = S::i('watch_last'); + } + $n = Watch::getCount($user, $date); S::set('notifs', $n); } diff --git a/include/notifs.inc.php b/include/notifs.inc.php index fd952cb..f22550f 100644 --- a/include/notifs.inc.php +++ b/include/notifs.inc.php @@ -191,11 +191,17 @@ class WatchBirthday extends WatchOperation protected function buildCondition(PlUser &$user) { - return new PFC_And(new PFC_OR(new UFC_Birthday('=', time()), - new PFC_And(new UFC_Birthday('<=', time() + self::WATCH_LIMIT), - new UFC_Birthday('>', $this->date + self::WATCH_LIMIT))), - new PFC_Or(new UFC_WatchPromo($user), - new UFC_WatchContact($user))); + $select_date = new PFC_OR(new UFC_Birthday('=', time()), + new PFC_And(new UFC_Birthday('<=', time() + self::WATCH_LIMIT), + new UFC_Birthday('>', $this->date + self::WATCH_LIMIT))); + $profile = $user->profile(); + $cond = new UFC_WatchContact($user); + if ($profile) { + $cond = new PFC_Or(new PFC_And(new UFC_WatchPromo($user), + new UFC_Promo('>=', $profile->mainGrade(), $profile->yearpromo() - 1), + new UFC_Promo('<=', $profile->mainGrade(), $profile->yearpromo() + 1))); + } + return new PFC_And($select_date, $cond); } public function getOrder() @@ -228,6 +234,18 @@ class Watch 'WatchDeath', 'WatchBirthday'); + private static function getDate(PlUser &$user, $date) + { + if (is_null($date)) { + $date = $user->watchLast(); + $limit = time() - (7 * 86400); + if ($date < $limit) { + $date = $limit; + } + } + return $date; + } + private static function fetchCount(PlUser &$user, $date, $class) { $obj = new $class(); @@ -238,9 +256,7 @@ class Watch public static function getCount(PlUser &$user, $date = null) { $count = 0; - if (is_null($date)) { - $date = $user->watchLast(); - } + $date = self::getDate($user, $date); foreach (self::$classes as $class) { $count += self::fetchCount($user, $date, $class); } @@ -266,9 +282,7 @@ class Watch public static function getEvents(PlUser &$user, $date = null) { - if (is_null($date)) { - $date = $user->watchLast(); - } + $date = self::getDate($user, $date); $events = array(); foreach (self::$classes as $class) { $e = self::fetchEvents($user, $date, $class);