ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
ILIAS\Notifications\ilNotificationSystem Class Reference
+ Collaboration diagram for ILIAS\Notifications\ilNotificationSystem:

Public Member Functions

 __construct (?ilRbacReview $rbacReview=null, ?ilLogger $logger=null)
 
 toUsers (ilNotificationConfig $notification, array $users, bool $process_async=false)
 
 clear (string $channel='')
 

Static Public Member Functions

static sendNotificationToUsers (ilNotificationConfig $notification, array $users, bool $processAsync=false)
 
static sendNotificationToListeners (ilNotificationConfig $notification, int $ref_id, bool $processAsync=false)
 
static sendNotificationToRoles (ilNotificationConfig $notification, array $roles, bool $processAsync=false)
 
static enableListeners (string $module, int $ref_id)
 
static enableUserListeners (string $module, int $ref_id, array $users)
 

Private Member Functions

 addHandler (string $channel, ilNotificationHandler $handler)
 
 toListeners (ilNotificationConfig $notification, int $ref_id, bool $process_async=false)
 
 toRoles (ilNotificationConfig $notification, array $roles, bool $process_async=false)
 

Private Attributes

array $handler = []
 
string $defaultLanguage = 'en'
 
readonly ilRbacReview $rbacReview
 
readonly ilLogger $logger
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

ILIAS\Notifications\ilNotificationSystem::__construct ( ?ilRbacReview  $rbacReview = null,
?ilLogger  $logger = null 
)

Definition at line 40 of file ilNotificationSystem.php.

References $DIC, ILIAS\Notifications\ilNotificationSystem\$logger, ILIAS\Notifications\ilNotificationSystem\$rbacReview, ILIAS\Notifications\ilNotificationSystem\addHandler(), ILIAS\Repository\logger(), and null.

41  {
42  $this->addHandler('osd', new ilNotificationOSDHandler());
43  $this->addHandler('mail', new ilNotificationMailHandler());
44 
45  if ($rbacReview === null) {
46  global $DIC;
47  $rbacReview = $DIC->rbac()->review();
48  }
49  $this->rbacReview = $rbacReview;
50 
51  if ($logger === null) {
52  global $DIC;
53  $logger = $DIC->logger()->nota();
54  }
55  $this->logger = $logger;
56  }
addHandler(string $channel, ilNotificationHandler $handler)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
global $DIC
Definition: shib_login.php:26
+ Here is the call graph for this function:

Member Function Documentation

◆ addHandler()

ILIAS\Notifications\ilNotificationSystem::addHandler ( string  $channel,
ilNotificationHandler  $handler 
)
private

Definition at line 58 of file ilNotificationSystem.php.

References ILIAS\Notifications\ilNotificationSystem\$handler.

Referenced by ILIAS\Notifications\ilNotificationSystem\__construct().

58  : void
59  {
60  if (!array_key_exists($channel, $this->handler)) {
61  $this->handler[$channel] = [];
62  }
63 
64  $this->handler[$channel][] = $handler;
65  }
+ Here is the caller graph for this function:

◆ clear()

ILIAS\Notifications\ilNotificationSystem::clear ( string  $channel = '')

Definition at line 232 of file ilNotificationSystem.php.

References $c, and ILIAS\Notifications\ilNotificationSystem\$handler.

232  : void
233  {
234  $channels = $this->handler;
235  if ($channel !== '') {
236  $channels = [$this->handler[$channel]] ?? [];
237  }
238  foreach ($channels as $c) {
239  foreach ($c as $handler) {
240  $handler->clear();
241  }
242  }
243  }
$c
Definition: deliver.php:25

◆ enableListeners()

static ILIAS\Notifications\ilNotificationSystem::enableListeners ( string  $module,
int  $ref_id 
)
static

Definition at line 217 of file ilNotificationSystem.php.

References ILIAS\Notifications\ilNotificationDatabaseHandler\enableListeners().

217  : void
218  {
220  }
$ref_id
Definition: ltiauth.php:65
static enableListeners(string $module, int $sender_id, array $users=[])
+ Here is the call graph for this function:

◆ enableUserListeners()

static ILIAS\Notifications\ilNotificationSystem::enableUserListeners ( string  $module,
int  $ref_id,
array  $users 
)
static
Parameters
list<int>$users

Definition at line 225 of file ilNotificationSystem.php.

References ILIAS\Notifications\ilNotificationDatabaseHandler\enableListeners().

