ILIAS  release_7 Revision v7.30-3-g800a261c036
ilNotification Class Reference

Class ilNotification. More...

+ Collaboration diagram for ilNotification:

Static Public Member Functions

static hasNotification ($type, $user_id, $id)
 Check notification status for object and user. More...
 
static hasOptOut ($obj_id)
 Is opt out (disable notification) allowed? More...
 
static getNotificationsForObject ($type, $id, $page_id=null, $ignore_threshold=false)
 Get all users for given object. More...
 
static setNotification ($type, $user_id, $id, $status=true)
 Set notification status for object and user. More...
 
static updateNotificationTime ($type, $id, array $user_ids, $page_id=false)
 Update the last mail timestamp for given object and users. More...
 
static removeForObject ($type, $id)
 Remove all notifications for given object. More...
 
static removeForUser ($user_id)
 Remove all notifications for given user. More...
 
static getActivatedNotifications (int $type, int $user_id)
 Get activated notifications of give type for user. More...
 

Data Fields

const TYPE_EXERCISE_SUBMISSION = 1
 
const TYPE_WIKI = 2
 
const TYPE_WIKI_PAGE = 3
 
const TYPE_BLOG = 4
 
const TYPE_DATA_COLLECTION = 5
 
const TYPE_POLL = 6
 
const TYPE_LM_BLOCKED_USERS = 7
 
const TYPE_BOOK = 8
 
const TYPE_LM = 9
 
const TYPE_LM_PAGE = 10
 
const THRESHOLD = 180
 

Detailed Description

Class ilNotification.

Author
Jörg Lützenkirchen luetz.nosp@m.enki.nosp@m.rchen.nosp@m.@lei.nosp@m.fos.c.nosp@m.om
Id
class.ilObjExerciseGUI.php 24003 2010-05-26 14:35:42Z akill

Definition at line 13 of file class.ilNotification.php.

Member Function Documentation

◆ getActivatedNotifications()

static ilNotification::getActivatedNotifications ( int  $type,
int  $user_id 
)
static

Get activated notifications of give type for user.

Parameters
int$type
int$user_id
Returns
int[]

Definition at line 343 of file class.ilNotification.php.

343 : array
344 {
345 global $DIC;
346
347 $db = $DIC->database();
348
349 $set = $db->queryF(
350 "SELECT id FROM notification " .
351 " WHERE type = %s " .
352 " AND user_id = %s " .
353 " AND activated = %s ",
354 array("integer", "integer", "integer"),
355 array($type, $user_id, 1)
356 );
357 $ids = [];
358 while ($rec = $db->fetchAssoc($set)) {
359 $ids[] = $rec["id"];
360 }
361
362 return $ids;
363 }
global $DIC
Definition: goto.php:24
$type

References $DIC, and $type.

Referenced by ilExcTutorRepository\getExerciseIdsBeingTutor().

+ Here is the caller graph for this function:

◆ getNotificationsForObject()

static ilNotification::getNotificationsForObject (   $type,
  $id,
  $page_id = null,
  $ignore_threshold = false 
)
static

Get all users for given object.

Parameters
int$type
int$id
int$page_id
bool$ignore_threshold
Returns
array

Definition at line 120 of file class.ilNotification.php.

