Moving to GitHub.
[platal.git] / include / notifs.inc.php
index 4d8013c..19a6480 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /***************************************************************************
- *  Copyright (C) 2003-2011 Polytechnique.org                              *
+ *  Copyright (C) 2003-2014 Polytechnique.org                              *
  *  http://opensource.polytechnique.org/                                   *
  *                                                                         *
  *  This program is free software; you can redistribute it and/or modify   *
@@ -130,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 +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()
@@ -196,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)));
@@ -205,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()
@@ -248,6 +252,7 @@ class Watch
     private $date = null;
     private $contactCond = null;
     private $promoCond = null;
+    private $groupCond = null;
 
     private $filters = array();
 
@@ -288,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])) {
@@ -302,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];
     }
@@ -371,5 +384,5 @@ class Watch
     }
 }
 
-// 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:
 ?>