Can get the number of notification.
[platal.git] / include / notifs.inc.php
CommitLineData
0337d704 1<?php
2/***************************************************************************
8d84c630 3 * Copyright (C) 2003-2009 Polytechnique.org *
0337d704 4 * http://opensource.polytechnique.org/ *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the Free Software *
18 * Foundation, Inc., *
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
20 ***************************************************************************/
21
4e7bf1e0 22class WatchProfileUpdate
612a2d8a 23{
4e7bf1e0 24 const ID = 1;
a3a049fc 25
4e7bf1e0 26 public static function register(Profile &$profile, $field)
612a2d8a 27 {
4e7bf1e0
FB
28 XDB::execute('REPLACE INTO watch_profile (uid, ts, field)
29 VALUES ({?}, NOW(), {?})',
30 $profile->id(), $field);
0337d704 31 }
32
7e735012 33 public function getCondition(PlUser &$user)
612a2d8a 34 {
7e735012 35 return new UFC_And(new UFC_ProfileUpdated('>', $user->watch_last),
4e7bf1e0 36 new UFC_WatchContacts($user->id()));
0337d704 37 }
38}
39
4e7bf1e0 40class WatchRegistration
612a2d8a 41{
4e7bf1e0 42 const ID = 2;
0337d704 43
7e735012 44 public function getCondition(PlUser &$user)
612a2d8a 45 {
7e735012
FB
46 return new UFC_And(new UFC_Registered(false, '>', $user->watch_last),
47 new UFC_Or(new UFC_WatchContacts($user->id()),
48 new UFC_WatchPromo($user->id()),
49 new UFC_WatchRegistration($user->id())));
0337d704 50 }
51}
52
4e7bf1e0 53class WatchDeath
612a2d8a 54{
4e7bf1e0 55 const ID = 3;
0337d704 56
7e735012 57 public function getCondition(PlUser &$user)
612a2d8a 58 {
7e735012 59 return new UFC_And(new UFC_Dead('>', $user->watch_last, true),
4e7bf1e0
FB
60 new UFC_Or(new UFC_WatchPromo($user->id()),
61 new UFC_WatchContacts($user->id())));
0337d704 62 }
63}
64
4e7bf1e0 65class WatchBirthday
612a2d8a 66{
4e7bf1e0 67 const ID = 4;
0337d704 68
7e735012 69 public function getCondition(PlUser &$user)
612a2d8a 70 {
7e735012
FB
71 return new UFC_And(new UFC_OR(new UFC_Birthday('=', time()),
72 new UFC_And(new UFC_Birthday('<=', time() + 864000),
73 new UFC_Birthday('>', $user->watch_last + 864000))),
4e7bf1e0
FB
74 new UFC_Or(new UFC_WatchPromo($user->id()),
75 new UFC_WatchContacts($user->id())));
0337d704 76 }
77}
a3a049fc 78
7e735012
FB
79class Watch
80{
81 private static $classes = array('WatchRegistration',
82 'WatchProfileUpdate',
83 'WatchDeath',
84 'WatchBirthday');
85
86 private static function fetchCount(PlUser &$user, $class)
87 {
88 $obj = new $class();
89 $uf = new UserFilter($obj->getCondition($user));
90 return $uf->getTotalCount();
91 }
92
93 public static function getCount(PlUser &$user)
94 {
95 $count = 0;
96 foreach (self::$classes as $class) {
97 $count += self::fetchCount($user, $class);
98 }
99 return $count;
100 }
101}
102
103// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
0337d704 104?>