ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ILIAS\Notifications\Repository\ilNotificationOSDRepository Class Reference
+ Inheritance diagram for ILIAS\Notifications\Repository\ilNotificationOSDRepository:
+ Collaboration diagram for ILIAS\Notifications\Repository\ilNotificationOSDRepository:

Public Member Functions

 __construct (?ilDBInterface $database=null)
 
 createOSDNotification (int $user_id, ilNotificationObject $object)
 
 ifOSDNotificationExistsById (int $id)
 
 getOSDNotificationsByUser (int $user_id, int $max_age_seconds=0, string $type='')
 
 deleteOSDNotificationById (int $id)
 
 deleteOSDNotificationByIdentification (string $povider_type, string $identification, int $user_id=0)
 
 deleteStaleOSDNotificationsForUserAndType (string $povider_type, int $user_id, int $until_timestamp)
 
 deleteAllOSDNotifications ()
 
- Public Member Functions inherited from ILIAS\Notifications\Repository\ilNotificationOSDRepositoryInterface
 __construct ()
 
 createOSDNotification (int $user_id, ilNotificationObject $object)
 
 ifOSDNotificationExistsById (int $id)
 
 getOSDNotificationsByUser (int $user_id)
 
 deleteOSDNotificationById (int $id)
 

Private Member Functions

 getCurrentUnixTimestamp ()
 
 deleteOSDNotificationByUserAndType (int $user_id, string $type)
 

Private Attributes

const UNIQUE_TYPES
 
readonly ilDBInterface $database
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

ILIAS\Notifications\Repository\ilNotificationOSDRepository::__construct ( ?ilDBInterface  $database = null)

Definition at line 44 of file ilNotificationOSDRepository.php.

45 {
46 if ($database === null) {
47 global $DIC;
48 $database = $DIC->database();
49 }
50 $this->database = $database;
51 }
global $DIC
Definition: shib_login.php:26

References ILIAS\Notifications\Repository\ilNotificationOSDRepository\$database, $DIC, and ILIAS\Repository\database().

+ Here is the call graph for this function:

Member Function Documentation

◆ createOSDNotification()

ILIAS\Notifications\Repository\ilNotificationOSDRepository::createOSDNotification ( int  $user_id,
ilNotificationObject  $object 
)

Implements ILIAS\Notifications\Repository\ilNotificationOSDRepositoryInterface.

Definition at line 58 of file ilNotificationOSDRepository.php.

58 : ?ilOSDNotificationObject
59 {
61 $base = $object->baseNotification;
62 $now = $this->getCurrentUnixTimestamp();
63
64 $notification = new ilOSDNotificationObject(
65 $id,
67 $object,
68 $now,
69 $base->getValidForSeconds() ? $base->getValidForSeconds() + $now : 0,
70 $base->getVisibleForSeconds(),
71 $base->getType(),
72 $base->getIdentification()
73 );
74
75 if (in_array($notification->getType(), self::UNIQUE_TYPES)) {
76 $this->deleteOSDNotificationByUserAndType($user_id, $notification->getType());
77 }
78
79 $affected = $this->database->insert(
81 [
82 'notification_osd_id' => [ilDBConstants::T_INTEGER, $notification->getId()],
83 'usr_id' => [ilDBConstants::T_INTEGER, $notification->getUser()],
84 'serialized' => [ilDBConstants::T_TEXT, serialize($notification->getObject())],
85 'valid_until' => [ilDBConstants::T_INTEGER, $notification->getValidUntil()],
86 'visible_for' => [ilDBConstants::T_INTEGER, $notification->getVisibleFor()],
87 'type' => [ilDBConstants::T_TEXT, $notification->getType()],
88 'time_added' => [ilDBConstants::T_INTEGER, $notification->getTimeAdded()],
89 'identification' => [ilDBConstants::T_TEXT, (string) $notification->getIdentification()]
90 ]
91 );
92
93 return ($affected === 1) ? $notification : null;
94 }
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23

