ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
NotificationGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
25
31{
32 protected \ilLogger $log;
35
36 public function __construct(
37 InternalDomainService $domain_service,
38 InternalGUIService $gui_service
39 ) {
40 $this->gui = $gui_service;
41 $this->domain = $domain_service;
42 $this->log = $domain_service->log();
43 }
44
45 public function send(
46 string $a_action,
47 int $a_type,
48 int $a_wiki_ref_id,
49 int $a_page_id,
50 ?string $a_comment = null,
51 string $lang = "-"
52 ): void {
53 global $DIC;
54
55 if ($a_wiki_ref_id === 0) {
56 return;
57 }
58
59 if ($lang === "") {
60 $lang = "-";
61 }
62
64 $log->debug("start... vvvvvvvvvvvvvvvvvvvvvvvvvvv");
65
66 $ilUser = $this->domain->user();
67 $ilAccess = $this->domain->access();
68
69 $wiki = $this->domain->wiki()->object($a_wiki_ref_id);
70 $wiki_id = $wiki->getId();
71 $log->debug("page id: " . $a_page_id);
72 $log->debug("lang: " . $lang);
73 $pgui = $this->gui->page()->getWikiPageGUI(
74 $a_wiki_ref_id,
75 $a_page_id,
76 0,
77 $lang
78 );
79 $page = $pgui->getPageObject();
80
81 // #11138
82 $ignore_threshold = ($a_action === "comment");
83
84 // 1st update will be converted to new - see below
85 if ($a_action === "new") {
86 return;
87 }
88
89 $log->debug("-- get notifications");
90 if ($a_type === \ilNotification::TYPE_WIKI_PAGE) {
91 $users = \ilNotification::getNotificationsForObject($a_type, $a_page_id, null, $ignore_threshold);
92 $wiki_users = \ilNotification::getNotificationsForObject(\ilNotification::TYPE_WIKI, $wiki_id, $a_page_id, $ignore_threshold);
93 $users = array_merge($users, $wiki_users);
94 if (!count($users)) {
95 $log->debug("no notifications... ^^^^^^^^^^^^^^^^^^");
96 return;
97 }
99 } else {
100 $users = \ilNotification::getNotificationsForObject(\ilNotification::TYPE_WIKI, $wiki_id, $a_page_id, $ignore_threshold);
101 if (!count($users)) {
102 $log->debug("no notifications... ^^^^^^^^^^^^^^^^^^");
103 return;
104 }
105 }
106
108
109 // #15192 - should always be present
110 if ($a_page_id) {
111 // #18804 - see ilWikiPageGUI::preview()
112 $link = \ilLink::_getLink(null, "wiki", [], "wpage_" . $a_page_id . "_" . $a_wiki_ref_id);
113 } else {
114 $link = \ilLink::_getLink($a_wiki_ref_id);
115 }
116
117 $log->debug("-- prepare content");
118 $pgui->setRawPageContent(true);
119 $pgui->setAbstractOnly(true);
120 $pgui->setFileDownloadLink(".");
121 $pgui->setFullscreenLink(".");
122 $pgui->setSourcecodeDownloadScript(".");
123 $snippet = $pgui->showPage();
124 $snippet = \ilPageObject::truncateHTML($snippet, 500, "...");
125
126 // making things more readable
127 $snippet = str_replace(['<br/>', '<br />', '</p>', '</div>'], "\n", $snippet);
128
129 $snippet = trim(strip_tags($snippet));
130
131 // "fake" new (to enable snippet - if any)
132 $hist = $page->getHistoryEntries();
133 $current_version = array_shift($hist);
134 $current_version = $current_version["nr"] ?? 0;
135 if (!$current_version && $a_action !== "comment") {
137 $a_action = "new";
138 }
139
140 $log->debug("-- sending mails");
141 $mails = [];
142 foreach (array_unique($users) as $idx => $user_id) {
143 if ($user_id !== $ilUser->getId() &&
144 $ilAccess->checkAccessOfUser($user_id, 'read', '', $a_wiki_ref_id)) {
145 // use language of recipient to compose message
147 $ulng->loadLanguageModule('wiki');
148
149 if ($a_action === "comment") {
150 $subject = sprintf($ulng->txt('wiki_notification_comment_subject'), $wiki->getTitle(), $page->getTitle());
151 $message = sprintf($ulng->txt('wiki_change_notification_salutation'), \ilObjUser::_lookupFullname($user_id)) . "\n\n";
152
153 $message .= $ulng->txt('wiki_notification_' . $a_action) . ":\n\n";
154 $message .= $ulng->txt('wiki') . ": " . $wiki->getTitle() . "\n";
155 $message .= $ulng->txt('page') . ": " . $page->getTitle() . "\n";
156 $message .= $ulng->txt('wiki_commented_by') . ": " . \ilUserUtil::getNamePresentation($ilUser->getId()) . "\n";
157
158 // include comment/note text
159 if ($a_comment) {
160 $message .= "\n" . $ulng->txt('comment') . ":\n\"" . trim($a_comment) . "\"\n";
161 }
162
163 $message .= "\n" . $ulng->txt('wiki_change_notification_page_link') . ": " . $link;
164 } else {
165 $subject = sprintf($ulng->txt('wiki_change_notification_subject'), $wiki->getTitle(), $page->getTitle());
166 $message = sprintf($ulng->txt('wiki_change_notification_salutation'), \ilObjUser::_lookupFullname($user_id)) . "\n\n";
167
168 if ($a_type == \ilNotification::TYPE_WIKI_PAGE) {
169 // update/delete
170 $message .= $ulng->txt('wiki_change_notification_page_body_' . $a_action) . ":\n\n";
171 $message .= $ulng->txt('wiki') . ": " . $wiki->getTitle() . "\n";
172 $message .= $ulng->txt('page') . ": " . $page->getTitle() . "\n";
173 $message .= $ulng->txt('wiki_changed_by') . ": " . \ilUserUtil::getNamePresentation($ilUser->getId()) . "\n";
174
175 if ($snippet) {
176 $message .= "\n" . $ulng->txt('content') . "\n" .
177 "----------------------------------------\n" .
178 $snippet . "\n" .
179 "----------------------------------------\n";
180 }
181
182 // include comment/note text
183 if ($a_comment) {
184 $message .= "\n" . $ulng->txt('comment') . ":\n\"" . trim($a_comment) . "\"\n";
185 }
186
187 $message .= "\n" . $ulng->txt('wiki_change_notification_page_link') . ": " . $link;
188 } else {
189 // new
190 $message .= $ulng->txt('wiki_change_notification_body_' . $a_action) . ":\n\n";
191 $message .= $ulng->txt('wiki') . ": " . $wiki->getTitle() . "\n";
192 $message .= $ulng->txt('page') . ": " . $page->getTitle() . "\n";
193 $message .= $ulng->txt('wiki_changed_by') . ": " . \ilUserUtil::getNamePresentation($ilUser->getId()) . "\n\n";
194
195 if ($snippet) {
196 $message .= $ulng->txt('content') . "\n" .
197 "----------------------------------------\n" .
198 $snippet . "\n" .
199 "----------------------------------------\n\n";
200 }
201
202 $message .= $ulng->txt('wiki_change_notification_link') . ": " . $link;
203 }
204 }
205
206 $mail_obj = new \ilMail(ANONYMOUS_USER_ID);
207 $mail_obj->appendInstallationSignature(true);
208 $log->debug("before enqueue ($user_id)");
209 /*
210 $mail_obj->enqueue(
211 ilObjUser::_lookupLogin($user_id),
212 "",
213 "",
214 $subject,
215 $message,
216 array()
217 );*/
219 $mails[] = new \ilMailValueObject(
220 '',
222 '',
223 '',
224 $subject,
225 $message,
226 [],
227 false,
228 false
229 );
230 $log->debug("after enqueue");
231 } else {
232 unset($users[$idx]);
233 }
234 }
235 if (count($mails) > 0) {
236 $processor = new \ilMassMailTaskProcessor();
237 $processor->run(
238 $mails,
240 "",
241 []
242 );
243 }
244 $log->debug("end... ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^");
245 }
246
247}
This class is only in GUI layer, since it needs to get the abstracts for the page GUI.
send(string $a_action, int $a_type, int $a_wiki_ref_id, int $a_page_id, ?string $a_comment=null, string $lang="-")
__construct(InternalDomainService $domain_service, InternalGUIService $gui_service)
static _getLanguageOfUser(int $a_usr_id)
Get language object of user.
debug(string $message, array $context=[])
static _getInstallationSignature()
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.
static _lookupFullname(int $a_user_id)
static _lookupLogin(int $a_user_id)
static truncateHTML(string $a_text, int $a_length=100, string $a_ending='...', bool $a_exact=false, bool $a_consider_html=true)
Truncate (html) string.
static getNamePresentation( $a_user_id, bool $a_user_image=false, bool $a_profile_link=false, string $a_profile_back_link='', bool $a_force_first_lastname=false, bool $a_omit_login=false, bool $a_sortable=true, bool $a_return_data_array=false, $a_ctrl_path=null)
Default behaviour is:
const ANONYMOUS_USER_ID
Definition: constants.php:27
global $DIC
Definition: shib_login.php:26
$lang
Definition: xapiexit.php:25
$message
Definition: xapiexit.php:31