ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilLearningModuleNotification.php
Go to the documentation of this file.
1<?php
2
27{
28 public const ACTION_COMMENT = "comment";
29 public const ACTION_UPDATE = "update";
30
31 protected ilObjUser $ilUser;
33 protected ilLanguage $lng;
34 protected ilSetting $lm_set;
35 protected string $action;
36 protected int $type;
38 protected int $page_id;
39 protected string $comment;
40 protected string $link;
41 protected int $lm_ref_id;
42 protected string $pg_title;
43
47 public function __construct(
48 string $a_action,
49 int $a_type,
50 ilObjLearningModule $a_learning_module,
51 int $a_page_id,
52 string $a_comment = ""
53 ) {
54 global $DIC;
55
56 $this->ilUser = $DIC->user();
57 $this->ilAccess = $DIC->access();
58 $this->lng = $DIC->language();
59 $this->lng->loadLanguageModule("content");
60 $this->lm_set = new ilSetting("lm");
61 $this->action = $a_action;
62 $this->type = $a_type;
63 $this->learning_module = $a_learning_module;
64 $this->page_id = $a_page_id;
65 $this->comment = $a_comment;
66 $this->lm_ref_id = $this->learning_module->getRefId();
67 $this->link = $this->getLink();
68 $this->pg_title = $this->getPageTitle();
69 }
70
71 // Generate notifications and send them if necessary
72 public function send(): void
73 {
74 $lm_id = $this->learning_module->getId();
75
76 // #11138 //only comment implemented so always true.
77 $ignore_threshold = ($this->action == self::ACTION_COMMENT);
78
79 $users = ilNotification::getNotificationsForObject(ilNotification::TYPE_LM, $lm_id, null, $ignore_threshold);
80
81 if ($this->type == ilNotification::TYPE_LM_PAGE) {
82 $page_users = ilNotification::getNotificationsForObject($this->type, $this->page_id, null, $ignore_threshold);
83 $users = array_merge($users, $page_users);
85 }
86
87 if (!sizeof($users)) {
88 return;
89 }
90
92
93
94 foreach (array_unique($users) as $idx => $user_id) {
95 if ($user_id != $this->ilUser->getId() &&
96 $this->ilAccess->checkAccessOfUser($user_id, 'read', '', $this->lm_ref_id)) {
97 // use language of recipient to compose message
99 $ulng->loadLanguageModule('content');
100
101 $subject = $this->getMailSubject($ulng);
102 $message = $this->getMailBody($ulng, $user_id);
103
104 $mail_obj = new ilMail(ANONYMOUS_USER_ID);
105 $mail_obj->appendInstallationSignature(true);
106 $mail_obj->enqueue(
108 "",
109 "",
110 $subject,
111 $message,
112 []
113 );
114 }
115 }
116 }
117
118 protected function getLink(): string
119 {
120 // #15192 - should always be present
121 if ($this->page_id) {
122 // #18804 - see ilWikiPageGUI::preview()
123 return ilLink::_getLink(null, "pg", [], $this->page_id . "_" . $this->lm_ref_id);
124 }
125
126 return ilLink::_getLink($this->lm_ref_id);
127 }
128
129 protected function getPageTitle(): string
130 {
132 $this->page_id,
133 $this->learning_module->getPageHeader(),
134 $this->learning_module->isActiveNumbering(),
135 $this->lm_set->get("time_scheduled_page_activation"),
136 false,
137 0,
138 $this->lng->getLangKey()
139 );
140 }
141
142 protected function getMailSubject(ilLanguage $ulng): string
143 {
144 if ($this->action == self::ACTION_COMMENT) {
145 return sprintf($ulng->txt('cont_notification_comment_subject_lm'), $this->learning_module->getTitle(), $this->pg_title);
146 }
147
148 return sprintf($ulng->txt('cont_change_notification_subject_lm'), $this->learning_module->getTitle(), $this->pg_title);
149 }
150
151 protected function getMailBody(ilLanguage $a_ulng, int $a_user_id): string
152 {
153 $message = sprintf($a_ulng->txt('cont_change_notification_salutation'), ilObjUser::_lookupFullname($a_user_id)) . "\n\n";
154 $message .= $a_ulng->txt('cont_notification_' . $this->action . "_lm") . ":\n\n";
155 $message .= $a_ulng->txt('learning module') . ": " . $this->learning_module->getTitle() . "\n";
156 $message .= $a_ulng->txt('page') . ": " . $this->pg_title . "\n";
157 if ($this->action == self::ACTION_COMMENT) {
158 // include comment/note text
159 $message .= $a_ulng->txt('cont_commented_by') . ": " . ilUserUtil::getNamePresentation($this->ilUser->getId()) . "\n";
160 $message .= "\n" . $a_ulng->txt('comment') . ":\n\"" . trim($this->comment) . "\"\n";
161 } else {
162 $message .= $this->getPreviewText($a_ulng);
163 }
164
165 $message .= "\n" . $a_ulng->txt('url') . ": " . $this->link;
166
167 return $message;
168 }
169
170 protected function getPreviewText(ilLanguage $a_ulng): string
171 {
172 $page = new ilLMPageGUI($this->page_id);
173 $page->setRawPageContent(true);
174 $page->setAbstractOnly(true);
175 $page->setFileDownloadLink(".");
176 $page->setFullscreenLink(".");
177 $page->setSourcecodeDownloadScript(".");
178 $str = $page->showPage();
179 $str = ilPageObject::truncateHTML($str, 500, "...");
180 // making things more readable
181 $str = str_replace('<br/>', "\n", $str);
182 $str = str_replace('<br />', "\n", $str);
183 $str = str_replace('</p>', "\n", $str);
184 $str = str_replace('</div>', "\n", $str);
185 $str = trim(strip_tags($str));
186
187 $content = "\n" . $a_ulng->txt('content') . "\n" .
188 "----------------------------------------\n" .
189 $str . "\n" .
190 "----------------------------------------\n";
191
192 return $content;
193 }
194}
Class ilAccessHandler Checks access for ILIAS objects.
Extension of ilPageObjectGUI for learning modules.
static _getPresentationTitle(int $a_pg_id, string $a_mode=self::CHAPTER_TITLE, bool $a_include_numbers=false, bool $a_time_scheduled_activation=false, bool $a_force_content=false, int $a_lm_id=0, string $a_lang="-", bool $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(int $a_usr_id)
Get language object of user.
language handling
txt(string $a_topic, string $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...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getMailBody(ilLanguage $a_ulng, int $a_user_id)
__construct(string $a_action, int $a_type, ilObjLearningModule $a_learning_module, int $a_page_id, string $a_comment="")
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.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
User class.
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.
ILIAS Setting Class.
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
Interface ilAccessHandler This interface combines all available interfaces which can be called via gl...
link(string $caption, string $href, bool $new_viewport=false)
global $DIC
Definition: shib_login.php:26
$message
Definition: xapiexit.php:31