ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilNotificationOSDHandler.php
Go to the documentation of this file.
1<?php
2
3require_once 'Services/Notifications/classes/class.ilNotificationSetupHelper.php';
4require_once 'Services/Notifications/classes/class.ilNotificationEchoHandler.php';
5
11{
12 public function notify(ilNotificationObject $notification)
13 {
14 global $ilDB;
15
17
18 $ilDB->insert(
20 array(
21 'notification_osd_id' => array('integer', $id),
22 'usr_id' => array('integer', $notification->user->getId()),
23 'serialized' => array('text', serialize($notification)),
24 'valid_until' => array('integer', $notification->baseNotification->getValidForSeconds() ? ($notification->baseNotification->getValidForSeconds() + time()) : 0),
25 'visible_for' => array('integer', $notification->baseNotification->getVisibleForSeconds() ? $notification->baseNotification->getVisibleForSeconds() : 0),
26 'type' => array('text', $notification->baseNotification->getType()),
27 'time_added' => array('integer', time()),
28 )
29 );
30 }
31
32 public function showSettings($item)
33 {
34 global $lng;
35 $txt = new ilTextInputGUI($lng->txt('polling_intervall'), 'osd_polling_intervall');
36 $txt->setRequired(true);
37 $txt->setInfo($lng->txt('polling_in_seconds'));
38 $txt->setValue('300');
39
40 $item->addSubItem($txt);
41
42 return array('osd_polling_intervall');
43 }
44
45 public static function getNotificationsForUser($user_id, $append_osd_id_to_link = true, $max_age_seconds = 0)
46 {
47 global $ilDB;
48
49 $query = 'SELECT notification_osd_id, serialized, valid_until, visible_for, type FROM ' . ilNotificationSetupHelper::$tbl_notification_osd_handler
50 . ' WHERE usr_id = %s AND (valid_until = 0 OR valid_until > ' . $ilDB->quote(time(), 'integer') . ') AND time_added > %s';
51
52 $types = array('integer', 'integer');
53 $values = array($user_id, $max_age_seconds ? (time() - $max_age_seconds) : 0);
54
55 $rset = $ilDB->queryF($query, $types, $values);
56 $notifications = array();
57
58 while ($row = $ilDB->fetchAssoc($rset)) {
59 $row['data'] = unserialize($row['serialized']);
60 unset($row['serialized']);
61
62 $row['data']->handlerParams = array('general' => $row['data']->handlerParams[''], 'osd' => $row['data']->handlerParams['osd']);
63
64 if ($append_osd_id_to_link) {
65 if ($row['data']->link) {
66 $row['data']->link = self::appendParamToLink($row['data']->link, 'osd_id', $row['notification_osd_id']);
67 }
68
69 $row['data']->shortDescription = self::appendOsdIdToLinks($row['data']->shortDescription, $row['notification_osd_id']);
70 $row['data']->longDescription = self::appendOsdIdToLinks($row['data']->longDescription, $row['notification_osd_id']);
71 }
72 $notifications[] = $row;
73 }
74
76
77 return $notifications;
78 }
79
80 private static function appendOsdIdToLinks($subject, $osd_id)
81 {
82 $matches = array();
83 preg_match_all('/href="(.*?)"/', $subject, $matches);
84 if ($matches[1]) {
85 foreach ($matches[1] as $match) {
86 $match_appended = self::appendParamToLink($match, 'osd_id', $osd_id);
87 $subject = str_replace($match, $match_appended, $subject);
88 }
89 }
90 return $subject;
91 }
92
100 public static function removeNotification($notification_osd_id)
101 {
102 global $ilDB;
103
104 $query = 'SELECT usr_id FROM ' . ilNotificationSetupHelper::$tbl_notification_osd_handler . ' WHERE notification_osd_id = %s';
105 $types = array('integer');
106 $values = array($notification_osd_id);
107
108 $rset = $ilDB->queryF($query, $types, $values);
109
110 if ($row = $ilDB->fetchAssoc($rset)) {
111 $query = 'DELETE FROM ' . ilNotificationSetupHelper::$tbl_notification_osd_handler . ' WHERE notification_osd_id = %s';
112 $types = array('integer');
113 $values = array($notification_osd_id);
114
115 $ilDB->manipulateF($query, $types, $values);
116
117 // sends a "delete the given notification" notification using the
118 // osd_maint channel
119 /*$deletedNotification = new ilNotificationConfig('osd_maint');
120 $deletedNotification->setValidForSeconds(120);
121 $deletedNotification->setTitleVar('deleted');
122 $deletedNotification->setShortDescriptionVar($notification_osd_id);
123 $deletedNotification->setLongDescriptionVar('dummy');
124
125 require_once 'Services/Notifications/classes/class.ilNotificationSystem.php';
126 ilNotificationSystem::sendNotificationToUsers($deletedNotification, array($row['usr_id']));*/
127 }
128 }
129
135 public static function cleanup()
136 {
137 global $ilDB;
138 $query = 'DELETE FROM ' . ilNotificationSetupHelper::$tbl_notification_osd_handler . ' WHERE valid_until < ' . $ilDB->quote(time(), 'integer');
139 $ilDB->manipulate($query);
140 }
141
145 public static function cleanupOnRandom()
146 {
147 $rnd = rand(0, 10000);
148 if ($rnd == 500) {
150 }
151 }
152
161 private static function appendParamToLink($link, $param, $value)
162 {
163 if (strpos($link, '?') !== false) {
164 $link .= '&' . $param . '=' . $value;
165 } else {
166 $link .= '?' . $param . '=' . $value;
167 }
168 return $link;
169 }
170}
An exception for terminatinating execution or to throw for unit testing.
Basic notification handler that dumps basic notification information to stdout.
Notification handler for senden a notification popup to the recipients browser.
static appendOsdIdToLinks($subject, $osd_id)
static removeNotification($notification_osd_id)
Removes a notifcation and triggers a follow up notification to remove the notification from the brows...
static cleanup()
Remove orphaned notifications.
static cleanupOnRandom()
Exec self::clean with a probability of 1%.
notify(ilNotificationObject $notification)
static getNotificationsForUser($user_id, $append_osd_id_to_link=true, $max_age_seconds=0)
static appendParamToLink($link, $param, $value)
Helper to append an additional parameter to an existing url.
A concrete notification based on the ilNotificationConfiguration and returned by ilNotificationConfig...
This class represents a text property in a property form.
$txt
Definition: error.php:11
if(!array_key_exists('StateId', $_REQUEST)) $id
global $lng
Definition: privfeed.php:17
$query
global $ilDB