References $id, ILIAS\Notifications\ilNotificationSetupHelper\$tbl_notification_osd_handler, $user_id, ILIAS\Repository\database(), ILIAS\Notifications\Repository\ilNotificationOSDRepository\deleteOSDNotificationByUserAndType(), ILIAS\Notifications\Repository\ilNotificationOSDRepository\getCurrentUnixTimestamp(), ilDBConstants\T_INTEGER, and ilDBConstants\T_TEXT.

+ Here is the call graph for this function:

◆ deleteAllOSDNotifications()

ILIAS\Notifications\Repository\ilNotificationOSDRepository::deleteAllOSDNotifications ( )

Definition at line 200 of file ilNotificationOSDRepository.php.

200 : void
201 {
202 $this->database->manipulate('TRUNCATE TABLE ' . ilNotificationSetupHelper::$tbl_notification_osd_handler);
203 }

References ILIAS\Notifications\ilNotificationSetupHelper\$tbl_notification_osd_handler, and ILIAS\Repository\database().

+ Here is the call graph for this function:

◆ deleteOSDNotificationById()

ILIAS\Notifications\Repository\ilNotificationOSDRepository::deleteOSDNotificationById ( int  $id)

◆ deleteOSDNotificationByIdentification()

ILIAS\Notifications\Repository\ilNotificationOSDRepository::deleteOSDNotificationByIdentification ( string  $povider_type,
string  $identification,
int  $user_id = 0 
)

Definition at line 177 of file ilNotificationOSDRepository.php.

177 : bool
178 {
179 $query = 'DELETE FROM ' . ilNotificationSetupHelper::$tbl_notification_osd_handler . ' WHERE type = %s AND identification = %s';
181 $values = [$povider_type, $identification];
182 if ($user_id > 0) {
183 $query .= ' AND user_id = %s';
184 $keys[] = ilDBConstants::T_INTEGER;
185 $values[] = $user_id;
186 }
187 return (1 === $this->database->manipulateF($query, $keys, $values));
188 }

References ILIAS\Notifications\ilNotificationSetupHelper\$tbl_notification_osd_handler, $user_id, ILIAS\Repository\database(), ilDBConstants\T_INTEGER, and ilDBConstants\T_TEXT.

+ Here is the call graph for this function:

◆ deleteOSDNotificationByUserAndType()

ILIAS\Notifications\Repository\ilNotificationOSDRepository::deleteOSDNotificationByUserAndType ( int  $user_id,
string  $type 
)
private

Definition at line 167 of file ilNotificationOSDRepository.php.

167 : void
168 {
169 $query = 'DELETE FROM ' . ilNotificationSetupHelper::$tbl_notification_osd_handler . ' WHERE usr_id = %s AND type = %s';
170 $this->database->manipulateF(
171 $query,
173 [$user_id, $type]
174 );
175 }

References ILIAS\Notifications\ilNotificationSetupHelper\$tbl_notification_osd_handler, $user_id, ILIAS\Repository\database(), ilDBConstants\T_INTEGER, and ilDBConstants\T_TEXT.

Referenced by ILIAS\Notifications\Repository\ilNotificationOSDRepository\createOSDNotification().

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

◆ deleteStaleOSDNotificationsForUserAndType()

ILIAS\Notifications\Repository\ilNotificationOSDRepository::deleteStaleOSDNotificationsForUserAndType ( string  $povider_type,
int  $user_id,
int  $until_timestamp 
)

Definition at line 190 of file ilNotificationOSDRepository.php.

190 : void
191 {
192 $query = 'DELETE FROM ' . ilNotificationSetupHelper::$tbl_notification_osd_handler . ' WHERE type = %s AND usr_id = %s AND time_added < %s';
193 $this->database->manipulateF(
194 $query,
196 [$povider_type, $user_id, $until_timestamp]
197 );
198 }

References ILIAS\Notifications\ilNotificationSetupHelper\$tbl_notification_osd_handler, $user_id, ILIAS\Repository\database(), ilDBConstants\T_INTEGER, and ilDBConstants\T_TEXT.

+ Here is the call graph for this function:

◆ getCurrentUnixTimestamp()

ILIAS\Notifications\Repository\ilNotificationOSDRepository::getCurrentUnixTimestamp ( )
private