121 {
122 global $DIC;
123
124 $ilDB = $DIC->database();
125 $tree = $DIC->repositoryTree();
126
127 include_once("./Services/Notification/classes/class.ilObjNotificationSettings.php");
128
130 $log->debug("Get notifications for type " . $type . ", id " . $id . ", page_id " . $page_id .
131 ", ignore threshold " . $ignore_threshold);
132
133 // currently done for blog
134 $recipients = array();
135 $setting = new ilObjNotificationSettings($id);
137 foreach (ilObject::_getAllReferences($id) as $ref_id) {
138 $grp_ref_id = $tree->checkForParentType($ref_id, 'grp');
139 if ($grp_ref_id > 0) {
140 include_once("./Modules/Group/classes/class.ilGroupParticipants.php");
142 foreach ($p->getMembers() as $user_id) {
143 if (!in_array($user_id, $recipients)) {
144 $recipients[$user_id] = $user_id;
145 }
146 }
147 }
148 $crs_ref_id = $tree->checkForParentType($ref_id, 'crs');
149 if ($crs_ref_id > 0) {
150 include_once("./Modules/Course/classes/class.ilCourseParticipants.php");
152 foreach ($p->getMembers() as $user_id) {
153 if (!in_array($user_id, $recipients)) {
154 $recipients[$user_id] = $user_id;
155 }
156 }
157 }
158 }
159 }
160
161 $log->debug("Step 1 recipients: " . print_r($recipients, true));
162
163
164 // remove all users that deactivated the feature
165 if ($setting->getMode() == ilObjNotificationSettings::MODE_DEF_ON_OPT_OUT) {
166 $sql = "SELECT user_id FROM notification" .
167 " WHERE type = " . $ilDB->quote($type, "integer") .
168 " AND id = " . $ilDB->quote($id, "integer") .
169 " AND activated = " . $ilDB->quote(0, "integer") .
170 " AND " . $ilDB->in("user_id", $recipients, false, "integer");
171 $set = $ilDB->query($sql);
172 while ($rec = $ilDB->fetchAssoc($set)) {
173 unset($recipients[$rec["user_id"]]);
174 $log->debug("Remove due to deactivation: " . $rec["user_id"]);
175 }
176 }
177
178 // remove all users that got a mail
179 // see #22773
180 //if ($setting->getMode() != ilObjNotificationSettings::MODE_DEF_OFF_USER_ACTIVATION && !$ignore_threshold) {
181 if (!$ignore_threshold) {
182 $sql = "SELECT user_id FROM notification" .
183 " WHERE type = " . $ilDB->quote($type, "integer") .
184 " AND id = " . $ilDB->quote($id, "integer") .
185 " AND " . $ilDB->in("user_id", $recipients, false, "integer");
186 $sql .= " AND (last_mail > " . $ilDB->quote(date(
187 "Y-m-d H:i:s",
188 strtotime("-" . self::THRESHOLD . "minutes")
189 ), "timestamp");
190 if ($page_id) {
191 $sql .= " AND page_id = " . $ilDB->quote($page_id, "integer");
192 }
193 $sql .= ")";
194 $set = $ilDB->query($sql);
195 while ($rec = $ilDB->fetchAssoc($set)) {
196 unset($recipients[$rec["user_id"]]);
197 $log->debug("Remove due to got mail: " . $rec["user_id"]);
198 }
199 }
200
201 // get single subscriptions
202 if ($setting->getMode() != ilObjNotificationSettings::MODE_DEF_ON_NO_OPT_OUT) {
203 $sql = "SELECT user_id FROM notification" .
204 " WHERE type = " . $ilDB->quote($type, "integer") .
205 " AND id = " . $ilDB->quote($id, "integer") .
206 " AND activated = " . $ilDB->quote(1, "integer");
207 if (!$ignore_threshold) {
208 $sql .= " AND (last_mail < " . $ilDB->quote(date(
209 "Y-m-d H:i:s",
210 strtotime("-" . self::THRESHOLD . "minutes")
211 ), "timestamp") .
212 " OR last_mail IS NULL";
213 if ($page_id) {
214 $sql .= " OR page_id <> " . $ilDB->quote($page_id, "integer");
215 }
216 $sql .= ")";
217 }
218 $set = $ilDB->query($sql);
219 while ($row = $ilDB->fetchAssoc($set)) {
220 $recipients[$row["user_id"]] = $row["user_id"];
221 $log->debug("Adding single subscription: " . $row["user_id"]);
222 }
223 }
224
225 return $recipients;
226 }
static _getInstanceByObjId($a_obj_id)
Get singleton instance.
static _getInstanceByObjId($a_obj_id)
Get singleton instance.
static getLogger($a_component_id)
Get component logger.
Handles general object notification settings, see e.g.
static _lookupObjectId($a_ref_id)
lookup object id
static _getAllReferences($a_id)
get all reference ids of object
$log
Definition: result.php:15
global $ilDB

References $DIC, $ilDB, $log, $type, ilObject\_getAllReferences(), ilCourseParticipants\_getInstanceByObjId(), ilGroupParticipants\_getInstanceByObjId(), ilObject\_lookupObjectId(), ilLoggerFactory\getLogger(), ilObjNotificationSettings\MODE_DEF_OFF_USER_ACTIVATION, ilObjNotificationSettings\MODE_DEF_ON_NO_OPT_OUT, and ilObjNotificationSettings\MODE_DEF_ON_OPT_OUT.

Referenced by ilExSubmissionBaseGUI\handleNewUpload(), ilExAssTypeWikiTeam\handleNewUpload(), ilExAssignmentReminder\parseGradeReminders(), ilLMPageGUI\processAnswer(), ilLearningModuleNotification\send(), ilObjBlog\sendNotification(), ilWikiUtil\sendNotification(), ilBookCronNotification\sendNotifications(), and ilObjPollGUI\sendNotifications().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ hasNotification()

static ilNotification::hasNotification (   $type,
  $user_id,
  $id 
)
static

Check notification status for object and user.

Parameters
int$type
int$user_id
int$id
Returns
bool

Definition at line 36 of file class.ilNotification.php.