225  : void
226  {
227  if ($users) {
229  }
230  }
$ref_id
Definition: ltiauth.php:65
static enableListeners(string $module, int $sender_id, array $users=[])
+ Here is the call graph for this function:

◆ sendNotificationToListeners()

static ILIAS\Notifications\ilNotificationSystem::sendNotificationToListeners ( ilNotificationConfig  $notification,
int  $ref_id,
bool  $processAsync = false 
)
static

Definition at line 196 of file ilNotificationSystem.php.

References $DIC.

Referenced by ILIAS\Notifications\Model\ilNotificationConfig\notifyByListeners().

200  : void {
201  global $DIC;
202  $DIC->notifications()->system()->toListeners($notification, $ref_id, $processAsync);
203  }
$ref_id
Definition: ltiauth.php:65
global $DIC
Definition: shib_login.php:26
+ Here is the caller graph for this function:

◆ sendNotificationToRoles()

static ILIAS\Notifications\ilNotificationSystem::sendNotificationToRoles ( ilNotificationConfig  $notification,
array  $roles,
bool  $processAsync = false 
)
static
Parameters
list<int>$roles

Definition at line 208 of file ilNotificationSystem.php.

References $DIC.

Referenced by ILIAS\Notifications\Model\ilNotificationConfig\notifyByRoles().

212  : void {
213  global $DIC;
214  $DIC->notifications()->system()->toRoles($notification, $roles, $processAsync);
215  }
global $DIC
Definition: shib_login.php:26
+ Here is the caller graph for this function:

◆ sendNotificationToUsers()

static ILIAS\Notifications\ilNotificationSystem::sendNotificationToUsers ( ilNotificationConfig  $notification,
array  $users,
bool  $processAsync = false 
)
static
Deprecated:
Parameters
list<int>$users

Definition at line 187 of file ilNotificationSystem.php.

References $DIC.

Referenced by ILIAS\Notifications\Model\ilNotificationConfig\notifyByUsers().

191  : void {
192  global $DIC;
193  $DIC->notifications()->system()->toUsers($notification, $users, $processAsync);
194  }
global $DIC
Definition: shib_login.php:26
+ Here is the caller graph for this function:

◆ toListeners()

ILIAS\Notifications\ilNotificationSystem::toListeners ( ilNotificationConfig  $notification,
int  $ref_id,
bool  $process_async = false 
)
private

Definition at line 157 of file ilNotificationSystem.php.

References $ref_id, ILIAS\Notifications\ilNotificationDatabaseHandler\disableListeners(), ILIAS\Notifications\ilNotificationDatabaseHandler\enqueueByListener(), ILIAS\Notifications\Model\ilNotificationConfig\getType(), ILIAS\Notifications\ilNotificationDatabaseHandler\getUsersByListener(), and ILIAS\Notifications\Model\ilNotificationConfig\hasDisableAfterDeliverySet().

157  : void
158  {
159  if ($process_async === false) {
160  $users = ilNotificationDatabaseHandler::getUsersByListener($notification->getType(), $ref_id);
161  if ($notification->hasDisableAfterDeliverySet()) {
162  ilNotificationDatabaseHandler::disableListeners($notification->getType(), $ref_id);
163  }
164  } else {
166  }
167  }
static enqueueByListener(ilNotificationConfig $notification, int $ref_id)
$ref_id
Definition: ltiauth.php:65
+ Here is the call graph for this function:

◆ toRoles()

ILIAS\Notifications\ilNotificationSystem::toRoles ( ilNotificationConfig  $notification,
array  $roles,
bool  $process_async = false 
)
private
Parameters
list<int>$roles

Definition at line 172 of file ilNotificationSystem.php.

References ILIAS\Notifications\ilNotificationSystem\toUsers().

172  : void
173  {
174  $users = [];
175  foreach ($roles as $role) {
176  $users[] = $this->rbacReview->assignedUsers($role);
177  }
178  $users = array_unique(array_merge(...$users));
179 
180  $this->toUsers($notification, $users, $process_async);
181  }
toUsers(ilNotificationConfig $notification, array $users, bool $process_async=false)
+ Here is the call graph for this function:

◆ toUsers()

ILIAS\Notifications\ilNotificationSystem::toUsers ( ilNotificationConfig  $notification,
array  $users,
bool  $process_async = false 
)
Parameters
list<int>$users

Definition at line 70 of file ilNotificationSystem.php.

