ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilLearningModuleNotification.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 2018 Extended GPL, see docs/LICENSE */
3
15{
16 const ACTION_COMMENT = "comment";
17 const ACTION_UPDATE = "update";
21 protected $ilUser;
22
26 protected $ilAccess;
27
31 protected $lng;
32
36 protected $lm_set;
37
42 protected $action;
43
47 protected $type;
48
53
57 protected $page_id;
58
62 protected $comment;
63
67 protected $link;
68
72 protected $lm_ref_id;
73
77 protected $pg_title;
78
87 public function __construct(string $a_action, int $a_type, ilObjLearningModule $a_learning_module, int $a_page_id, string $a_comment = null)
88 {
89 global $DIC;
90
91 $this->ilUser = $DIC->user();
92 $this->ilAccess = $DIC->access();
93 $this->lng = $DIC->language();
94 $this->lng->loadLanguageModule("content");
95 $this->lm_set = new ilSetting("lm");
96 $this->action = $a_action;
97 $this->type = $a_type;
98 $this->learning_module = $a_learning_module;
99 $this->page_id = $a_page_id;
100 $this->comment = $a_comment;
101 $this->lm_ref_id = $this->learning_module->getRefId();
102 $this->link = $this->getLink();
103 $this->pg_title = $this->getPageTitle();
104 }
105
109 public function send()
110 {
111 $lm_id = $this->learning_module->getId();
112
113 // #11138 //only comment implemented so always true.
114 $ignore_threshold = ($this->action == self::ACTION_COMMENT);
115
116 $users = ilNotification::getNotificationsForObject(ilNotification::TYPE_LM, $lm_id, "", $ignore_threshold);
117
118 if ($this->type == ilNotification::TYPE_LM_PAGE) {
119 $page_users = ilNotification::getNotificationsForObject($this->type, $this->page_id, null, $ignore_threshold);
120 $users = array_merge($users, $page_users);
122 }
123
124 if (!sizeof($users)) {
125 return;
126 }
127
129
130
131 foreach (array_unique($users) as $idx => $user_id) {
132 if ($user_id != $this->ilUser->getId() &&
133 $this->ilAccess->checkAccessOfUser($user_id, 'read', '', $this->lm_ref_id)) {
134 // use language of recipient to compose message
136 $ulng->loadLanguageModule('content');
137
138 $subject = $this->getMailSubject($ulng);
139 $message = $this->getMailBody($ulng, $user_id);
140
141 $mail_obj = new ilMail(ANONYMOUS_USER_ID);
142 $mail_obj->appendInstallationSignature(true);
143 $mail_obj->enqueue(
144 ilObjUser::_lookupLogin($user_id),
145 "",
146 "",
147 $subject,
148 $message,
149 []
150 );
151 }
152 }
153 }
154
159 protected function getLink() : string
160 {
161 // #15192 - should always be present
162 if ($this->page_id) {
163 // #18804 - see ilWikiPageGUI::preview()
164 return ilLink::_getLink("", "pg", null, $this->page_id . "_" . $this->lm_ref_id);
165 }
166
167 return ilLink::_getLink($this->lm_ref_id);
168 }
169
174 protected function getPageTitle() : string
175 {
177 $this->page_id,
178 $this->learning_module->getPageHeader(),
179 $this->learning_module->isActiveNumbering(),
180 $this->lm_set->get("time_scheduled_page_activation"),
181 false,
182 0,
183 $this->lng->getLangKey()
184 );
185 }
186
192 protected function getMailSubject(ilLanguage $ulng) : string
193 {
194 if ($this->action == self::ACTION_COMMENT) {
195 return sprintf($ulng->txt('cont_notification_comment_subject_lm'), $this->learning_module->getTitle(), $this->pg_title);
196 }
197
198 return sprintf($ulng->txt('cont_change_notification_subject_lm'), $this->learning_module->getTitle(), $this->pg_title);
199 }
200
207 protected function getMailBody(ilLanguage $a_ulng, int $a_user_id) : string
208 {
209 $message = sprintf($a_ulng->txt('cont_change_notification_salutation'), ilObjUser::_lookupFullname($a_user_id)) . "\n\n";
210 $message .= $a_ulng->txt('cont_notification_' . $this->action . "_lm") . ":\n\n";
211 $message .= $a_ulng->txt('learning module') . ": " . $this->learning_module->getTitle() . "\n";
212 $message .= $a_ulng->txt('page') . ": " . $this->pg_title . "\n";
213 if ($this->action == self::ACTION_COMMENT) {
214 // include comment/note text
215 $message .= $a_ulng->txt('cont_commented_by') . ": " . ilUserUtil::getNamePresentation($this->ilUser->getId()) . "\n";
216 $message .= "\n" . $a_ulng->txt('comment') . ":\n\"" . trim($this->comment) . "\"\n";
217 } else {
218 $message .= $this->getPreviewText($a_ulng);
219 }
220
221 $message .= "\n" . $a_ulng->txt('url') . ": " . $this->link;
222
223 return $message;
224 }
225
232 protected function getPreviewText(ilLanguage $a_ulng) : string
233 {
234 $page = new ilLMPageGUI($this->page_id);
235 $page->setRawPageContent(true);
236 $page->setAbstractOnly(true);
237 $page->setFileDownloadLink(".");
238 $page->setFullscreenLink(".");
239 $page->setSourcecodeDownloadScript(".");
240 $str = $page->showPage();
241 $str = ilPageObject::truncateHTML($str, 500, "...");
242 // making things more readable
243 $str = str_replace('<br/>', "\n", $str);
244 $str = str_replace('<br />', "\n", $str);
245 $str = str_replace('</p>', "\n", $str);
246 $str = str_replace('</div>', "\n", $str);
247 $str = trim(strip_tags($str));
248
249 $content = "\n" . $a_ulng->txt('content') . "\n" .
250 "----------------------------------------\n" .
251 $str . "\n" .
252 "----------------------------------------\n";
253
254 return $content;
255 }
256}
An exception for terminatinating execution or to throw for unit testing.
Class ilAccessHandler.
Extension of ilPageObjectGUI for learning modules.
static _getPresentationTitle( $a_pg_id, $a_mode=self::CHAPTER_TITLE, $a_include_numbers=false, $a_time_scheduled_activation=false, $a_force_content=false, $a_lm_id=0, $a_lang="-", $a_include_short=false)
presentation title doesn't have to be page title, it may be chapter title + page title or chapter tit...
static _getLanguageOfUser($a_usr_id)
Get language object of user.
language handling
txt($a_topic, $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
Class ilLearningModuleNotification class.
send()
Generate notifications and send them if necessary.
getMailSubject(ilLanguage $ulng)
get Subject of mail/notification
getPreviewText(ilLanguage $a_ulng)
Get first 500 characters of the recently added content behavior copied from ilWikiUtil->sendNotificat...
getMailBody(ilLanguage $a_ulng, int $a_user_id)
get email/notification body
__construct(string $a_action, int $a_type, ilObjLearningModule $a_learning_module, int $a_page_id, string $a_comment=null)
ilLearningModuleNotification constructor.
static getNotificationsForObject($type, $id, $page_id=null, $ignore_threshold=false)
Get all users for given object.
static updateNotificationTime($type, $id, array $user_ids, $page_id=false)
Update the last mail timestamp for given object and users.
Class ilObjLearningModule.
static _lookupLogin($a_user_id)
lookup login
static _lookupFullname($a_user_id)
Lookup Full Name.
static truncateHTML( $a_text, $a_length=100, $a_ending='...', $a_exact=false, $a_consider_html=true)
Truncate (html) string.
ILIAS Setting Class.
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:
comment()
Definition: comment.php:2
const ANONYMOUS_USER_ID
Definition: constants.php:25
global $DIC
Definition: goto.php:24
$message
Definition: xapiexit.php:14