37 {
38 global $DIC;
39
40 $ilDB = $DIC->database();
41 $tree = $DIC->repositoryTree();
42
43 $notification = false;
44
45 include_once("./Services/Notification/classes/class.ilObjNotificationSettings.php");
46 $setting = new ilObjNotificationSettings($id);
48 // check membership, members should be notidifed...
49 foreach (ilObject::_getAllReferences($id) as $ref_id) {
50 $grp_ref_id = $tree->checkForParentType($ref_id, 'grp');
51 if ($grp_ref_id > 0) {
52 include_once("./Modules/Group/classes/class.ilGroupParticipants.php");
53 if (ilGroupParticipants::_isParticipant($grp_ref_id, $user_id)) {
54 $notification = true;
55 }
56 }
57 $crs_ref_id = $tree->checkForParentType($ref_id, 'crs');
58 if ($crs_ref_id > 0) {
59 include_once("./Modules/Course/classes/class.ilCourseParticipants.php");
60 if (ilCourseParticipants::_isParticipant($crs_ref_id, $user_id)) {
61 $notification = true;
62 }
63 }
64 }
65
66 if ($notification && $setting->getMode() == ilObjNotificationSettings::MODE_DEF_ON_OPT_OUT) {
67 $set = $ilDB->query("SELECT user_id FROM notification" .
68 " WHERE type = " . $ilDB->quote($type, "integer") .
69 " AND user_id = " . $ilDB->quote($user_id, "integer") .
70 " AND id = " . $ilDB->quote($id, "integer") .
71 " AND activated = " . $ilDB->quote(0, "integer"));
72 $rec = $ilDB->fetchAssoc($set);
73 // ... except when the opted out
74 if ($rec["user_id"] == $user_id) {
75 return false;
76 }
77 return true;
78 }
79
80 if ($notification && $setting->getMode() == ilObjNotificationSettings::MODE_DEF_ON_NO_OPT_OUT) {
81 return true;
82 }
83 }
84
85
86 $set = $ilDB->query("SELECT user_id FROM notification" .
87 " WHERE type = " . $ilDB->quote($type, "integer") .
88 " AND user_id = " . $ilDB->quote($user_id, "integer") .
89 " AND id = " . $ilDB->quote($id, "integer") .
90 " AND activated = " . $ilDB->quote(1, "integer"));
91
92 return (bool) $ilDB->numRows($set);
93 }
static _isParticipant($a_ref_id, $a_usr_id)
Static function to check if a user is a participant of the container object.
static _isParticipant($a_ref_id, $a_usr_id)
Static function to check if a user is a participant of the container object.

References $DIC, $ilDB, $type, ilObject\_getAllReferences(), ilGroupParticipants\_isParticipant(), ilParticipants\_isParticipant(), ilObjNotificationSettings\MODE_DEF_OFF_USER_ACTIVATION, ilObjNotificationSettings\MODE_DEF_ON_NO_OPT_OUT, and ilObjNotificationSettings\MODE_DEF_ON_OPT_OUT.

Referenced by ilObjDataCollectionGUI\addHeaderAction(), ilWikiPageGUI\addHeaderAction(), ilObjExerciseGUI\getEditFormCustomValues(), ilLMPresentationGUI\getHeaderAction(), ilPollBlockGUI\getHTML(), ilObjContentObjectGUI\getPropertiesFormValues(), ilObjBookingPoolGUI\initHeaderAction(), and ilObjBlogGUI\initHeaderAction().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ hasOptOut()

static ilNotification::hasOptOut (   $obj_id)
static

Is opt out (disable notification) allowed?

Parameters
int$obj_id
Returns
bool

Definition at line 101 of file class.ilNotification.php.

102 {
103 include_once("./Services/Notification/classes/class.ilObjNotificationSettings.php");
104 $setting = new ilObjNotificationSettings($obj_id);
105 if ($setting->getMode() == ilObjNotificationSettings::MODE_DEF_ON_NO_OPT_OUT) {
106 return false;
107 }
108 return true;
109 }

References ilObjNotificationSettings\MODE_DEF_ON_NO_OPT_OUT.

Referenced by ilWikiPageGUI\addHeaderAction(), ilLMPresentationGUI\getHeaderAction(), and ilObjBlogGUI\initHeaderAction().

+ Here is the caller graph for this function:

◆ removeForObject()

static ilNotification::removeForObject (   $type,
  $id 
)
static

Remove all notifications for given object.

Parameters
int$type
int$id

Definition at line 310 of file class.ilNotification.php.

311 {
312 global $DIC;
313
314 $ilDB = $DIC->database();
315
316 $ilDB->query("DELETE FROM notification" .
317 " WHERE type = " . $ilDB->quote($type, "integer") .
318 " AND id = " . $ilDB->quote($id, "integer"));
319 }

References $DIC, $ilDB, and $type.

Referenced by ilObjExercise\delete(), ilObjWiki\delete(), ilWikiPage\delete(), and ilObjBlog\doDelete().

+ Here is the caller graph for this function:

