ILIAS  trunk Revision v11.0_alpha-1713-gd8962da2f67
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
class.NotificationsManager.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
21 namespace ILIAS\Notes;
22 
27 {
28  protected \ilAccessHandler $access;
29  protected \ilSetting $settings;
33 
34  public function __construct(
35  InternalDataService $data,
36  InternalRepoService $repo,
37  InternalDomainService $domain
38  ) {
39  $this->data = $data;
40  $this->repo = $repo;
41  $this->domain = $domain;
42  $this->settings = $domain->settings();
43  $this->access = $domain->access();
44  }
45 
51  public function sendNotifications(
52  Note $note,
53  bool $a_changed = false
54  ): void {
55  $settings = $this->settings;
56  $access = $this->access;
57 
58  $obj_title = "";
59  $type_lv = "";
60 
61  // no notifications for notes
62  if ($note->getType() === Note::PRIVATE) {
63  return;
64  }
65 
66  $recipients = $settings->get("comments_noti_recip", '');
67  $recipients = explode(",", $recipients);
68 
69  // blog: blog_id, 0, "blog"
70  // lm: lm_id, page_id, "pg" (ok)
71  // sahs: sahs_id, node_id, node_type
72  // info_screen: obj_id, 0, obj_type (ok)
73  // portfolio: port_id, page_id, "portfolio_page" (ok)
74  // wiki: wiki_id, wiki_page_id, "wpg" (ok)
75 
76  $context = $note->getContext();
77  $rep_obj_id = $context->getObjId();
78  $sub_obj_id = $context->getSubObjId();
79  $obj_type = $context->getType();
80 
81  // repository objects, no blogs
82  $ref_ids = array();
83  if (($sub_obj_id === 0 && $obj_type !== "blp") || in_array($obj_type, array("pg", "wpg"), true)) {
84  $obj_title = \ilObject::_lookupTitle($rep_obj_id);
85  $type_lv = "obj_" . $obj_type;
86  $ref_ids = \ilObject::_getAllReferences($rep_obj_id);
87  }
88 
89  if ($obj_type === "wpg") {
90  $type_lv = "obj_wiki";
91  }
92  if ($obj_type === "pg") {
93  $type_lv = "obj_lm";
94  }
95  if ($obj_type === "blp") {
96  $obj_title = \ilObject::_lookupTitle($rep_obj_id);
97  $type_lv = "obj_blog";
98  }
99  if ($obj_type === "pfpg") {
100  $obj_title = \ilObject::_lookupTitle($rep_obj_id);
101  $type_lv = "portfolio";
102  }
103  if ($obj_type === "dcl") {
104  $obj_title = \ilObject::_lookupTitle($rep_obj_id);
105  $type_lv = "obj_dcl";
106  }
107 
108  foreach ($recipients as $r) {
109  $login = trim($r);
110  if (($user_id = \ilObjUser::_lookupId($login)) > 0) {
111  $link = "";
112  foreach ($ref_ids as $ref_id) {
113  if ($access->checkAccessOfUser($user_id, "read", "", $ref_id)) {
114  if ($sub_obj_id === 0 && $obj_type !== "blog") {
115  $link = \ilLink::_getLink($ref_id);
116  } elseif ($obj_type === "wpg") {
117  $title = \ilWikiPage::lookupTitle($sub_obj_id);
118  $link = \ilLink::_getStaticLink(
119  $ref_id,
120  "wiki",
121  true,
122  "_" . \ilWikiUtil::makeUrlTitle($title)
123  );
124  } elseif ($obj_type === "pg") {
125  $link = ILIAS_HTTP_PATH . '/goto.php?client_id=' . CLIENT_ID . "&target=pg_" . $sub_obj_id . "_" . $ref_id;
126  }
127  }
128  }
129  if ($obj_type === "blp") {
130  // todo
131  }
132  if ($obj_type === "pfpg") {
133  $link = ILIAS_HTTP_PATH . '/goto.php?client_id=' . CLIENT_ID . "&target=prtf_" . $rep_obj_id;
134  }
135 
136  // use language of recipient to compose message
138  $ulng->loadLanguageModule('note');
139 
140  if ($a_changed) {
141  $subject = sprintf($ulng->txt('note_comment_notification_subjectc'), $obj_title . " (" . $ulng->txt($type_lv) . ")");
142  } else {
143  $subject = sprintf($ulng->txt('note_comment_notification_subject'), $obj_title . " (" . $ulng->txt($type_lv) . ")");
144  }
145  $message = sprintf($ulng->txt('note_comment_notification_salutation'), \ilObjUser::_lookupFullname($user_id)) . "\n\n";
146 
147  $message .= sprintf($ulng->txt('note_comment_notification_user_has_written'), \ilUserUtil::getNamePresentation($note->getAuthor())) . "\n\n";
148 
149  $message .= $note->getText() . "\n\n";
150 
151  if ($link !== "") {
152  $message .= $ulng->txt('note_comment_notification_link') . ": " . $link . "\n\n";
153  }
154 
155  $message .= $ulng->txt('note_comment_notification_reason') . "\n\n";
156 
157  $mail_obj = new \ilMail(ANONYMOUS_USER_ID);
158  $mail_obj->appendInstallationSignature(true);
159  $mail_obj->enqueue(
161  "",
162  "",
163  $subject,
164  $message,
165  array()
166  );
167  }
168  }
169  }
170 
174  public function notifyObserver(
175  array $observer,
176  string $action,
177  Note $note
178  ): void {
179  foreach ($observer as $item) {
180  $context = $note->getContext();
181  $param[] = $context->getObjId();
182  $param[] = $context->getSubObjId();
183  $param[] = $context->getType();
184  $param[] = $action;
185  $param[] = $note->getId();
186  call_user_func_array($item, $param);
187  }
188  }
189 }
$context
Definition: webdav.php:31
const ANONYMOUS_USER_ID
Definition: constants.php:27
static _lookupFullname(int $a_user_id)
static _getAllReferences(int $id)
get all reference ids for object ID
static lookupTitle(int $a_page_id, string $lang="-")
static _lookupId($a_user_str)
Repository internal data service.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$ref_id
Definition: ltiauth.php:65
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='ilpublicuserprofilegui')
Default behaviour is:
static _lookupTitle(int $obj_id)
static _getLanguageOfUser(int $a_usr_id)
Get language object of user.
notifyObserver(array $observer, string $action, Note $note)
Notify observers on update/create.
$param
Definition: xapitoken.php:46
const CLIENT_ID
Definition: constants.php:41
__construct(InternalDataService $data, InternalRepoService $repo, InternalDomainService $domain)
sendNotifications(Note $note, bool $a_changed=false)
Sends all comments to a list of accounts configured in the global administration. ...
static makeUrlTitle(string $a_par)
$message
Definition: xapiexit.php:31
$r
static _lookupLogin(int $a_user_id)