ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilSystemNotification.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 include_once './Services/Mail/classes/class.ilMailNotification.php';
5 
17 {
18  protected $subject_lang_id; // [string]
19  protected $introduction; // [string]
20  protected $introduction_direct; // [string]
21  protected $task; // [string]
22  protected $reason; // [string]
23  protected $additional; // [array]
24  protected $goto_caption; // [string]
25  protected $changed_by; // [int]
26  protected $all_ref_ids; // [array]
27 
33  public function setSubjectLangId($a_lang_id)
34  {
35  $this->subject_lang_id = (string) $a_lang_id;
36  }
37 
43  public function setIntroductionLangId($a_lang_id)
44  {
45  $this->introduction = (string) $a_lang_id;
46  }
47 
53  public function setIntroductionDirect($a_text)
54  {
55  $this->introduction_direct = trim($a_text);
56  }
57 
63  public function setTaskLangId($a_lang_id)
64  {
65  $this->task = (string) $a_lang_id;
66  }
67 
73  public function setReasonLangId($a_lang_id)
74  {
75  $this->reason = (string) $a_lang_id;
76  }
77 
83  public function setGotoLangId($a_lang_id)
84  {
85  $this->goto_caption = (string) $a_lang_id;
86  }
87 
93  public function setChangedByUserId($a_id)
94  {
95  $this->changed_by = (int) $a_id;
96 
97  include_once "Services/User/classes/class.ilUserUtil.php";
98  }
99 
108  public function addAdditionalInfo($a_lang_id, $a_value, $a_multiline = false, $a_lang_direct = false)
109  {
110  $this->additional[$a_lang_id] = array(trim($a_value), (bool) $a_multiline, (bool) $a_lang_direct);
111  }
112 
121  public function sendMail(array $a_user_ids, $a_goto_additional = null, $a_permission = "read")
122  {
123  $this->all_ref_ids = null;
124 
125  // prepare object related info
126  if ($this->getObjId()) {
127  if (!$this->getRefId()) {
128  // try to find ref_id(s)
129  if (!$this->is_in_wsp) {
130  $ref_ids = ilObject::_getAllReferences($this->getObjId());
131  if (sizeof($ref_ids) == 1) {
132  $this->ref_id = array_shift($ref_ids);
133  } else {
134  $this->all_ref_ids = $ref_ids;
135  }
136  }
137  } elseif ($this->is_in_wsp) { // #11680
138  $this->ref_id = $this->wsp_tree->lookupNodeId($this->getObjId());
139  }
140 
141  // default values
142  if (!$this->goto_caption) {
143  $this->goto_caption = "url";
144  }
145  }
146 
147  $recipient_ids = array();
148  foreach (array_unique($a_user_ids) as $user_id) {
149  // author of change should not get notification
150  if ($this->changed_by == $user_id) {
151  continue;
152  }
153  if ($this->composeAndSendMail($user_id, $a_goto_additional, $a_permission)) {
154  $recipient_ids[] = $user_id;
155  }
156  }
157 
158  return $recipient_ids;
159  }
160 
170  public function compose($a_user_id, $a_goto_additional = null, $a_permission = "read", $a_append_signature_direct = false)
171  {
172  $this->initLanguage($a_user_id);
173  $this->initMail();
174 
175  $this->setSubject(
176  sprintf($this->getLanguageText($this->subject_lang_id), $this->getObjectTitle(true))
177  );
178 
179  $this->setBody(ilMail::getSalutation($a_user_id, $this->getLanguage()));
180  $this->appendBody("\n\n");
181 
182  if ($this->introduction) {
183  $this->appendBody($this->getLanguageText($this->introduction));
184  $this->appendBody("\n\n");
185  }
186 
187  if ($this->introduction_direct) {
188  $this->appendBody($this->introduction_direct);
189  $this->appendBody("\n\n");
190  }
191 
192  if ($this->task) {
193  $this->appendBody($this->getLanguageText($this->task));
194  $this->appendBody("\n\n");
195  }
196 
197  // details table
198  if ($this->getObjId()) {
199  $this->appendBody($this->getLanguageText("obj_" . $this->getObjType()) . ": " .
200  $this->getObjectTitle() . "\n");
201  }
202  if (sizeof($this->additional)) {
203  foreach ($this->additional as $lang_id => $item) {
204  $caption = "";
205  if ($lang_id) {
206  $caption = (!$item[2])
207  ? $this->getLanguageText($lang_id)
208  : $lang_id;
209  }
210  if (!$item[1]) {
211  if ($caption) {
212  $caption .= ": ";
213  }
214  $this->appendBody($caption . $item[0] . "\n");
215  } else {
216  if ($caption) {
217  $caption .= "\n";
218  }
219  $this->appendBody("\n" . $caption .
220  $this->getBlockBorder() .
221  $item[0] . "\n" .
222  $this->getBlockBorder() . "\n");
223  }
224  }
225  }
226  $this->body = trim($this->body);
227  $this->appendBody("\n\n");
228 
229  if ($this->changed_by) {
230  $this->appendBody($this->getLanguageText("system_notification_installation_changed_by") . ": " .
231  ilUserUtil::getNamePresentation($this->changed_by));
232  $this->appendBody("\n\n");
233  }
234 
235  if ($this->getObjId()) {
236  // try to find accessible ref_id
237  if (!$this->getRefId() && $this->all_ref_ids) {
238  $find_ref_id = true;
239  foreach ($this->all_ref_ids as $ref_id) {
240  if ($this->isRefIdAccessible($a_user_id, $ref_id, $a_permission)) {
241  $this->ref_id = $ref_id;
242  break;
243  }
244  }
245  }
246 
247  // check if initially given ref_id is accessible for current recipient
248  if ($this->getRefId() &&
249  !$find_ref_id &&
250  !$this->isRefIdAccessible($a_user_id, $this->getRefId(), $a_permission)) {
251  return false;
252  }
253 
254  $goto = $this->createPermanentLink(array(), $a_goto_additional);
255  if ($goto) {
256  $this->appendBody($this->getLanguageText($this->goto_caption) . ": " .
257  $goto);
258  $this->appendBody("\n\n");
259  }
260 
261  if ($find_ref_id) {
262  $this->ref_id = null;
263  }
264  }
265 
266  if ($this->reason) {
267  $this->appendBody($this->getLanguageText($this->reason));
268  $this->appendBody("\n\n");
269  }
270 
271  $this->appendBody(ilMail::_getAutoGeneratedMessageString($this->language));
272 
273  // signature will append new lines
274  $this->body = trim($this->body);
275 
276  if (!$a_append_signature_direct) {
277  $this->getMail()->appendInstallationSignature(true);
278  } else {
280  }
281 
282  return true;
283  }
284 
293  protected function composeAndSendMail($a_user_id, $a_goto_additional = null, $a_permission = "read")
294  {
295  if ($this->compose($a_user_id, $a_goto_additional, $a_permission)) {
296  parent::sendMail(array($a_user_id), array('system'), is_numeric($a_user_id));
297  return true;
298  }
299  return false;
300  }
301 
311  public function composeAndGetMessage($a_user_id, $a_goto_additional = null, $a_permission = "read", $a_append_signature_direct = false)
312  {
313  if ($this->compose($a_user_id, $a_goto_additional, $a_permission, $a_append_signature_direct)) {
314  return $this->body;
315  }
316  }
317 }
Add rich text string
sendMail(array $a_user_ids, $a_goto_additional=null, $a_permission="read")
Send notification(s)
initLanguage($a_usr_id)
Init language.
isRefIdAccessible($a_user_id, $a_ref_id, $a_permission="read")
Check if ref id is accessible for user.
static _getAllReferences($a_id)
get all reference ids of object
setChangedByUserId($a_id)
Set changed by user id.
Base class for course/group mail notifications.
composeAndSendMail($a_user_id, $a_goto_additional=null, $a_permission="read")
Send notification to single recipient.
setIntroductionDirect($a_text)
Set introduction text.
setTaskLangId($a_lang_id)
Set task lang id.
getObjectTitle($a_shorten=false)
static getNamePresentation( $a_user_id, $a_user_image=false, $a_profile_link=false, $a_profile_back_link="", $a_force_first_lastname=false, $a_omit_login=false, $a_sortable=true, $a_return_data_array=false, $a_ctrl_path="ilpublicuserprofilegui")
Default behaviour is:
getObjType()
Get object type.
setIntroductionLangId($a_lang_id)
Set introduction lang id.
Create styles array
The data for the language used.
addAdditionalInfo($a_lang_id, $a_value, $a_multiline=false, $a_lang_direct=false)
Add additional information.
compose($a_user_id, $a_goto_additional=null, $a_permission="read", $a_append_signature_direct=false)
Compose notification to single recipient.
getBlockBorder()
Get (ascii) block border.
createPermanentLink($a_params=array(), $a_append='')
setSubjectLangId($a_lang_id)
Set subject lang id.
static _getAutoGeneratedMessageString(ilLanguage $lang=null)
Get auto generated info string.
appendBody($a_body)
Append body text.
composeAndGetMessage($a_user_id, $a_goto_additional=null, $a_permission="read", $a_append_signature_direct=false)
Compose notification to single recipient.
setReasonLangId($a_lang_id)
Set reason lang id.
Wrapper classes for system notifications.
setGotoLangId($a_lang_id)
Set goto lang id.
static _getInstallationSignature()
static getSalutation($a_usr_id, ilLanguage $a_language=null)