Definition at line 53 of file ilNotificationOSDRepository.php.

53 : int
54 {
55 return time(); // Should be replace by the consumption of the `Clock` interface
56 }

Referenced by ILIAS\Notifications\Repository\ilNotificationOSDRepository\createOSDNotification(), and ILIAS\Notifications\Repository\ilNotificationOSDRepository\getOSDNotificationsByUser().

+ Here is the caller graph for this function:

◆ getOSDNotificationsByUser()

ILIAS\Notifications\Repository\ilNotificationOSDRepository::getOSDNotificationsByUser ( int  $user_id,
int  $max_age_seconds = 0,
string  $type = '' 
)

Definition at line 105 of file ilNotificationOSDRepository.php.

105 : array
106 {
107 $now = $this->getCurrentUnixTimestamp();
108
109 if ($max_age_seconds === 0) {
110 $max_age_seconds = $now;
111 }
112
113 $query =
115 ' WHERE usr_id = %s AND (valid_until = 0 OR valid_until > %s) AND time_added > %s';
116
118 $values = [$user_id, $now, $now - $max_age_seconds];
119
120 if ($type !== '') {
121 $query .= ' AND type = %s';
122 $types[] = ilDBConstants::T_TEXT;
123 $values[] = $type;
124 }
125
126 $rset = $this->database->queryF($query, $types, $values);
127 $notifications = [];
128
129 while ($row = $this->database->fetchAssoc($rset)) {
130 $object = unserialize(
131 $row['serialized'],
132 ['allowed_classes' => [ilNotificationObject::class, ilNotificationLink::class, ilNotificationParameter::class]]
133 );
134 if (isset($object->handlerParams[''], $object->handlerParams['osd'])) {
135 $object->handlerParams = [
136 'general' => $object->handlerParams[''],
137 'osd' => $object->handlerParams['osd']
138 ];
139 }
140 $notification = new ilOSDNotificationObject(
141 (int) $row['notification_osd_id'],
142 (int) $row['usr_id'],
143 $object,
144 (int) $row['time_added'],
145 (int) $row['valid_until'],
146 (int) $row['visible_for'],
147 $row['type'],
148 new NotificationIdentification($row['type'], $row['identification'])
149 );
150
151 $notifications[] = $notification;
152 }
153
154 return $notifications;
155 }

References ILIAS\Notifications\ilNotificationSetupHelper\$tbl_notification_osd_handler, $user_id, ILIAS\Repository\database(), ILIAS\Notifications\Repository\ilNotificationOSDRepository\getCurrentUnixTimestamp(), ilDBConstants\T_INTEGER, and ilDBConstants\T_TEXT.

+ Here is the call graph for this function:

◆ ifOSDNotificationExistsById()

ILIAS\Notifications\Repository\ilNotificationOSDRepository::ifOSDNotificationExistsById ( int  $id)

Implements ILIAS\Notifications\Repository\ilNotificationOSDRepositoryInterface.

Definition at line 96 of file ilNotificationOSDRepository.php.

96 : bool
97 {
98 $query = 'SELECT count(*) AS count FROM ' . ilNotificationSetupHelper::$tbl_notification_osd_handler . ' WHERE notification_osd_id = %s';
99 $result = $this->database->queryF($query, [ilDBConstants::T_INTEGER], [$id]);
100 $row = $this->database->fetchAssoc($result);
101
102 return ((int) ($row['count'] ?? 0)) === 1;
103 }

References $id, ILIAS\Notifications\ilNotificationSetupHelper\$tbl_notification_osd_handler, ILIAS\Repository\database(), and ilDBConstants\T_INTEGER.

Referenced by ILIAS\Notifications\Repository\ilNotificationOSDRepository\deleteOSDNotificationById().

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

Field Documentation

◆ $database

readonly ilDBInterface ILIAS\Notifications\Repository\ilNotificationOSDRepository::$database
private

◆ UNIQUE_TYPES

const ILIAS\Notifications\Repository\ilNotificationOSDRepository::UNIQUE_TYPES
private
Initial value:
= [
'who_is_online'
]

Definition at line 38 of file ilNotificationOSDRepository.php.


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