ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilSystemNotification.php
Go to the documentation of this file.
1<?php
2
27{
28 protected string $subject_lang_id = "";
29 protected string $subject_direct = "";
30 protected string $introduction = "";
31 protected string $introduction_direct = "";
32 protected string $task = "";
33 protected string $reason = "";
34 protected array $additional = [];
35 protected string $goto_caption = "";
36 protected int $changed_by = 0;
37 protected ?array $all_ref_ids = [];
38
39 public function __construct(protected bool $is_in_wsp = false)
40 {
41 parent::__construct($is_in_wsp);
42 $this->ref_id = 0;
43 }
44
45 public function setSubjectLangId(string $a_lang_id): void
46 {
47 $this->subject_lang_id = $a_lang_id;
48 }
49
50 public function setSubjectDirect(string $a_text): void
51 {
52 $this->subject_direct = trim($a_text);
53 }
54
55 public function setIntroductionLangId(string $a_lang_id): void
56 {
57 $this->introduction = $a_lang_id;
58 }
59
60 public function setIntroductionDirect(string $a_text): void
61 {
62 $this->introduction_direct = trim($a_text);
63 }
64
65 public function setTaskLangId(string $a_lang_id): void
66 {
67 $this->task = $a_lang_id;
68 }
69
70 public function setReasonLangId(string $a_lang_id): void
71 {
72 $this->reason = $a_lang_id;
73 }
74
75 public function setGotoLangId(string $a_lang_id): void
76 {
77 $this->goto_caption = $a_lang_id;
78 }
79
80 public function setChangedByUserId(int $a_id): void
81 {
82 $this->changed_by = $a_id;
83 }
84
88 public function addAdditionalInfo(
89 string $a_lang_id,
90 string $a_value,
91 bool $a_multiline = false,
92 bool $a_lang_direct = false
93 ): void {
94 $this->additional[$a_lang_id] = array(trim($a_value), $a_multiline, $a_lang_direct);
95 }
96
106 array $a_user_ids,
107 ?string $a_goto_additional = null,
108 string $a_permission = "read"
109 ): array {
110 $this->all_ref_ids = null;
111
112 // prepare object related info
113 if ($this->getObjId()) {
114 if (!$this->getRefId()) {
115 // try to find ref_id(s)
116 if (!$this->is_in_wsp) {
117 $ref_ids = ilObject::_getAllReferences($this->getObjId());
118 if (count($ref_ids) === 1) {
119 $this->ref_id = array_shift($ref_ids);
120 } else {
121 $this->all_ref_ids = $ref_ids;
122 }
123 }
124 } elseif ($this->is_in_wsp) { // #11680
125 $this->ref_id = $this->wsp_tree->lookupNodeId($this->getObjId());
126 }
127
128 // default values
129 if (!$this->goto_caption) {
130 $this->goto_caption = "url";
131 }
132 }
133
134 $recipient_ids = array();
135 foreach (array_unique($a_user_ids) as $user_id) {
136 // author of change should not get notification
137 if ($this->changed_by === $user_id) {
138 continue;
139 }
140 if ($this->composeAndSendMail($user_id, $a_goto_additional, $a_permission)) {
141 $recipient_ids[] = $user_id;
142 }
143 }
144
145 return $recipient_ids;
146 }
147
151 public function compose(
152 int $a_user_id,
153 ?string $a_goto_additional = null,
154 string $a_permission = "read",
155 bool $a_append_signature_direct = false
156 ): bool {
157 $find_ref_id = false;
158 $this->initLanguage($a_user_id);
159 $this->initMail();
160 if ($this->subject_direct) {
161 $this->setSubject($this->subject_direct);
162 } else {
163 $this->setSubject(
164 sprintf($this->getLanguageText($this->subject_lang_id), $this->getObjectTitle(true))
165 );
166 }
167
168 $this->setBody(ilMail::getSalutation($a_user_id, $this->getLanguage()));
169 $this->appendBody("\n\n");
170
171 if ($this->introduction) {
172 $this->appendBody($this->getLanguageText($this->introduction));
173 $this->appendBody("\n\n");
174 }
175
176 if ($this->introduction_direct) {
177 $this->appendBody($this->introduction_direct);
178 $this->appendBody("\n\n");
179 }
180
181 if ($this->task) {
182 $this->appendBody($this->getLanguageText($this->task));
183 $this->appendBody("\n\n");
184 }
185
186 // details table
187 if ($this->getObjId()) {
188 $this->appendBody($this->getLanguageText("obj_" . $this->getObjType()) . ": " .
189 $this->getObjectTitle() . "\n");
190 }
191 if (count($this->additional) > 0) {
192 foreach ($this->additional as $lang_id => $item) {
193 $caption = "";
194 if ($lang_id) {
195 $caption = (!$item[2])
196 ? $this->getLanguageText($lang_id)
197 : $lang_id;
198 }
199 if (!$item[1]) {
200 if ($caption) {
201 $caption .= ": ";
202 }
203 $this->appendBody($caption . $item[0] . "\n");
204 } else {
205 if ($caption) {
206 $caption .= "\n";
207 }
208 $this->appendBody("\n" . $caption .
209 $this->getBlockBorder() .
210 $item[0] . "\n" .
211 $this->getBlockBorder() . "\n");
212 }
213 }
214 }
215 $this->body = trim($this->body);
216 $this->appendBody("\n\n");
217
218 if ($this->changed_by) {
219 $this->appendBody($this->getLanguageText("system_notification_installation_changed_by") . ": " .
220 ilUserUtil::getNamePresentation($this->changed_by));
221 $this->appendBody("\n\n");
222 }
223
224 if ($this->getObjId()) {
225 // try to find accessible ref_id
226 if (!$this->getRefId() && $this->all_ref_ids) {
227 $find_ref_id = true;
228 foreach ($this->all_ref_ids as $ref_id) {
229 if ($this->isRefIdAccessible($a_user_id, $ref_id, $a_permission)) {
230 $this->ref_id = $ref_id;
231 break;
232 }
233 }
234 }
235
236 // check if initially given ref_id is accessible for current recipient
237 if ($this->getRefId() &&
238 !$find_ref_id &&
239 !$this->isRefIdAccessible($a_user_id, $this->getRefId(), $a_permission)) {
240 return false;
241 }
242
243 $goto = $this->createPermanentLink(array(), (string) $a_goto_additional);
244 if ($goto) {
245 $this->appendBody($this->getLanguageText($this->goto_caption) . ": " .
246 $goto);
247 $this->appendBody("\n\n");
248 }
249
250 if ($find_ref_id) {
251 $this->ref_id = 0;
252 }
253 }
254
255 if ($this->reason) {
256 $this->appendBody($this->getLanguageText($this->reason));
257 $this->appendBody("\n\n");
258 }
259
260 $this->appendBody(ilMail::_getAutoGeneratedMessageString($this->language));
261
262 // signature will append new lines
263 $this->body = trim($this->body);
264
265 if (!$a_append_signature_direct) {
266 $this->getMail()->appendInstallationSignature(true);
267 } else {
268 $this->appendBody(ilMail::_getInstallationSignature());
269 }
270
271 return true;
272 }
273
277 protected function composeAndSendMail(
278 int $a_user_id,
279 ?string $a_goto_additional = null,
280 string $a_permission = "read"
281 ): bool {
282 if ($this->compose($a_user_id, $a_goto_additional, $a_permission)) {
283 $this->sendMail(array($a_user_id), is_numeric($a_user_id));
284 return true;
285 }
286 return false;
287 }
288
292 public function composeAndGetMessage(
293 int $a_user_id,
294 ?string $a_goto_additional = null,
295 string $a_permission = "read",
296 bool $a_append_signature_direct = false
297 ): string {
298 if ($this->compose($a_user_id, $a_goto_additional, $a_permission, $a_append_signature_direct)) {
299 return $this->body;
300 }
301 return "";
302 }
303}
static getSalutation(int $a_usr_id, ?ilLanguage $a_language=null)
static _getInstallationSignature()
static _getAutoGeneratedMessageString(?ilLanguage $lang=null)
static _getAllReferences(int $id)
get all reference ids for object ID
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setIntroductionLangId(string $a_lang_id)
setSubjectLangId(string $a_lang_id)
sendMailAndReturnRecipients(array $a_user_ids, ?string $a_goto_additional=null, string $a_permission="read")
Send notification(s)
compose(int $a_user_id, ?string $a_goto_additional=null, string $a_permission="read", bool $a_append_signature_direct=false)
Compose notification to single recipient.
composeAndGetMessage(int $a_user_id, ?string $a_goto_additional=null, string $a_permission="read", bool $a_append_signature_direct=false)
Compose notification to single recipient.
composeAndSendMail(int $a_user_id, ?string $a_goto_additional=null, string $a_permission="read")
Send notification to single recipient.
setReasonLangId(string $a_lang_id)
addAdditionalInfo(string $a_lang_id, string $a_value, bool $a_multiline=false, bool $a_lang_direct=false)
Add additional information.
__construct(protected bool $is_in_wsp=false)
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:
$ref_id
Definition: ltiauth.php:66
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
if(!file_exists('../ilias.ini.php'))
getLanguage()