X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=include%2Fnotifs.inc.php;h=f22550fb15aa4c7ad8129469925a4d43a4b36cd9;hb=87d72675e4a6d5e2ca377cde0f30666f6305ad2b;hp=fd952cb6012cab29b0bc296cdcb7317a38e04980;hpb=00ca0ad5370df5be4a0272364fb16a4385ffabfe;p=platal.git 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);