ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ilNotification Class Reference

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V. More...

+ Collaboration diagram for ilNotification:

Static Public Member Functions

static hasNotification (int $type, int $user_id, int $id)
 Check notification status for object and user. More...
 
static hasOptOut (int $obj_id)
 Is opt out (disable notification) allowed? More...
 
static getNotificationsForObject (int $type, int $id, ?int $page_id=null, bool $ignore_threshold=false)
 Get all users/recipients for given object. More...
 
static setNotification (int $type, int $user_id, int $id, bool $status=true)
 Set notification status for object and user. More...
 
static updateNotificationTime (int $type, int $id, array $user_ids, ?int $page_id=null, bool $activate_new_entries=true)
 Update the last mail timestamp for given object and users. More...
 
static removeForObject (int $type, int $id)
 Remove all notifications for given object. More...
 
static removeForUser (int $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 THRESHOLD = 180
 
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
 

Detailed Description

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V.

ILIAS is licensed with the GPL-3.0, see https://www.gnu.org/licenses/gpl-3.0.en.html You should have received a copy of said license along with the source code, too.

If this is not the case or you just want to try ILIAS, you'll find us at: https://www.ilias.de https://github.com/ILIAS-eLearning

Author
Jörg Lützenkirchen luetz.nosp@m.enki.nosp@m.rchen.nosp@m.@lei.nosp@m.fos.c.nosp@m.om

Definition at line 22 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.

Returns
int[]

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

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

Referenced by ilExcTutorRepository\getExerciseIdsBeingTutor().

+ Here is the caller graph for this function:

◆ getNotificationsForObject()

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

Get all users/recipients for given object.

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

112 : array {
113 global $DIC;
114
115 $ilDB = $DIC->database();
116 $tree = $DIC->repositoryTree();
117
118
120 $log->debug("Get notifications for type " . $type . ", id " . $id . ", page_id " . $page_id .
121 ", ignore threshold " . $ignore_threshold);
122
123 // currently done for blog
124 $recipients = array();
125 $setting = new ilObjNotificationSettings($id);
128 $grp_ref_id = $tree->checkForParentType($ref_id, 'grp');
129 if ($grp_ref_id > 0) {
131 foreach ($p->getMembers() as $user_id) {
132 if (!in_array($user_id, $recipients)) {
133 $recipients[$user_id] = $user_id;
134 }
135 }
136 }
137 $crs_ref_id = $tree->checkForParentType($ref_id, 'crs');
138 if ($crs_ref_id > 0) {
140 foreach ($p->getMembers() as $user_id) {
141 if (!in_array($user_id, $recipients)) {
142 $recipients[$user_id] = $user_id;
143 }
144 }
145 }
146 }
147 }
148
149 $log->debug("Step 1 recipients: " . print_r($recipients, true));
150
151 // remove all users that deactivated the feature
152 if ($setting->getMode() === ilObjNotificationSettings::MODE_DEF_ON_OPT_OUT) {
153 $sql = "SELECT user_id FROM notification" .
154 " WHERE type = " . $ilDB->quote($type, "integer") .
155 " AND id = " . $ilDB->quote($id, "integer") .
156 " AND activated = " . $ilDB->quote(0, "integer") .
157 " AND " . $ilDB->in("user_id", $recipients, false, "integer");
158 $set = $ilDB->query($sql);
159 while ($rec = $ilDB->fetchAssoc($set)) {
160 unset($recipients[$rec["user_id"]]);
161 $log->debug("Remove due to deactivation: " . $rec["user_id"]);
162 }
163 }
164
165 // get single subscriptions
166 if ($setting->getMode() !== ilObjNotificationSettings::MODE_DEF_ON_NO_OPT_OUT) {
167 $sql = "SELECT user_id FROM notification" .
168 " WHERE type = " . $ilDB->quote($type, "integer") .
169 " AND id = " . $ilDB->quote($id, "integer") .
170 " AND activated = " . $ilDB->quote(1, "integer");
171 if (!$ignore_threshold) {
172 $sql .= " AND (last_mail < " . $ilDB->quote(date(
173 "Y-m-d H:i:s",
174 strtotime("-" . self::THRESHOLD . "minutes")
175 ), "timestamp") .
176 " OR last_mail IS NULL";
177 if ($page_id) {
178 $sql .= " OR page_id <> " . $ilDB->quote($page_id, "integer");
179 }
180 $sql .= ")";
181 }
182 $set = $ilDB->query($sql);
183 while ($row = $ilDB->fetchAssoc($set)) {
184 $recipients[$row["user_id"]] = $row["user_id"];
185 $log->debug("Adding single subscription: " . $row["user_id"]);
186 }
187 }
188
189 // remove all users that got a mail
190 // see #22773
191 //if ($setting->getMode() !== ilObjNotificationSettings::MODE_DEF_OFF_USER_ACTIVATION && !$ignore_threshold) {
192 if (!$ignore_threshold) {
193 $sql = "SELECT user_id FROM notification" .
194 " WHERE type = " . $ilDB->quote($type, "integer") .
195 " AND id = " . $ilDB->quote($id, "integer") .
196 " AND " . $ilDB->in("user_id", $recipients, false, "integer");
197 $sql .= " AND (last_mail > " . $ilDB->quote(date(
198 "Y-m-d H:i:s",
199 strtotime("-" . self::THRESHOLD . "minutes")
200 ), "timestamp");
201 if ($page_id) {
202 $sql .= " AND page_id = " . $ilDB->quote($page_id, "integer");
203 }
204 $sql .= ")";
205 $set = $ilDB->query($sql);
206 while ($rec = $ilDB->fetchAssoc($set)) {
207 unset($recipients[$rec["user_id"]]);
208 $log->debug("Remove due to got mail: " . $rec["user_id"]);
209 }
210
211 if ($type === self::TYPE_WIKI) {
212 $sql = "SELECT user_id FROM notification" .
213 " WHERE type = " . $ilDB->quote(self::TYPE_WIKI_PAGE, "integer") .
214 " AND id = " . $ilDB->quote($page_id, "integer") .
215 " AND " . $ilDB->in("user_id", $recipients, false, "integer");
216 $sql .= " AND (last_mail > " . $ilDB->quote(date(
217 "Y-m-d H:i:s",
218 strtotime("-" . self::THRESHOLD . "minutes")
219 ), "timestamp");
220 $sql .= ")";
221 $set = $ilDB->query($sql);
222 while ($rec = $ilDB->fetchAssoc($set)) {
223 unset($recipients[$rec["user_id"]]);
224 $log->debug("Remove due to got mail: " . $rec["user_id"]);
225 }
226 }
227 }
228
229
230 return $recipients;
231 }
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
static _getInstanceByObjId(int $a_obj_id)
static _getInstanceByObjId(int $a_obj_id)
Get singleton instance.
static getLogger(string $a_component_id)
Get component logger.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _lookupObjectId(int $ref_id)
static _getAllReferences(int $id)
get all reference ids for object ID
$ref_id
Definition: ltiauth.php:66
$log
Definition: ltiresult.php:34

