Moving to GitHub.
[platal.git] / include / notifs.inc.php
index 0d2c5e2..19a6480 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /***************************************************************************
- *  Copyright (C) 2003-2010 Polytechnique.org                              *
+ *  Copyright (C) 2003-2014 Polytechnique.org                              *
  *  http://opensource.polytechnique.org/                                   *
  *                                                                         *
  *  This program is free software; you can redistribute it and/or modify   *
@@ -46,19 +46,19 @@ abstract class WatchOperation
 
     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;
     }
@@ -72,7 +72,7 @@ class WatchProfileUpdate extends WatchOperation
     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('INSERT INTO  watch_profile (pid, ts, field)
                            VALUES  ({?}, NOW(), {?})
@@ -95,29 +95,12 @@ class WatchProfileUpdate extends WatchOperation
         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
@@ -129,7 +112,7 @@ class WatchProfileUpdate extends WatchOperation
         } else {
             $text = array();
             foreach ($data as $f) {
-                $text[] = self::$descriptions[$f];
+                $text[] = Profile::$descriptions[$f];
             }
             return $text;
         }
@@ -147,7 +130,8 @@ class WatchRegistration extends WatchOperation
     {
         return new PFC_And(new UFC_Registered(false, '>', $watch->date()),
                            new PFC_Or($watch->contactCondition(),
-                                      $watch->promoCondition()));
+                                      $watch->promoCondition(),
+                                      $watch->groupCondition()));
     }
 
     public function getOrder()
@@ -158,7 +142,7 @@ class WatchRegistration extends WatchOperation
         return self::$order;
     }
 
-    public function getDate(PlUser &$user)
+    public function getDate(PlUser $user)
     {
         return $user->registration_date;
     }
@@ -175,7 +159,8 @@ class WatchDeath extends WatchOperation
     {
         return new PFC_And(new UFC_Dead('>', $watch->date(), true),
                            new PFC_Or($watch->contactCondition(),
-                                      $watch->promoCondition()));
+                                      $watch->promoCondition(),
+                                      $watch->groupCondition()));
     }
 
     public function getOrder()
@@ -186,17 +171,17 @@ class WatchDeath extends WatchOperation
         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;
     }
@@ -213,6 +198,7 @@ class WatchBirthday extends WatchOperation
 
     protected function buildCondition(Watch $watch)
     {
+        $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)));
@@ -222,9 +208,10 @@ class WatchBirthday extends WatchOperation
             $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)));
+                                           new UFC_Promo('<=', $profile->mainGrade(), $profile->yearpromo() + 1)),
+                               $watch->groupCondition());
         }
-        return new PFC_And($select_date, $cond);
+        return new PFC_And($not_dead, $select_date, $cond);
     }
 
     public function getOrder()
@@ -235,17 +222,17 @@ class WatchBirthday extends WatchOperation
         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
@@ -265,6 +252,7 @@ class Watch
     private $date = null;
     private $contactCond = null;
     private $promoCond = null;
+    private $groupCond = null;
 
     private $filters = array();
 
@@ -305,6 +293,14 @@ class Watch
         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])) {
@@ -319,7 +315,7 @@ class Watch
         if (!isset($this->filters[$class])) {
             $event = $this->fetchEventWatch($class);
             $this->filters[$class] = new UserFilter($event->getCondition($this),
-                                                    array($event->getOrder(), new UFO_Name(Profile::DN_SORT)));
+                                                    array($event->getOrder(), new UFO_Name()));
         }
         return $this->filters[$class];
     }
@@ -363,7 +359,7 @@ class Watch
     }
 
 
-    private static function getDate(PlUser &$user, $date)
+    private static function getDate(PlUser $user, $date)
     {
         if (is_null($date)) {
             $date = $user->watchLast();
@@ -375,18 +371,18 @@ class Watch
         return $date;
     }
 
-    public static function getCount(PlUser &$user, $date = null)
+    public static function getCount(PlUser $user, $date = null)
     {
         $watch = new Watch($user, $date);
         return $watch->count();
     }
 
-    public static function getEvents(PlUser &$user, $date = null)
+    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:
 ?>