X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=include%2Fnotifs.inc.php;h=19a64809f0a5c88576afbae4ed59207ded49c91d;hb=3424387cde6c635ff16c3b5459c4caa88bb76e2e;hp=fd952cb6012cab29b0bc296cdcb7317a38e04980;hpb=93d42b4fcc6f055a428c9b63e386ac62c918d08a;p=platal.git diff --git a/include/notifs.inc.php b/include/notifs.inc.php index fd952cb..19a6480 100644 --- a/include/notifs.inc.php +++ b/include/notifs.inc.php @@ -1,6 +1,6 @@ date = $date; - if (!$user->watchType($this->flag)) { - return new PFC_False(); + if (!$watch->user()->watchType($this->flag)) { + if (!self::$false) { + self::$false = new PFC_False(); + } + return self::$false; } else { - return $this->buildCondition($user); + return $this->buildCondition($watch); } } - abstract protected function buildCondition(PlUser &$user); + abstract protected function buildCondition(Watch $watch); abstract public function getOrder(); - abstract public function getDate(PlUser &$user); + abstract public function getDate(PlUser $user); - public function publicationDate(PlUser &$user) + public function publicationDate(PlUser $user) { return $this->getDate($user); } - public function seen(PlUser &$user, $last) + public function seen(PlUser $user, $last) { return strtotime($this->getDate($user)) > $last; } - public function getData(PlUser &$user) + public function getData(PlUser $user) { return null; } @@ -64,50 +66,41 @@ abstract class WatchOperation class WatchProfileUpdate extends WatchOperation { + private static $order = null; + public $flag = 'profile'; public $title = 'Mise$s à jour de fiche'; + private $date = null; - public static function register(Profile &$profile, $field) + public static function register(Profile $profile, $field) { - XDB::execute('REPLACE INTO watch_profile (pid, ts, field) - VALUES ({?}, NOW(), {?})', + XDB::execute('INSERT INTO watch_profile (pid, ts, field) + VALUES ({?}, NOW(), {?}) + ON DUPLICATE KEY UPDATE ts = NOW()', $profile->id(), $field); } - protected function buildCondition(PlUser &$user) + protected function buildCondition(Watch $watch) { - return new PFC_And(new UFC_ProfileUpdated('>', $this->date), - new UFC_WatchContact($user)); + $this->date = $watch->date(); + return new PFC_And(new UFC_ProfileUpdated('>', $watch->date()), + $watch->contactCondition()); } public function getOrder() { - return new UFO_ProfileUpdate(); + if (!self::$order) { + self::$order = new UFO_ProfileUpdate(); + } + return self::$order; } - public function getDate(PlUser &$user) + public function getDate(PlUser $user) { return $user->profile()->last_change; } - static private $descriptions = array('search_names' => 'L\'un de ses noms', - 'freetext' => 'Le texte libre', - 'mobile' => 'Son numéro de téléphone portable', - 'nationalite' => 'Sa nationalité', - 'nationalite2' => 'Sa seconde nationalité', - 'nationalite3' => 'Sa troisième nationalité', - 'nick' => 'Son surnom', - 'networking' => 'La liste de ses adresses de networking', - 'edus' => 'Ses formations', - 'addresses' => 'Ses adresses', - 'section' => 'Sa section sportive', - 'binets' => 'La liste de ses binets', - 'medals' => 'Ses décorations', - 'cv' => 'Son Curriculum Vitae', - 'corps' => 'Son Corps d\'État', - 'jobs' => 'Ses informations professionnelles', - 'photo' => 'Sa photographie'); - public function getData(PlUser &$user) + public function getData(PlUser $user) { $data = XDB::fetchColumn("SELECT field FROM watch_profile @@ -119,7 +112,7 @@ class WatchProfileUpdate extends WatchOperation } else { $text = array(); foreach ($data as $f) { - $text[] = self::$descriptions[$f]; + $text[] = Profile::$descriptions[$f]; } return $text; } @@ -128,22 +121,28 @@ class WatchProfileUpdate extends WatchOperation class WatchRegistration extends WatchOperation { + private static $order = null; + public $flag = 'registration'; public $title = 'Inscription$s'; - protected function buildCondition(PlUser &$user) + protected function buildCondition(Watch $watch) { - return new PFC_And(new UFC_Registered(false, '>', $this->date), - new PFC_Or(new UFC_WatchContact($user), - new UFC_WatchPromo($user))); + return new PFC_And(new UFC_Registered(false, '>', $watch->date()), + new PFC_Or($watch->contactCondition(), + $watch->promoCondition(), + $watch->groupCondition())); } public function getOrder() { - return new UFO_Registration(); + if (!self::$order) { + self::$order = new UFO_Registration(); + } + return self::$order; } - public function getDate(PlUser &$user) + public function getDate(PlUser $user) { return $user->registration_date; } @@ -151,32 +150,38 @@ class WatchRegistration extends WatchOperation class WatchDeath extends WatchOperation { + private static $order = null; + public $flag = 'death'; public $title = 'Décès'; - protected function buildCondition(PlUser &$user) + protected function buildCondition(Watch $watch) { - return new PFC_And(new UFC_Dead('>', $this->date, true), - new PFC_Or(new UFC_WatchPromo($user), - new UFC_WatchContact($user))); + return new PFC_And(new UFC_Dead('>', $watch->date(), true), + new PFC_Or($watch->contactCondition(), + $watch->promoCondition(), + $watch->groupCondition())); } public function getOrder() { - return new UFO_Death(); + if (!self::$order) { + self::$order = new UFO_Death(); + } + return self::$order; } - public function getDate(PlUser &$user) + public function getDate(PlUser $user) { return $user->profile()->deathdate; } - public function publicationDate(PlUser &$user) + public function publicationDate(PlUser $user) { return $user->profile()->deathdate_rec; } - public function seen(PlUser &$user, $last) + public function seen(PlUser $user, $last) { return strtotime($user->profile()->deathdate_rec) > $last; } @@ -186,34 +191,48 @@ class WatchBirthday extends WatchOperation { const WATCH_LIMIT = 604800; // 1 week + private static $order = null; + public $flag = 'birthday'; public $title = 'Anniversaire$s'; - protected function buildCondition(PlUser &$user) + protected function buildCondition(Watch $watch) { - 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))); + $not_dead = new PFC_Not(new UFC_Dead()); + $select_date = new PFC_OR(new UFC_Birthday('=', time()), + new PFC_And(new UFC_Birthday('<=', time() + self::WATCH_LIMIT), + new UFC_Birthday('>', $watch->date() + self::WATCH_LIMIT))); + $profile = $watch->profile(); + $cond = $watch->contactCondition(); + if ($profile) { + $cond = new PFC_Or($cond, + new PFC_And($watch->promoCondition(), + new UFC_Promo('>=', $profile->mainGrade(), $profile->yearpromo() - 1), + new UFC_Promo('<=', $profile->mainGrade(), $profile->yearpromo() + 1)), + $watch->groupCondition()); + } + return new PFC_And($not_dead, $select_date, $cond); } public function getOrder() { - return new UFO_Birthday(); + if (!self::$order) { + self::$order = new UFO_Birthday(); + } + return self::$order; } - public function getDate(PlUser &$user) + public function getDate(PlUser $user) { return $user->profile()->next_birthday; } - public function publicationDate(PlUser &$user) + public function publicationDate(PlUser $user) { return date('Y-m-d', strtotime($user->profile()->next_birthday) - self::WATCH_LIMIT); } - public function seen(PlUser &$user, $last) + public function seen(PlUser $user, $last) { $birthday = strtotime($user->profile()->next_birthday); return $birthday > $last + self::WATCH_LIMIT @@ -227,32 +246,95 @@ class Watch 'WatchProfileUpdate', 'WatchDeath', 'WatchBirthday'); + private static $events = array(); + + private $user = null; + private $date = null; + private $contactCond = null; + private $promoCond = null; + private $groupCond = null; + + private $filters = array(); - private static function fetchCount(PlUser &$user, $date, $class) + public function __construct(PlUser $user, $date = null) { - $obj = new $class(); - $uf = new UserFilter($obj->getCondition($user, $date)); - return $uf->getTotalCount(); + $this->user = $user; + $this->date = self::getDate($user, $date); } - public static function getCount(PlUser &$user, $date = null) + public function user() { - $count = 0; - if (is_null($date)) { - $date = $user->watchLast(); + return $this->user; + } + + public function profile() + { + return $this->user->profile(); + } + + public function date() + { + return $this->date; + } + + public function contactCondition() + { + if (!$this->contactCond) { + $this->contactCond = new UFC_WatchContact($this->user); + } + return $this->contactCond; + } + + public function promoCondition() + { + if (!$this->promoCond) { + $this->promoCond = new UFC_WatchPromo($this->user); + } + return $this->promoCond; + } + + public function groupCondition() + { + if (!$this->groupCond) { + $this->groupCond = new UFC_WatchGroup($this->user); + } + return $this->groupCond; + } + + private function fetchEventWatch($class) + { + if (!isset(self::$events[$class])) { + self::$events[$class] = new $class(); + } + return self::$events[$class]; + } + + private function fetchFilter($class) + { + + if (!isset($this->filters[$class])) { + $event = $this->fetchEventWatch($class); + $this->filters[$class] = new UserFilter($event->getCondition($this), + array($event->getOrder(), new UFO_Name())); } + return $this->filters[$class]; + } + + public function count() + { + $count = 0; foreach (self::$classes as $class) { - $count += self::fetchCount($user, $date, $class); + $uf = $this->fetchFilter($class); + $count += $uf->getTotalCount(); } return $count; } - private static function fetchEvents(PlUser &$user, $date, $class) + private function fetchEvents($class) { - $obj = new $class(); - $uf = new UserFilter($obj->getCondition($user, $date), - array($obj->getOrder(), new UFO_Name(Profile::DN_SORT))); + $obj = $this->fetchEventWatch($class); + $uf = $this->fetchFilter($class); $users = $uf->getUsers(); if (count($users) == 0) { return null; @@ -264,21 +346,43 @@ class Watch } } - public static function getEvents(PlUser &$user, $date = null) + public function events() { - if (is_null($date)) { - $date = $user->watchLast(); - } $events = array(); foreach (self::$classes as $class) { - $e = self::fetchEvents($user, $date, $class); + $e = $this->fetchEvents($class); if (!is_null($e)) { $events[] = $e; } } return $events; } + + + 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; + } + + public static function getCount(PlUser $user, $date = null) + { + $watch = new Watch($user, $date); + return $watch->count(); + } + + public static function getEvents(PlUser $user, $date = null) + { + $watch = new Watch($user, $date); + return $watch->events(); + } } -// 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: ?>