ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
NotificationManager.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
24
26{
27 protected int $current_user_id;
28
29 public function __construct(
30 protected InternalDomainService $domain
31 ) {
32 $this->current_user_id = $this->domain->user()->getId();
33 }
34
35 public function sendNotification(
36 string $action,
37 bool $in_wsp,
38 int $blog_node_id,
39 int $posting_id,
40 ?string $comment = null
41 ): void {
42 $blog_obj_id = $this->getBlogObjectId($in_wsp, $blog_node_id);
43 if (!$blog_obj_id) {
44 return;
45 }
46
47 $posting = new \ilBlogPosting($posting_id);
48
49 $ignore_threshold = ($action === "comment");
50 $admin_only = false;
51
52 if (!$posting->isApproved()) {
53 $blog_settings = $this->domain->blogSettings()->getByObjId($blog_obj_id);
54 if ($blog_settings?->getApproval()) {
55 switch ($action) {
56 case "update":
57 return;
58
59 case "new":
60 $admin_only = true;
61 $ignore_threshold = true;
62 $action = "approve";
63 break;
64 }
65 }
66 }
67
68 if (!$in_wsp && in_array($action, array("update", "new"))) {
69 $this->domain->news()->handle($posting, ($action === "update"));
70 }
71
74 $blog_obj_id,
75 $posting_id,
76 $ignore_threshold
77 );
78 if (!count($users)) {
79 return;
80 }
81
83 $in_wsp,
84 $blog_node_id,
85 $action,
86 $posting,
88 $users,
89 $admin_only
90 );
91
92 if (count($users)) {
95 $blog_obj_id,
96 $users,
97 $posting_id
98 );
99 }
100 }
101
102 protected function getBlogObjectId(bool $in_wsp, int $blog_node_id): ?int
103 {
104 if ($in_wsp) {
105 $tree = new \ilWorkspaceTree($this->current_user_id);
106 return $tree->lookupObjectId($blog_node_id);
107 } else {
108 return \ilObject::_lookupObjId($blog_node_id);
109 }
110 }
111
112 protected function sendSystemNotification(
113 bool $in_wsp,
114 int $blog_node_id,
115 string $action,
116 \ilBlogPosting $posting,
117 ?string $comment,
118 array $users,
119 bool $admin_only
120 ): void {
121 $ntf = new \ilSystemNotification($in_wsp);
122 $ntf->setLangModules(array("blog"));
123 $ntf->setRefId($blog_node_id);
124 $ntf->setChangedByUserId($this->current_user_id);
125 $ntf->setSubjectLangId('blog_change_notification_subject');
126 $ntf->setIntroductionLangId('blog_change_notification_body_' . $action);
127 $ntf->addAdditionalInfo('blog_posting', $posting->getTitle());
128
129 if ($comment) {
130 $ntf->addAdditionalInfo('comment', $comment, true);
131 }
132
133 $ntf->setGotoLangId('blog_change_notification_link');
134 $ntf->setReasonLangId('blog_change_notification_reason');
135
136 $abstract = $posting->getNotificationAbstract();
137 if ($abstract) {
138 $ntf->addAdditionalInfo('content', $abstract, true);
139 }
140
141 $notified = $ntf->sendMailAndReturnRecipients(
142 $users,
143 "_" . $posting->getId(),
144 ($admin_only ? "write" : "read")
145 );
146
147 if (count($notified)) {
150 $posting->getBlogId(),
151 $notified,
152 $posting->getId()
153 );
154 }
155 }
156}
$comment
Definition: buildRTE.php:72
sendSystemNotification(bool $in_wsp, int $blog_node_id, string $action, \ilBlogPosting $posting, ?string $comment, array $users, bool $admin_only)
__construct(protected InternalDomainService $domain)
sendNotification(string $action, bool $in_wsp, int $blog_node_id, int $posting_id, ?string $comment=null)
getBlogObjectId(bool $in_wsp, int $blog_node_id)
Class ilBlogPosting.
setLangModules(array $a_modules)
static updateNotificationTime(int $type, int $id, array $user_ids, ?int $page_id=null, bool $activate_new_entries=true)
Update the last mail timestamp for given object and users.
static getNotificationsForObject(int $type, int $id, ?int $page_id=null, bool $ignore_threshold=false)
Get all users/recipients for given object.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...