ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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...
 

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 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

ilNotification:

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

Member Function Documentation

◆ 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.

References $DIC, $id, $ilDB, $row, $tree, $type, ilObject\_getAllReferences(), ilGroupParticipants\_getInstanceByObjId(), ilCourseParticipants\_getInstanceByObjId(), ilObject\_lookupObjectId(), ilObjNotificationSettings\MODE_DEF_OFF_USER_ACTIVATION, ilObjNotificationSettings\MODE_DEF_ON_NO_OPT_OUT, and ilObjNotificationSettings\MODE_DEF_ON_OPT_OUT.

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

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

References $DIC, $id, $ilDB, $tree, $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 ilWikiPageGUI\addHeaderAction(), ilObjDataCollectionGUI\addHeaderAction(), ilObjExerciseGUI\getEditFormCustomValues(), ilPollBlockGUI\getHTML(), ilObjContentObjectGUI\getPropertiesFormValues(), ilObjBookingPoolGUI\initHeaderAction(), and ilObjBlogGUI\initHeaderAction().

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.
$type
global $DIC
Definition: saml.php:7
Handles general object notification settings, see e.g.
if(!array_key_exists('StateId', $_REQUEST)) $id
static _getAllReferences($a_id)
get all reference ids of object
global $ilDB
+ 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.

References ilObjNotificationSettings\MODE_DEF_ON_NO_OPT_OUT.

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

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  }
Handles general object notification settings, see e.g.
+ 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 274 of file class.ilNotification.php.

References $DIC, $id, $ilDB, and $type.

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

275  {
276  global $DIC;
277 
278  $ilDB = $DIC->database();
279 
280  $ilDB->query("DELETE FROM notification" .
281  " WHERE type = " . $ilDB->quote($type, "integer") .
282  " AND id = " . $ilDB->quote($id, "integer"));
283  }
$type
global $DIC
Definition: saml.php:7
if(!array_key_exists('StateId', $_REQUEST)) $id
global $ilDB
+ 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 290 of file class.ilNotification.php.

References $DIC, and $ilDB.

Referenced by ilObjUser\delete().

291  {
292  global $DIC;
293 
294  $ilDB = $DIC->database();
295 
296  $ilDB->query("DELETE FROM notification" .
297  " WHERE user_id = " . $ilDB->quote($user_id, "integer"));
298  }
global $DIC
Definition: saml.php:7
global $ilDB
+ 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 226 of file class.ilNotification.php.

References $DIC, $id, $ilDB, and $type.

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

227  {
228  global $DIC;
229 
230  $ilDB = $DIC->database();
231 
232  $fields = array(
233  "type" => array("integer", $type),
234  "user_id" => array("integer", $user_id),
235  "id" => array("integer", $id)
236  );
237  $ilDB->replace("notification", $fields, array("activated" => array("integer", (int) $status)));
238  }
$type
global $DIC
Definition: saml.php:7
if(!array_key_exists('StateId', $_REQUEST)) $id
global $ilDB
+ 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 248 of file class.ilNotification.php.

References $DIC, $id, $ilDB, and $type.

Referenced by ilObjDataCollection\doUpdate(), ilWikiUtil\sendNotification(), ilObjBlog\sendNotification(), and ilObjPollGUI\sendNotifications().

249  {
250  global $DIC;
251 
252  $ilDB = $DIC->database();
253 
254  $sql = "UPDATE notification" .
255  " SET last_mail = " . $ilDB->quote(date("Y-m-d H:i:s"), "timestamp");
256 
257  if ($page_id) {
258  $sql .= ", page_id = " . $ilDB->quote($page_id, "integer");
259  }
260 
261  $sql .= " WHERE type = " . $ilDB->quote($type, "integer") .
262  " AND id = " . $ilDB->quote($id, "integer") .
263  " AND " . $ilDB->in("user_id", $user_ids, false, "integer");
264 
265  $ilDB->query($sql);
266  }
$type
global $DIC
Definition: saml.php:7
if(!array_key_exists('StateId', $_REQUEST)) $id
global $ilDB
+ 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

◆ TYPE_EXERCISE_SUBMISSION

◆ TYPE_LM_BLOCKED_USERS

const ilNotification::TYPE_LM_BLOCKED_USERS = 7

◆ TYPE_POLL

const ilNotification::TYPE_POLL = 6

◆ TYPE_WIKI

◆ TYPE_WIKI_PAGE


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