◆ removeForUser()

static ilNotification::removeForUser (   $user_id)
static

Remove all notifications for given user.

Parameters
int$user_id

Definition at line 326 of file class.ilNotification.php.

327 {
328 global $DIC;
329
330 $ilDB = $DIC->database();
331
332 $ilDB->query("DELETE FROM notification" .
333 " WHERE user_id = " . $ilDB->quote($user_id, "integer"));
334 }

References $DIC, and $ilDB.

Referenced by ilObjUser\delete().

+ Here is the caller graph for this function:

◆ setNotification()

static ilNotification::setNotification (   $type,
  $user_id,
  $id,
  $status = true 
)
static

Set notification status for object and user.

Parameters
int$type
int$user_id
int$id
bool$status

Definition at line 236 of file class.ilNotification.php.

237 {
238 global $DIC;
239
240 $ilDB = $DIC->database();
241
242 $fields = array(
243 "type" => array("integer", $type),
244 "user_id" => array("integer", $user_id),
245 "id" => array("integer", $id)
246 );
247 $ilDB->replace("notification", $fields, array("activated" => array("integer", (int) $status)));
248 }

References $DIC, $ilDB, and $type.

Referenced by ilLMPresentationGUI\executeCommand(), ilWikiPageGUI\executeCommand(), ilObjBookingPoolGUI\saveNotificationObject(), ilObjContentObjectGUI\saveProperties(), ilObjBlogGUI\setNotification(), ilObjPollGUI\subscribe(), ilObjBibliographicGUI\toggleNotification(), ilObjDataCollectionGUI\toggleNotification(), ilObjPollGUI\unsubscribe(), and ilObjExerciseGUI\updateCustom().

+ Here is the caller graph for this function:

◆ updateNotificationTime()

static ilNotification::updateNotificationTime (   $type,
  $id,
array  $user_ids,
  $page_id = false 
)
static

Update the last mail timestamp for given object and users.

Parameters
int$type
int$id
array$user_ids
int$page_id

Definition at line 258 of file class.ilNotification.php.

259 {
260 global $DIC;
261
262 $ilDB = $DIC->database();
263
264 // create initial entries, if not existing
265 // see #22773, currently only done for wiki, might be feasible for other variants
266 if (in_array($type, [self::TYPE_WIKI, self::TYPE_BLOG])) {
267 $set = $ilDB->queryF(
268 "SELECT user_id FROM notification " .
269 " WHERE type = %s AND id = %s AND " .
270 $ilDB->in("user_id", $user_ids, false, "integer"),
271 ["integer", "integer"],
272 [$type, $id]
273 );
274 $noti_users = [];
275 while ($rec = $ilDB->fetchAssoc($set)) {
276 $noti_users[] = $rec["user_id"];
277 }
278 foreach ($user_ids as $user_id) {
279 if (!in_array($user_id, $noti_users)) {
280 $ilDB->insert("notification", [
281 "type" => ["integer", $type],
282 "id" => ["integer", $id],
283 "user_id" => ["integer", $user_id],
284 "page_id" => ["integer", (int) $page_id],
285 "activated" => ["integer", 1]
286 ]);
287 }
288 }
289 }
290
291 $sql = "UPDATE notification" .
292 " SET last_mail = " . $ilDB->quote(date("Y-m-d H:i:s"), "timestamp");
293
294 if ($page_id) {
295 $sql .= ", page_id = " . $ilDB->quote($page_id, "integer");
296 }
297
298 $sql .= " WHERE type = " . $ilDB->quote($type, "integer") .
299 " AND id = " . $ilDB->quote($id, "integer") .
300 " AND " . $ilDB->in("user_id", $user_ids, false, "integer");
301 $ilDB->query($sql);
302 }

References $DIC, $ilDB, and $type.

Referenced by ilLearningModuleNotification\send(), ilObjBlog\sendNotification(), ilWikiUtil\sendNotification(), and ilObjPollGUI\sendNotifications().

+ Here is the caller graph for this function:

Field Documentation

◆ THRESHOLD

const ilNotification::THRESHOLD = 180

Definition at line 26 of file class.ilNotification.php.

◆ TYPE_BLOG

const ilNotification::TYPE_BLOG = 4

◆ TYPE_BOOK

◆ TYPE_DATA_COLLECTION

const ilNotification::TYPE_DATA_COLLECTION = 5

◆ TYPE_EXERCISE_SUBMISSION

◆ TYPE_LM

◆ TYPE_LM_BLOCKED_USERS

const ilNotification::TYPE_LM_BLOCKED_USERS = 7

◆ TYPE_LM_PAGE

◆ TYPE_POLL

const ilNotification::TYPE_POLL = 6

◆ TYPE_WIKI

◆ TYPE_WIKI_PAGE


The documentation for this class was generated from the following file: