Can get the number of notification.
[platal.git] / include / notifs.inc.php
index 8efb108..0cdfdf5 100644 (file)
@@ -30,9 +30,9 @@ class WatchProfileUpdate
                      $profile->id(), $field);
     }
 
-    public static function getCondition(PlUser &$user)
+    public function getCondition(PlUser &$user)
     {
-        return new UFC_And(new UFC_ProfileUpdated('>=', $user->watch_last),
+        return new UFC_And(new UFC_ProfileUpdated('>', $user->watch_last),
                            new UFC_WatchContacts($user->id()));
     }
 }
@@ -41,10 +41,12 @@ class WatchRegistration
 {
     const ID = 2;
 
-    public static function getCondition(PlUser &$user)
+    public function getCondition(PlUser &$user)
     {
-        return new UFC_And(new UFC_Registered(false, '>=', $user->watch_last),
-                           new UFC_WatchRegistration($user->id()));
+        return new UFC_And(new UFC_Registered(false, '>', $user->watch_last),
+                           new UFC_Or(new UFC_WatchContacts($user->id()),
+                                      new UFC_WatchPromo($user->id()),
+                                      new UFC_WatchRegistration($user->id())));
     }
 }
 
@@ -52,9 +54,9 @@ class WatchDeath
 {
     const ID = 3;
 
-    public static function getCondition(PlUser &$user)
+    public function getCondition(PlUser &$user)
     {
-        return new UFC_And(new UFC_Dead('>=', $user->watch_last, true),
+        return new UFC_And(new UFC_Dead('>', $user->watch_last, true),
                            new UFC_Or(new UFC_WatchPromo($user->id()),
                                       new UFC_WatchContacts($user->id())));
     }
@@ -64,12 +66,39 @@ class WatchBirthday
 {
     const ID = 4;
 
-    public static function getCondition(PlUser &$user)
+    public function getCondition(PlUser &$user)
     {
-        return new UFC_And(new UFC_Birthday(),
+        return new UFC_And(new UFC_OR(new UFC_Birthday('=', time()),
+                                      new UFC_And(new UFC_Birthday('<=', time() + 864000),
+                                                  new UFC_Birthday('>', $user->watch_last + 864000))),
                            new UFC_Or(new UFC_WatchPromo($user->id()),
                                       new UFC_WatchContacts($user->id())));
     }
 }
 
+class Watch
+{
+    private static  $classes = array('WatchRegistration',
+                                     'WatchProfileUpdate',
+                                     'WatchDeath',
+                                     'WatchBirthday');
+
+    private static function fetchCount(PlUser &$user, $class)
+    {
+        $obj = new $class();
+        $uf = new UserFilter($obj->getCondition($user));
+        return $uf->getTotalCount();
+    }
+
+    public static function getCount(PlUser &$user)
+    {
+        $count = 0;
+        foreach (self::$classes as $class) {
+            $count += self::fetchCount($user, $class);
+        }
+        return $count;
+    }
+}
+
+// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
 ?>