Referenced by ilExAssignmentReminder\parseGradeReminders(), ilLMPageGUI\processAnswer(), ilLearningModuleNotification\send(), ILIAS\Exercise\Notification\NotificationManager\sendDeadlineRequestNotification(), ilBookCronNotification\sendNotifications(), ilObjPollGUI\sendNotifications(), ilObjDataCollection\sendRecordNotification(), and ILIAS\Exercise\Notification\NotificationManager\sendUploadNotification().

+ Here is the caller graph for this function:

◆ hasNotification()

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

Check notification status for object and user.

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

43 : bool {
44 global $DIC;
45
46 $ilDB = $DIC->database();
47 $tree = $DIC->repositoryTree();
48
49 $notification = false;
50
51 $setting = new ilObjNotificationSettings($id);
53 // check membership, members should be notidifed...
55 $grp_ref_id = $tree->checkForParentType($ref_id, 'grp');
56 if (($grp_ref_id > 0) && ilGroupParticipants::_isParticipant($grp_ref_id, $user_id)) {
57 $notification = true;
58 }
59 $crs_ref_id = $tree->checkForParentType($ref_id, 'crs');
60 if (($crs_ref_id > 0) && ilCourseParticipants::_isParticipant($crs_ref_id, $user_id)) {
61 $notification = true;
62 }
63 }
64
65 if ($notification && $setting->getMode() === ilObjNotificationSettings::MODE_DEF_ON_OPT_OUT) {
66 $set = $ilDB->query("SELECT user_id FROM notification" .
67 " WHERE type = " . $ilDB->quote($type, "integer") .
68 " AND user_id = " . $ilDB->quote($user_id, "integer") .
69 " AND id = " . $ilDB->quote($id, "integer") .
70 " AND activated = " . $ilDB->quote(0, "integer"));
71 $rec = $ilDB->fetchAssoc($set);
72 // if there is no user record, take the default value
73 if (!isset($rec["user_id"])) {
74 return $notification;
75 }
76 // ... except when the opted out
77 return isset($rec["user_id"]) && ((int) $rec["user_id"] !== $user_id);
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(int $a_ref_id, int $a_usr_id)
Static function to check if a user is a participant of the container object.
static _isParticipant(int $a_ref_id, int $a_usr_id)
Static function to check if a user is a participant of the container object.

Referenced by ilObjDataCollectionGUI\addHeaderAction(), ILIAS\Exercise\Settings\SettingsGUI\getEditForm(), ilObjExerciseGUI\getEditFormCustomValues(), ilPollBlockGUI\getHTML(), ilObjContentObjectGUI\getPropertiesFormValues(), and ilObjBookingPoolGUI\initHeaderAction().

+ Here is the caller graph for this function:

◆ hasOptOut()

static ilNotification::hasOptOut ( int  $obj_id)
static

Is opt out (disable notification) allowed?

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

98 : bool
99 {
100 $setting = new ilObjNotificationSettings($obj_id);
101 return $setting->getMode() !== ilObjNotificationSettings::MODE_DEF_ON_NO_OPT_OUT;
102 }

References ilObjNotificationSettings\MODE_DEF_ON_NO_OPT_OUT.

◆ removeForObject()

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

Remove all notifications for given object.

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

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

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

+ Here is the caller graph for this function:

◆ removeForUser()

static ilNotification::removeForUser ( int  $user_id)
static

Remove all notifications for given user.

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

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

Referenced by ilObjUser\delete(), and NotificationTest\testRemoveForUser().

+ Here is the caller graph for this function:

◆ setNotification()

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

Set notification status for object and user.

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

241 : void {
242 global $DIC;
243
244 $ilDB = $DIC->database();
245
246 $fields = array(
247 "type" => array("integer", $type),
248 "user_id" => array("integer", $user_id),
249 "id" => array("integer", $id)
250 );
251 $ilDB->replace("notification", $fields, array("activated" => array("integer", (int) $status)));
252 }

Referenced by ilObjDataCollectionGUI\activateNotification(), ilObjDataCollectionGUI\deactivateNotification(), ilLMPresentationGUI\executeCommand(), ilWikiPageGUI\executeCommand(), ILIAS\Exercise\Settings\SettingsGUI\save(), ilObjBookingPoolGUI\saveNotificationObject(), ilObjContentObjectGUI\saveProperties(), ilObjBlogGUI\setNotification(), ilObjPollGUI\subscribe(), ilObjBibliographicGUI\toggleNotification(), ilObjPollGUI\unsubscribe(), and ilObjExerciseGUI\updateCustom().

+ Here is the caller graph for this function:

◆ updateNotificationTime()

static ilNotification::updateNotificationTime ( int  $type,
int  $id,
array  $user_ids,
?int  $page_id = null,
bool  $activate_new_entries = true 
)
static

Update the last mail timestamp for given object and users.

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

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

References $id, $ilDB, and $user_id.

Referenced by ilLearningModuleNotification\send(), ilObjPollGUI\sendNotifications(), and ilObjDataCollection\sendRecordNotification().

+ Here is the caller graph for this function:

Field Documentation

◆ THRESHOLD

const ilNotification::THRESHOLD = 180

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

◆ TYPE_BLOG

const ilNotification::TYPE_BLOG = 4

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

Referenced by ilObjBlog\doDelete(), and ilObjBlogGUI\setNotification().

◆ TYPE_BOOK

◆ TYPE_DATA_COLLECTION

◆ TYPE_EXERCISE_SUBMISSION

◆ TYPE_LM

const ilNotification::TYPE_LM = 9

◆ TYPE_LM_BLOCKED_USERS

const ilNotification::TYPE_LM_BLOCKED_USERS = 7

◆ TYPE_LM_PAGE

const ilNotification::TYPE_LM_PAGE = 10

◆ TYPE_POLL

const ilNotification::TYPE_POLL = 6

◆ TYPE_WIKI

const ilNotification::TYPE_WIKI = 2

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

Referenced by ilObjWiki\delete(), and ilWikiPageGUI\executeCommand().

◆ TYPE_WIKI_PAGE

const ilNotification::TYPE_WIKI_PAGE = 3

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