19declare(strict_types=1);
51 $this->db =
$DIC->database();
52 $this->
user = $DIC->user();
53 $this->forum_id =
$DIC[
'ilObjDataCache']->lookupObjId(
$ref_id);
58 $this->notification_id = $a_notification_id;
68 $this->user_id = $a_user_id;
78 $this->forum_id = $a_forum_id;
88 $this->thread_id = $a_thread_id;
108 $this->admin_force = $a_admin_force;
118 $this->user_toggle = $a_user_toggle;
128 $this->ref_id = $a_ref_id;
139 $this->user_id_noti = $a_user_id_noti;
150 $res = $this->db->queryF(
152 SELECT admin_force_noti FROM frm_notification
155 AND user_id_noti > %s ',
156 [
'integer',
'integer',
'integer'],
160 if ($row = $this->db->fetchAssoc(
$res)) {
161 return (
bool) $row[
'admin_force_noti'];
169 $res = $this->db->queryF(
171 SELECT user_toggle_noti FROM frm_notification
174 AND user_id_noti > %s',
175 [
'integer',
'integer',
'integer'],
179 if ($row = $this->db->fetchAssoc(
$res)) {
180 return (
bool) $row[
'user_toggle_noti'];
187 $next_id = $this->db->nextId(
'frm_notification');
190 $this->db->manipulateF(
192 INSERT INTO frm_notification
193 (notification_id, user_id, frm_id, admin_force_noti, user_toggle_noti, interested_events, user_id_noti)
194 VALUES(%s, %s, %s, %s, %s, %s, %s)',
195 [
'integer',
'integer',
'integer',
'integer',
'integer',
'integer',
'integer'],
210 $this->db->manipulateF(
212 DELETE FROM frm_notification
215 AND admin_force_noti = %s
216 AND user_id_noti > %s',
217 [
'integer',
'integer',
'integer',
'integer'],
224 $this->db->manipulateF(
226 DELETE FROM frm_notification
229 AND admin_force_noti = %s
230 AND user_toggle_noti = %s
231 AND user_id_noti > %s',
232 [
'integer',
'integer',
'integer',
'integer',
'integer'],
239 $this->db->manipulateF(
240 'UPDATE frm_notification SET user_toggle_noti = %s WHERE user_id = %s AND frm_id = %s AND admin_force_noti = %s',
241 [
'integer',
'integer',
'integer',
'integer'],
254 $ilUser =
$DIC->user();
258 foreach ($node_data as
$data) {
264 $frm_noti->setUserId($ilUser->getId());
268 if ($properties->isAdminForceNoti() || $properties->isUserToggleNoti()) {
269 if ($properties->isAdminForceNoti()) {
270 $frm_noti->setInterestedEvents($properties->getInterestedEvents());
273 $frm_noti->setAdminForce($properties->isAdminForceNoti());
274 $frm_noti->setUserToggle($properties->isUserToggleNoti());
275 $frm_noti->setForumId($properties->getObjId());
276 if (!$frm_noti->existsNotification()) {
277 $frm_noti->insertAdminForce();
287 $ilUser =
$DIC->user();
291 foreach ($node_data as
$data) {
294 $moderator_ids = $objFrmMods->getCurrentModerators();
299 $frm_noti->setUserId($ilUser->getId());
302 $frm_noti->setForumId((
int)
$data[
'obj_id']);
303 if (!in_array($frm_noti->getUserId(), $moderator_ids,
true)) {
304 $frm_noti->deleteAdminForce();
313 if (!array_key_exists(
$ref_id, self::$node_data_cache)) {
314 $container_node =
$DIC->repositoryTree()->getNodeData(
$ref_id);
315 if (!isset($container_node[
'child'])) {
319 $node_data =
$DIC->repositoryTree()->getSubTree(
324 $node_data = array_filter($node_data,
static function (array $forum_node) use (
$DIC,
$ref_id):
bool {
326 foreach (
$DIC->repositoryTree()->getNodePath((
int) $forum_node[
'child'],
$ref_id) as $path_node) {
327 $notRootNode = (int) $path_node[
'child'] !== $ref_id;
328 $isGroup = $path_node[
'type'] ===
'grp';
329 if ($notRootNode && $isGroup) {
336 self::$node_data_cache[
$ref_id] = $node_data;
339 return self::$node_data_cache[
$ref_id];
342 public static function _clearForcedForumNotifications(array $move_tree_event): void
347 if ($move_tree_event[
'tree'] !==
'tree') {
353 if ($source_forum->isParentMembershipEnabledContainer()) {
355 'DELETE FROM frm_notification WHERE frm_id = %s AND admin_force_noti = %s',
356 [
'integer',
'integer'],
357 [$source_forum->getId(), 1]
364 $this->db->manipulateF(
365 'UPDATE frm_notification SET admin_force_noti = %s, user_toggle_noti = %s, ' .
366 'interested_events = %s WHERE user_id = %s AND frm_id = %s',
367 [
'integer',
'integer',
'integer',
'integer',
'integer'],
369 (
int) $this->getAdminForce(),
370 (
int) $this->getUserToggle(),
371 $this->getInterestedEvents(),
372 (
int) $this->getUserId(),
380 $this->db->manipulateF(
381 'DELETE FROM frm_notification WHERE frm_id = %s AND user_id_noti > %s',
382 [
'integer',
'integer'],
383 [$this->getForumId(), 0]
394 $res = $this->db->queryF(
'SELECT * FROM frm_notification WHERE frm_id = %s', [
'integer'], [$this->getForumId()]);
395 while ($row = $this->db->fetchAssoc(
$res)) {
396 $result[(
int) $row[
'user_id']][
'notification_id'] = (
int) $row[
'notification_id'];
397 $result[(
int) $row[
'user_id']][
'user_id'] = (
int) $row[
'user_id'];
398 $result[(
int) $row[
'user_id']][
'frm_id'] = (
int) $row[
'frm_id'];
399 $result[(
int) $row[
'user_id']][
'thread_id'] = (
int) $row[
'thread_id'];
400 $result[(
int) $row[
'user_id']][
'admin_force_noti'] = (
int) $row[
'admin_force_noti'];
401 $result[(
int) $row[
'user_id']][
'user_toggle_noti'] = (
int) $row[
'user_toggle_noti'];
402 $result[(
int) $row[
'user_id']][
'interested_events'] = (
int) $row[
'interested_events'];
403 $result[(
int) $row[
'user_id']][
'user_id_noti'] = (
int) $row[
'user_id_noti'];
416 'SELECT notification_id, user_id FROM frm_notification WHERE frm_id = %s AND thread_id = %s ORDER BY user_id ASC',
417 [
'integer',
'integer'],
418 [0, $merge_source_thread_id]
421 $res_2 =
$ilDB->queryF(
422 'SELECT DISTINCT user_id FROM frm_notification WHERE frm_id = %s AND thread_id = %s ORDER BY user_id ASC',
423 [
'integer',
'integer'],
424 [0, $merge_target_thread_id]
427 $users_already_notified = [];
428 while ($users_row =
$ilDB->fetchAssoc($res_2)) {
429 $users_already_notified[(
int) $users_row[
'user_id']] = (
int) $users_row[
'user_id'];
433 if (isset($users_already_notified[(
int) $row[
'user_id']])) {
435 'DELETE FROM frm_notification WHERE notification_id = %s',
437 [$row[
'notification_id']]
442 [
'thread_id' => [
'integer', $merge_target_thread_id]],
443 [
'thread_id' => [
'integer', $merge_source_thread_id]]
451 $res = $this->db->queryF(
452 'SELECT user_id FROM frm_notification WHERE user_id = %s AND frm_id = %s AND admin_force_noti = %s',
453 [
'integer',
'integer',
'integer'],
454 [(
int) $this->getUserId(), $this->getForumId(), (
int) $this->getAdminForce()]
457 return $this->db->numRows(
$res) > 0;
462 $sourceNotificationSettings =
new self($sourceRefId);
463 $records = $sourceNotificationSettings->read();
465 foreach ($records as $usrId => $row) {
466 $this->setUserId($usrId);
467 $this->setAdminForce((
bool) $row[
'admin_force_noti']);
468 $this->setUserToggle((
bool) $row[
'user_toggle_noti']);
469 $this->setUserIdNoti((
int) $row[
'user_id_noti']);
470 $this->setInterestedEvents((
int) $row[
'interested_events']);
472 $this->insertAdminForce();
478 $this->db->manipulateF(
479 'UPDATE frm_notification SET interested_events = %s WHERE user_id = %s AND frm_id = %s',
480 [
'integer',
'integer',
'integer'],
481 [$this->getInterestedEvents(), (
int) $this->getUserId(), $this->getForumId()]
489 $this->db->setLimit(1);
490 $res = $this->db->queryF(
491 'SELECT interested_events FROM frm_notification WHERE user_id = %s AND frm_id = %s',
492 [
'integer',
'integer'],
493 [(
int) $this->getUserId(), $this->getForumId()]
496 while ($row = $this->db->fetchAssoc(
$res)) {
497 $interested_events = (
int) $row[
'interested_events'];
500 return $interested_events;
508 $res = $this->db->queryF(
509 'SELECT * FROM frm_notification WHERE admin_force_noti = %s AND frm_id = %s',
510 [
'integer',
'integer'],
514 while ($row = $this->db->fetchAssoc(
$res)) {
516 $notificationConfig->setNotificationId((
int) $row[
'notification_id']);
517 $notificationConfig->setUserId((
int) $row[
'user_id']);
518 $notificationConfig->setForumId((
int) $row[
'frm_id']);
519 $notificationConfig->setAdminForce((
bool) $row[
'admin_force_noti']);
520 $notificationConfig->setUserToggle((
bool) $row[
'user_toggle_noti']);
521 $notificationConfig->setInterestedEvents((
int) $row[
'interested_events']);
523 self::$forced_events_cache[(
int) $row[
'user_id']] = $notificationConfig;
526 return self::$forced_events_cache;
531 if (!isset(self::$forced_events_cache[
$user_id])) {
532 $this->readAllForcedEvents();
535 if (!isset(self::$forced_events_cache[
$user_id])) {
536 self::$forced_events_cache[
$user_id] = $this->createMissingNotification(
$user_id);
539 return self::$forced_events_cache[
$user_id];
546 $new_object->setForumId($this->forum_id);
547 $new_object->insertAdminForce();
557 $notification_settings_by_usr_id = $this->read();
558 foreach ($usr_ids as $usr_id) {
559 $this->setUserId($usr_id);
560 $this->setAdminForce(
true);
564 if (array_key_exists($usr_id, $notification_settings_by_usr_id) &&
567 } elseif (!$this->existsNotification()) {
568 $this->insertAdminForce();
Class ilForumNotification.
deleteNotificationAllUsers()
static checkForumsExistsInsert(int $ref_id, int $user_id)
static mergeThreadNotifications($merge_source_thread_id, $merge_target_thread_id)
setUserToggle(bool $a_user_toggle)
setInterestedEvents(int $interested_events)
readonly ilDBInterface $db
getForcedEventsObjectByUserId(int $user_id)
isUserToggleNotification()
setUserIdNoti(int $a_user_id_noti)
createMissingNotification(int $user_id)
setNotificationId(int $a_notification_id)
static getCachedNodeData(int $ref_id)
setThreadId(int $a_thread_id)
setAdminForce(bool $a_admin_force)
cloneFromSource(int $sourceRefId)
__construct(private int $ref_id)
updateUserNotifications(array $usr_ids, ilForumProperties $object_properties)
setUserId(?int $a_user_id)
isAdminForceNotification()
static array $forced_events_cache
setForumRefId(int $a_ref_id)
static checkForumsExistsDelete(int $ref_id, int $user_id)
setForumId(int $a_forum_id)
static array $node_data_cache
static getInstance(int $a_obj_id=0)
static getInstanceByRefId(int $ref_id, bool $stop_on_error=true)
get an instance of an Ilias object by reference id