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());
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]
392 $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']] = [
397 'notification_id' => (
int) $row[
'notification_id'],
398 'user_id' => (
int) $row[
'user_id'],
399 'frm_id' => (
int) $row[
'frm_id'],
400 'thread_id' => (
int) $row[
'thread_id'],
401 'admin_force_noti' => (
int) $row[
'admin_force_noti'],
402 'user_toggle_noti' => (
int) $row[
'user_toggle_noti'],
403 'interested_events' => (
int) $row[
'interested_events'],
404 'user_id_noti' => (
int) $row[
'user_id_noti']
418 'SELECT notification_id, user_id FROM frm_notification WHERE frm_id = %s AND thread_id = %s ORDER BY user_id ASC',
419 [
'integer',
'integer'],
420 [0, $merge_source_thread_id]
423 $res_2 =
$ilDB->queryF(
424 'SELECT DISTINCT user_id FROM frm_notification WHERE frm_id = %s AND thread_id = %s ORDER BY user_id ASC',
425 [
'integer',
'integer'],
426 [0, $merge_target_thread_id]
429 $users_already_notified = [];
430 while ($users_row =
$ilDB->fetchAssoc($res_2)) {
431 $users_already_notified[(
int) $users_row[
'user_id']] = (
int) $users_row[
'user_id'];
435 if (isset($users_already_notified[(
int) $row[
'user_id']])) {
437 'DELETE FROM frm_notification WHERE notification_id = %s',
439 [$row[
'notification_id']]
444 [
'thread_id' => [
'integer', $merge_target_thread_id]],
445 [
'thread_id' => [
'integer', $merge_source_thread_id]]
453 $res = $this->db->queryF(
454 'SELECT user_id FROM frm_notification WHERE user_id = %s AND frm_id = %s AND admin_force_noti = %s',
455 [
'integer',
'integer',
'integer'],
456 [(
int) $this->getUserId(), $this->getForumId(), (
int) $this->getAdminForce()]
459 return $this->db->numRows(
$res) > 0;
464 $sourceNotificationSettings =
new self($sourceRefId);
465 $records = $sourceNotificationSettings->read();
467 foreach ($records as $usrId => $row) {
468 $this->setUserId($usrId);
469 $this->setAdminForce((
bool) $row[
'admin_force_noti']);
470 $this->setUserToggle((
bool) $row[
'user_toggle_noti']);
471 $this->setUserIdNoti((
int) $row[
'user_id_noti']);
472 $this->setInterestedEvents((
int) $row[
'interested_events']);
474 $this->insertAdminForce();
480 $this->db->manipulateF(
481 'UPDATE frm_notification SET interested_events = %s WHERE user_id = %s AND frm_id = %s',
482 [
'integer',
'integer',
'integer'],
483 [$this->getInterestedEvents(), (
int) $this->getUserId(), $this->getForumId()]
491 $this->db->setLimit(1);
492 $res = $this->db->queryF(
493 'SELECT interested_events FROM frm_notification WHERE user_id = %s AND frm_id = %s',
494 [
'integer',
'integer'],
495 [(
int) $this->getUserId(), $this->getForumId()]
498 while ($row = $this->db->fetchAssoc(
$res)) {
499 $interested_events = (
int) $row[
'interested_events'];
502 return $interested_events;
510 $res = $this->db->queryF(
511 'SELECT * FROM frm_notification WHERE admin_force_noti = %s AND frm_id = %s',
512 [
'integer',
'integer'],
516 while ($row = $this->db->fetchAssoc(
$res)) {
518 $notificationConfig->setNotificationId((
int) $row[
'notification_id']);
519 $notificationConfig->setUserId((
int) $row[
'user_id']);
520 $notificationConfig->setForumId((
int) $row[
'frm_id']);
521 $notificationConfig->setAdminForce((
bool) $row[
'admin_force_noti']);
522 $notificationConfig->setUserToggle((
bool) $row[
'user_toggle_noti']);
523 $notificationConfig->setInterestedEvents((
int) $row[
'interested_events']);
525 self::$forced_events_cache[(
int) $row[
'user_id']] = $notificationConfig;
528 return self::$forced_events_cache;
533 if (!isset(self::$forced_events_cache[
$user_id])) {
534 $this->readAllForcedEvents();
537 if (!isset(self::$forced_events_cache[
$user_id])) {
538 self::$forced_events_cache[
$user_id] = $this->createMissingNotification(
$user_id);
541 return self::$forced_events_cache[
$user_id];
548 $new_object->setForumId($this->forum_id);
549 $new_object->insertAdminForce();
562 array $all_context_usr_ids,
566 $existing_notification_records = $this->read();
568 foreach ($existing_notification_records as
$user_id => $row) {
572 $this->setInterestedEvents((
int) $row[
'interested_events']);
580 foreach ($existing_notification_records as
$user_id => $row) {
590 $this->setInterestedEvents((
int) $row[
'interested_events']);
596 foreach ($all_context_usr_ids as
$user_id) {
597 if (array_key_exists(
$user_id, $existing_notification_records)) {
605 $this->insertAdminForce();
612 foreach ($existing_notification_records as
$user_id => $row) {
616 $this->setUserToggle((
bool) $row[
'user_toggle_noti']);
618 if ((
int) $row[
'user_toggle_noti'] === 1) {
623 $this->setInterestedEvents((
int) $row[
'interested_events']);
629 foreach ($all_context_usr_ids as
$user_id) {
630 if (array_key_exists(
$user_id, $existing_notification_records)) {
638 $this->insertAdminForce();
Class ilForumNotification.
applyTypeConfigurationFor(array $all_context_usr_ids, ilForumProperties $effective_properties, ?ilForumProperties $former_properties=null)
Aligns frm_notification rows for this forum with the effective notification mode and properties.
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)
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