ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
class.ilNotification.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
4
16{
18 const TYPE_WIKI = 2;
19 const TYPE_WIKI_PAGE = 3;
20 const TYPE_BLOG = 4;
22 const TYPE_POLL = 6;
24
25 const THRESHOLD = 180; // time between mails in minutes
26
35 public static function hasNotification($type, $user_id, $id)
36 {
37 global $ilDB;
38
39 $set = $ilDB->query("SELECT user_id FROM notification".
40 " WHERE type = ".$ilDB->quote($type, "integer").
41 " AND user_id = ".$ilDB->quote($user_id, "integer").
42 " AND id = ".$ilDB->quote($id, "integer"));
43 return (bool)$ilDB->numRows($set);
44 }
45
55 public static function getNotificationsForObject($type, $id, $page_id = null, $ignore_threshold = false)
56 {
57 global $ilDB;
58
59 $sql = "SELECT user_id FROM notification".
60 " WHERE type = ".$ilDB->quote($type, "integer").
61 " AND id = ".$ilDB->quote($id, "integer");
62 if(!$ignore_threshold)
63 {
64 $sql .= " AND (last_mail < ".$ilDB->quote(date("Y-m-d H:i:s",
65 strtotime("-".self::THRESHOLD."minutes")), "timestamp").
66 " OR last_mail IS NULL";
67 if($page_id)
68 {
69 $sql .= " OR page_id <> ".$ilDB->quote($page_id, "integer");
70 }
71 $sql .= ")";
72 }
73 $user = array();
74 $set = $ilDB->query($sql);
75 while($row = $ilDB->fetchAssoc($set))
76 {
77 $user[] = $row["user_id"];
78 }
79 return $user;
80 }
81
91 public static function setNotification($type, $user_id, $id, $status = true)
92 {
93 global $ilDB;
94
95 if(!$status)
96 {
97 $ilDB->query("DELETE FROM notification".
98 " WHERE type = ".$ilDB->quote($type, "integer").
99 " AND user_id = ".$ilDB->quote($user_id, "integer").
100 " AND id = ".$ilDB->quote($id, "integer"));
101 }
102 else
103 {
104 $fields = array(
105 "type" => array("integer", $type),
106 "user_id" => array("integer", $user_id),
107 "id" => array("integer", $id)
108 );
109 $ilDB->replace("notification", $fields, array());
110 }
111 }
112
121 public static function updateNotificationTime($type, $id, array $user_ids, $page_id = false)
122 {
123 global $ilDB;
124
125 $sql = "UPDATE notification".
126 " SET last_mail = ".$ilDB->quote(date("Y-m-d H:i:s"), "timestamp");
127
128 if($page_id)
129 {
130 $sql .= ", page_id = ".$ilDB->quote($page_id, "integer");
131 }
132
133 $sql .= " WHERE type = ".$ilDB->quote($type, "integer").
134 " AND id = ".$ilDB->quote($id, "integer").
135 " AND ".$ilDB->in("user_id", $user_ids, false, "integer");
136
137 $ilDB->query($sql);
138 }
139
146 public static function removeForObject($type, $id)
147 {
148 global $ilDB;
149
150 $ilDB->query("DELETE FROM notification".
151 " WHERE type = ".$ilDB->quote($type, "integer").
152 " AND id = ".$ilDB->quote($id, "integer"));
153 }
154
160 public static function removeForUser($user_id)
161 {
162 global $ilDB;
163
164 $ilDB->query("DELETE FROM notification".
165 " WHERE user_id = ".$ilDB->quote($user_id, "integer"));
166 }
167}
168
169?>
Class ilNotification.
static removeForUser($user_id)
Remove all notifications for given user.
static removeForObject($type, $id)
Remove all notifications for given object.
static setNotification($type, $user_id, $id, $status=true)
Set notification status for object and user.
static getNotificationsForObject($type, $id, $page_id=null, $ignore_threshold=false)
Get all users for given object.
static updateNotificationTime($type, $id, array $user_ids, $page_id=false)
Update the last mail timestamp for given object and users.
static hasNotification($type, $user_id, $id)
Check notification status for object and user.
global $ilDB