References $data, ILIAS\Notifications\ilNotificationSystem\$handler, $lang, ILIAS\Notifications\ilNotificationDatabaseHandler\enqueueByUsers(), ILIAS\Notifications\ilNotificationDatabaseHandler\getAvailableChannels(), ILIAS\Notifications\ilNotificationDatabaseHandler\getAvailableTypes(), ILIAS\Notifications\Model\ilNotificationConfig\getIdentification(), ilObjectFactory\getInstanceByObjId(), ILIAS\Notifications\Model\ilNotificationConfig\getLanguageParameters(), ILIAS\Notifications\ilNotificationDatabaseHandler\getTranslatedLanguageVariablesOfNotificationParameters(), ILIAS\Notifications\Model\ilNotificationConfig\getType(), ILIAS\Notifications\Model\ilNotificationConfig\getUserInstance(), ILIAS\Notifications\ilNotificationDatabaseHandler\getUsersWithCustomConfig(), ILIAS\Notifications\ilNotificationDatabaseHandler\loadUserConfig(), and ILIAS\Repository\logger().

Referenced by ILIAS\Notifications\ilNotificationSystem\toRoles().

70  : void
71  {
72  $this->logger->debug(
73  'Sending notification to users {users}: {notification_type} / {id} / {id_type}',
74  [
75  'users' => $users,
76  'notification_type' => $notification->getType(),
77  'id' => (string) $notification->getIdentification(),
78  'id_type' => $notification->getIdentification()->getType(),
79  ]
80  );
81 
82  if ($process_async === false) {
84  $usersWithCustomConfig = ilNotificationDatabaseHandler::getUsersWithCustomConfig($users);
88  $notification->getLanguageParameters()
89  );
90 
91  $user_by_handler = [];
92  if (isset($types[$notification->getType()]['config_type'])) {
93  if ($types[$notification->getType()]['config_type'] === 'set_by_user') {
94  $it = new ilNotificationUserIterator($notification->getType(), $users);
95  $channelsByAdmin = false;
96  foreach ($it as $usr_id => $data) {
97  if (!isset($channels[$data['channel']])) {
98  continue;
99  }
100  if (!isset($user_by_handler[$data['channel']])) {
101  $user_by_handler[$data['channel']] = [];
102  }
103  $user_by_handler[$data['channel']][] = $usr_id;
104  }
105  } elseif ($types[$notification->getType()]['config_type'] !== 'disabled') {
106  $channelsByAdmin = true;
107  if (isset($adminConfig[$notification->getType()])) {
108  foreach ($adminConfig[$notification->getType()] as $channel) {
109  if (!isset($channels[$channel]) || !$channels[$channel]) {
110  continue;
111  }
112  $user_by_handler[$channel] = $users;
113  }
114  }
115  }
116  }
117 
118  $this->logger->debug(
119  'User by handler: {user_by_handler}',
120  [
121  'user_by_handler' => $user_by_handler
122  ]
123  );
124 
125  $userCache = [];
126 
127  foreach ($user_by_handler as $handler => $h_users) {
128  $handler = $this->handler[$handler];
129  foreach ($h_users as $userId) {
130  if (!isset($userCache[$userId])) {
131  $user = ilObjectFactory::getInstanceByObjId($userId, false);
132  if (!($user instanceof ilObjUser)) {
133  continue;
134  }
135  $userCache[$userId] = $user;
136  }
137  $user = $userCache[$userId];
138 
139  $instance = $notification->getUserInstance($user, $lang, $this->defaultLanguage);
140  foreach ($handler as $h) {
141  $this->logger->debug(
142  'Notify {user} by calling handler {handler}',
143  [
144  'user' => $user->getId(),
145  'handler' => get_class($h),
146  ]
147  );
148  $h->notify($instance);
149  }
150  }
151  }
152  } else {
153  ilNotificationDatabaseHandler::enqueueByUsers($notification, $users);
154  }
155  }
static getAvailableChannels(array $config_types=[], bool $include_disabled=false)
$lang
Definition: xapiexit.php:25
static getInstanceByObjId(?int $obj_id, bool $stop_on_error=true)
get an instance of an Ilias object by object id
static enqueueByUsers(ilNotificationConfig $notification, array $usr_ids)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $defaultLanguage

string ILIAS\Notifications\ilNotificationSystem::$defaultLanguage = 'en'
private

Definition at line 36 of file ilNotificationSystem.php.

◆ $handler

array ILIAS\Notifications\ilNotificationSystem::$handler = []
private

◆ $logger

readonly ilLogger ILIAS\Notifications\ilNotificationSystem::$logger
private

◆ $rbacReview

readonly ilRbacReview ILIAS\Notifications\ilNotificationSystem::$rbacReview
private

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