19 declare(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, user_id_noti) 194 VALUES(%s, %s, %s, %s, %s, %s)',
195 [
'integer',
'integer',
'integer',
'integer',
'integer',
'integer'],
209 $this->db->manipulateF(
211 DELETE FROM frm_notification 214 AND admin_force_noti = %s 215 AND user_id_noti > %s',
216 [
'integer',
'integer',
'integer',
'integer'],
223 $this->db->manipulateF(
225 DELETE FROM frm_notification 228 AND admin_force_noti = %s 229 AND user_toggle_noti = %s 230 AND user_id_noti > %s',
231 [
'integer',
'integer',
'integer',
'integer',
'integer'],
238 $this->db->manipulateF(
239 'UPDATE frm_notification SET user_toggle_noti = %s WHERE user_id = %s AND frm_id = %s AND admin_force_noti = %s',
240 [
'integer',
'integer',
'integer',
'integer'],
253 $ilUser = $DIC->user();
255 $node_data = self::getCachedNodeData($ref_id);
257 foreach ($node_data as
$data) {
260 if ($user_id !== 0) {
261 $frm_noti->setUserId($user_id);
263 $frm_noti->setUserId($ilUser->getId());
267 $frm_noti->setAdminForce($admin_force);
271 $frm_noti->setAdminForce(
true);
274 if ($admin_force || $user_toggle) {
275 $frm_noti->setUserToggle($user_toggle);
276 $frm_noti->setForumId((
int) $data[
'obj_id']);
277 if (!$frm_noti->existsNotification()) {
278 $frm_noti->insertAdminForce();
288 $ilUser = $DIC->user();
290 $node_data = self::getCachedNodeData($ref_id);
292 foreach ($node_data as
$data) {
295 $moderator_ids = $objFrmMods->getCurrentModerators();
297 if ($user_id !== 0) {
298 $frm_noti->setUserId($user_id);
300 $frm_noti->setUserId($ilUser->getId());
303 $frm_noti->setForumId((
int) $data[
'obj_id']);
304 if (!in_array($frm_noti->getUserId(), $moderator_ids,
true)) {
305 $frm_noti->deleteAdminForce();
314 if (!array_key_exists($ref_id, self::$node_data_cache)) {
315 $container_node = $DIC->repositoryTree()->getNodeData($ref_id);
316 if (!isset($container_node[
'child'])) {
320 $node_data = $DIC->repositoryTree()->getSubTree(
325 $node_data = array_filter($node_data,
static function (array $forum_node) use ($DIC, $ref_id):
bool {
327 foreach ($DIC->repositoryTree()->getNodePath((
int) $forum_node[
'child'], $ref_id) as $path_node) {
328 $notRootNode = (
int) $path_node[
'child'] !== $ref_id;
329 $isGroup = $path_node[
'type'] ===
'grp';
330 if ($notRootNode && $isGroup) {
337 self::$node_data_cache[
$ref_id] = $node_data;
340 return self::$node_data_cache[
$ref_id];
343 public static function _clearForcedForumNotifications(array $move_tree_event):
void 346 $ilDB = $DIC->database();
348 if ($move_tree_event[
'tree'] !==
'tree') {
354 if ($source_forum->isParentMembershipEnabledContainer()) {
356 'DELETE FROM frm_notification WHERE frm_id = %s AND admin_force_noti = %s',
357 [
'integer',
'integer'],
358 [$source_forum->getId(), 1]
365 $this->db->manipulateF(
366 'UPDATE frm_notification SET admin_force_noti = %s, user_toggle_noti = %s, ' .
367 'interested_events = %s WHERE user_id = %s AND frm_id = %s',
368 [
'integer',
'integer',
'integer',
'integer',
'integer'],
381 $this->db->manipulateF(
382 'DELETE FROM frm_notification WHERE frm_id = %s AND user_id_noti > %s',
383 [
'integer',
'integer'],
395 $res = $this->db->queryF(
'SELECT * FROM frm_notification WHERE frm_id = %s', [
'integer'], [$this->
getForumId()]);
396 while ($row = $this->db->fetchAssoc(
$res)) {
397 $result[(
int) $row[
'user_id']][
'notification_id'] = (
int) $row[
'notification_id'];
398 $result[(
int) $row[
'user_id']][
'user_id'] = (
int) $row[
'user_id'];
399 $result[(
int) $row[
'user_id']][
'frm_id'] = (
int) $row[
'frm_id'];
400 $result[(
int) $row[
'user_id']][
'thread_id'] = (
int) $row[
'thread_id'];
401 $result[(
int) $row[
'user_id']][
'admin_force_noti'] = (
int) $row[
'admin_force_noti'];
402 $result[(
int) $row[
'user_id']][
'user_toggle_noti'] = (
int) $row[
'user_toggle_noti'];
403 $result[(
int) $row[
'user_id']][
'interested_events'] = (
int) $row[
'interested_events'];
404 $result[(
int) $row[
'user_id']][
'user_id_noti'] = (
int) $row[
'user_id_noti'];
414 $ilDB = $DIC->database();
417 'SELECT notification_id, user_id FROM frm_notification WHERE frm_id = %s AND thread_id = %s ORDER BY user_id ASC',
418 [
'integer',
'integer'],
419 [0, $merge_source_thread_id]
422 $res_2 =
$ilDB->queryF(
423 'SELECT DISTINCT user_id FROM frm_notification WHERE frm_id = %s AND thread_id = %s ORDER BY user_id ASC',
424 [
'integer',
'integer'],
425 [0, $merge_target_thread_id]
428 $users_already_notified = [];
429 while ($users_row =
$ilDB->fetchAssoc($res_2)) {
430 $users_already_notified[(
int) $users_row[
'user_id']] = (
int) $users_row[
'user_id'];
434 if (isset($users_already_notified[(
int) $row[
'user_id']])) {
436 'DELETE FROM frm_notification WHERE notification_id = %s',
438 [$row[
'notification_id']]
443 [
'thread_id' => [
'integer', $merge_target_thread_id]],
444 [
'thread_id' => [
'integer', $merge_source_thread_id]]
452 $res = $this->db->queryF(
453 'SELECT user_id FROM frm_notification WHERE user_id = %s AND frm_id = %s AND admin_force_noti = %s',
454 [
'integer',
'integer',
'integer'],
458 return $this->db->numRows(
$res) > 0;
463 $sourceNotificationSettings =
new self($sourceRefId);
464 $records = $sourceNotificationSettings->read();
466 foreach ($records as $usrId => $row) {
479 $this->db->manipulateF(
480 'UPDATE frm_notification SET interested_events = %s WHERE user_id = %s AND frm_id = %s',
481 [
'integer',
'integer',
'integer'],
490 $this->db->setLimit(1);
491 $res = $this->db->queryF(
492 'SELECT interested_events FROM frm_notification WHERE user_id = %s AND frm_id = %s',
493 [
'integer',
'integer'],
497 while ($row = $this->db->fetchAssoc(
$res)) {
498 $interested_events = (
int) $row[
'interested_events'];
509 $res = $this->db->queryF(
510 'SELECT * FROM frm_notification WHERE admin_force_noti = %s AND frm_id = %s',
511 [
'integer',
'integer'],
515 while ($row = $this->db->fetchAssoc(
$res)) {
517 $notificationConfig->setNotificationId((
int) $row[
'notification_id']);
518 $notificationConfig->setUserId((
int) $row[
'user_id']);
519 $notificationConfig->setForumId((
int) $row[
'frm_id']);
520 $notificationConfig->setAdminForce((
bool) $row[
'admin_force_noti']);
521 $notificationConfig->setUserToggle((
bool) $row[
'user_toggle_noti']);
522 $notificationConfig->setInterestedEvents((
int) $row[
'interested_events']);
524 self::$forced_events_cache[(
int) $row[
'user_id']] = $notificationConfig;
527 return self::$forced_events_cache;
532 if (!isset(self::$forced_events_cache[$user_id])) {
536 if (!isset(self::$forced_events_cache[$user_id])) {
540 return self::$forced_events_cache[
$user_id];
546 $new_object->setUserId($user_id);
547 $new_object->setForumId($this->forum_id);
548 $new_object->insertAdminForce();
558 $notification_settings_by_usr_id = $this->
read();
559 foreach ($usr_ids as $usr_id) {
565 if (array_key_exists($usr_id, $notification_settings_by_usr_id) &&
deleteNotificationAllUsers()
setUserId(?int $a_user_id)
createMissingNotification(int $user_id)
isUserToggleNotification()
static array $node_data_cache
setThreadId(int $a_thread_id)
isAdminForceNotification()
setUserToggle(bool $a_user_toggle)
setForumRefId(int $a_ref_id)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
static _isAdminForceNoti(int $a_obj_id)
setNotificationId(int $a_notification_id)
setAdminForce(bool $a_admin_force)
__construct(private int $ref_id)
static getInstanceByRefId(int $ref_id, bool $stop_on_error=true)
get an instance of an Ilias object by reference id
cloneFromSource(int $sourceRefId)
static array $forced_events_cache
static getCachedNodeData(int $ref_id)
getForcedEventsObjectByUserId(int $user_id)
setForumId(int $a_forum_id)
readonly ilDBInterface $db
setInterestedEvents(int $interested_events)
static _isUserToggleNoti(int $a_obj_id)
static mergeThreadNotifications($merge_source_thread_id, $merge_target_thread_id)
static checkForumsExistsDelete(int $ref_id, int $user_id)
static checkForumsExistsInsert(int $ref_id, int $user_id)
updateUserNotifications(array $usr_ids, ilForumProperties $object_properties)
setUserIdNoti(int $a_user_id_noti)