X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=include%2Fnotifs.inc.php;h=f22550fb15aa4c7ad8129469925a4d43a4b36cd9;hb=87d72675e4a6d5e2ca377cde0f30666f6305ad2b;hp=a9946ae63d7e03c0012ad4afc474bd7ff0be146d;hpb=9b80d0730d8ec0ac77c0def648fc1da4a18cffc9;p=platal.git diff --git a/include/notifs.inc.php b/include/notifs.inc.php index a9946ae..f22550f 100644 --- a/include/notifs.inc.php +++ b/include/notifs.inc.php @@ -1,6 +1,6 @@ date = $date; - if (!$user->watch($this->flag)) { + if (!$user->watchType($this->flag)) { return new PFC_False(); } else { return $this->buildCondition($user); @@ -69,7 +69,7 @@ class WatchProfileUpdate extends WatchOperation public static function register(Profile &$profile, $field) { - XDB::execute('REPLACE INTO watch_profile (uid, ts, field) + XDB::execute('REPLACE INTO watch_profile (pid, ts, field) VALUES ({?}, NOW(), {?})', $profile->id(), $field); } @@ -109,11 +109,11 @@ class WatchProfileUpdate extends WatchOperation 'photo' => 'Sa photographie'); public function getData(PlUser &$user) { - $data = XDB::fetchColumn('SELECT field + $data = XDB::fetchColumn("SELECT field FROM watch_profile - WHERE uid = {?} AND ts > FROM_UNIXTIME({?}) AND field != \'\' - ORDER BY ts', - $user->id(), $this->date); + WHERE pid = {?} AND ts > FROM_UNIXTIME({?}) AND field != '' + ORDER BY ts", + $user->profile()->id(), $this->date); if (count($data) == 0) { return null; } else { @@ -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); } @@ -252,12 +268,13 @@ class Watch { $obj = new $class(); $uf = new UserFilter($obj->getCondition($user, $date), - array($obj->getOrder(), new UFO_Name(UserFilter::DN_SORT))); + array($obj->getOrder(), new UFO_Name(Profile::DN_SORT))); $users = $uf->getUsers(); if (count($users) == 0) { return null; } else { - return array('operation' => $obj, + return array('type' => $obj->flag, + 'operation' => $obj, 'title' => $obj->getTitle(count($users)), 'users' => $users); } @@ -265,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);