ILIAS  trunk Revision v11.0_alpha-1761-g6dbbfa7b760
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
ILIAS\Wiki\Notification\NotificationGUI Class Reference

This class is only in GUI layer, since it needs to get the abstracts for the page GUI. More...

+ Collaboration diagram for ILIAS\Wiki\Notification\NotificationGUI:

Public Member Functions

 __construct (InternalDomainService $domain_service, InternalGUIService $gui_service)
 
 send (string $a_action, int $a_type, int $a_wiki_ref_id, int $a_page_id, ?string $a_comment=null, string $lang="-")
 

Protected Attributes

ilLogger $log
 
InternalGUIService $gui
 
InternalDomainService $domain
 

Detailed Description

This class is only in GUI layer, since it needs to get the abstracts for the page GUI.

Definition at line 30 of file NotificationGUI.php.

Constructor & Destructor Documentation

◆ __construct()

ILIAS\Wiki\Notification\NotificationGUI::__construct ( InternalDomainService  $domain_service,
InternalGUIService  $gui_service 
)

Definition at line 36 of file NotificationGUI.php.

References ILIAS\Wiki\InternalDomainService\log().

39  {
40  $this->gui = $gui_service;
41  $this->domain = $domain_service;
42  $this->log = $domain_service->log();
43  }
+ Here is the call graph for this function:

Member Function Documentation

◆ send()

ILIAS\Wiki\Notification\NotificationGUI::send ( string  $a_action,
int  $a_type,
int  $a_wiki_ref_id,
int  $a_page_id,
?string  $a_comment = null,
string  $lang = "-" 
)

Definition at line 45 of file NotificationGUI.php.

References $DIC, $lang, ILIAS\Wiki\Notification\NotificationGUI\$log, $message, $user_id, ilMail\_getInstallationSignature(), ilLanguageFactory\_getLanguageOfUser(), ilObjUser\_lookupFullname(), ilObjUser\_lookupLogin(), ANONYMOUS_USER_ID, ilLogger\debug(), ilUserUtil\getNamePresentation(), ilNotification\getNotificationsForObject(), null, ilPageObject\truncateHTML(), ilNotification\TYPE_WIKI, ilNotification\TYPE_WIKI_PAGE, and ilNotification\updateNotificationTime().

52  : void {
53  global $DIC;
54 
55  if ($a_wiki_ref_id === 0) {
56  return;
57  }
58 
59  if ($lang === "") {
60  $lang = "-";
61  }
62 
63  $log = $this->log;
64  $log->debug("start... vvvvvvvvvvvvvvvvvvvvvvvvvvv");
65 
66  $ilUser = $this->domain->user();
67  $ilAccess = $this->domain->access();
68 
69  $wiki = $this->domain->wiki()->object($a_wiki_ref_id);
70  $wiki_id = $wiki->getId();
71  $log->debug("page id: " . $a_page_id);
72  $log->debug("lang: " . $lang);
73  $pgui = $this->gui->page()->getWikiPageGUI(
74  $a_wiki_ref_id,
75  $a_page_id,
76  0,
77  $lang
78  );
79  $page = $pgui->getPageObject();
80 
81  // #11138
82  $ignore_threshold = ($a_action === "comment");
83 
84  // 1st update will be converted to new - see below
85  if ($a_action === "new") {
86  return;
87  }
88 
89  $log->debug("-- get notifications");
90  if ($a_type === \ilNotification::TYPE_WIKI_PAGE) {
91  $users = \ilNotification::getNotificationsForObject($a_type, $a_page_id, null, $ignore_threshold);
92  $wiki_users = \ilNotification::getNotificationsForObject(\ilNotification::TYPE_WIKI, $wiki_id, $a_page_id, $ignore_threshold);
93  $users = array_merge($users, $wiki_users);
94  if (!count($users)) {
95  $log->debug("no notifications... ^^^^^^^^^^^^^^^^^^");
96  return;
97  }
99  } else {
100  $users = \ilNotification::getNotificationsForObject(\ilNotification::TYPE_WIKI, $wiki_id, $a_page_id, $ignore_threshold);
101  if (!count($users)) {
102  $log->debug("no notifications... ^^^^^^^^^^^^^^^^^^");
103  return;
104  }
105  }
106 
108 
109  // #15192 - should always be present
110  if ($a_page_id) {
111  // #18804 - see ilWikiPageGUI::preview()
112  $link = \ilLink::_getLink(null, "wiki", [], "wpage_" . $a_page_id . "_" . $a_wiki_ref_id);
113  } else {
114  $link = \ilLink::_getLink($a_wiki_ref_id);
115  }
116 
117  $log->debug("-- prepare content");
118  $pgui->setRawPageContent(true);
119  $pgui->setAbstractOnly(true);
120  $pgui->setFileDownloadLink(".");
121  $pgui->setFullscreenLink(".");
122  $pgui->setSourcecodeDownloadScript(".");
123  $snippet = $pgui->showPage();
124  $snippet = \ilPageObject::truncateHTML($snippet, 500, "...");
125 
126  // making things more readable
127  $snippet = str_replace(['<br/>', '<br />', '</p>', '</div>'], "\n", $snippet);
128 
129  $snippet = trim(strip_tags($snippet));
130 
131  // "fake" new (to enable snippet - if any)
132  $hist = $page->getHistoryEntries();
133  $current_version = array_shift($hist);
134  $current_version = $current_version["nr"] ?? 0;
135  if (!$current_version && $a_action !== "comment") {
136  $a_type = \ilNotification::TYPE_WIKI;
137  $a_action = "new";
138  }
139 
140  $log->debug("-- sending mails");
141  $mails = [];
142  foreach (array_unique($users) as $idx => $user_id) {
143  if ($user_id !== $ilUser->getId() &&
144  $ilAccess->checkAccessOfUser($user_id, 'read', '', $a_wiki_ref_id)) {
145  // use language of recipient to compose message
147  $ulng->loadLanguageModule('wiki');
148 
149  if ($a_action === "comment") {
150  $subject = sprintf($ulng->txt('wiki_notification_comment_subject'), $wiki->getTitle(), $page->getTitle());
151  $message = sprintf($ulng->txt('wiki_change_notification_salutation'), \ilObjUser::_lookupFullname($user_id)) . "\n\n";
152 
153  $message .= $ulng->txt('wiki_notification_' . $a_action) . ":\n\n";
154  $message .= $ulng->txt('wiki') . ": " . $wiki->getTitle() . "\n";
155  $message .= $ulng->txt('page') . ": " . $page->getTitle() . "\n";
156  $message .= $ulng->txt('wiki_commented_by') . ": " . \ilUserUtil::getNamePresentation($ilUser->getId()) . "\n";
157 
158  // include comment/note text
159  if ($a_comment) {
160  $message .= "\n" . $ulng->txt('comment') . ":\n\"" . trim($a_comment) . "\"\n";
161  }
162 
163  $message .= "\n" . $ulng->txt('wiki_change_notification_page_link') . ": " . $link;
164  } else {
165  $subject = sprintf($ulng->txt('wiki_change_notification_subject'), $wiki->getTitle(), $page->getTitle());
166  $message = sprintf($ulng->txt('wiki_change_notification_salutation'), \ilObjUser::_lookupFullname($user_id)) . "\n\n";
167 
168  if ($a_type == \ilNotification::TYPE_WIKI_PAGE) {
169  // update/delete
170  $message .= $ulng->txt('wiki_change_notification_page_body_' . $a_action) . ":\n\n";
171  $message .= $ulng->txt('wiki') . ": " . $wiki->getTitle() . "\n";
172  $message .= $ulng->txt('page') . ": " . $page->getTitle() . "\n";
173  $message .= $ulng->txt('wiki_changed_by') . ": " . \ilUserUtil::getNamePresentation($ilUser->getId()) . "\n";
174 
175  if ($snippet) {
176  $message .= "\n" . $ulng->txt('content') . "\n" .
177  "----------------------------------------\n" .
178  $snippet . "\n" .
179  "----------------------------------------\n";
180  }
181 
182  // include comment/note text
183  if ($a_comment) {
184  $message .= "\n" . $ulng->txt('comment') . ":\n\"" . trim($a_comment) . "\"\n";
185  }
186 
187  $message .= "\n" . $ulng->txt('wiki_change_notification_page_link') . ": " . $link;
188  } else {
189  // new
190  $message .= $ulng->txt('wiki_change_notification_body_' . $a_action) . ":\n\n";
191  $message .= $ulng->txt('wiki') . ": " . $wiki->getTitle() . "\n";
192  $message .= $ulng->txt('page') . ": " . $page->getTitle() . "\n";
193  $message .= $ulng->txt('wiki_changed_by') . ": " . \ilUserUtil::getNamePresentation($ilUser->getId()) . "\n\n";
194 
195  if ($snippet) {
196  $message .= $ulng->txt('content') . "\n" .
197  "----------------------------------------\n" .
198  $snippet . "\n" .
199  "----------------------------------------\n\n";
200  }
201 
202  $message .= $ulng->txt('wiki_change_notification_link') . ": " . $link;
203  }
204  }
205 
206  $mail_obj = new \ilMail(ANONYMOUS_USER_ID);
207  $mail_obj->appendInstallationSignature(true);
208  $log->debug("before enqueue ($user_id)");
209  /*
210  $mail_obj->enqueue(
211  ilObjUser::_lookupLogin($user_id),
212  "",
213  "",
214  $subject,
215  $message,
216  array()
217  );*/
219  $mails[] = new \ilMailValueObject(
220  '',
222  '',
223  '',
224  $subject,
225  $message,
226  [],
227  false,
228  false
229  );
230  $log->debug("after enqueue");
231  } else {
232  unset($users[$idx]);
233  }
234  }
235  if (count($mails) > 0) {
236  $processor = new \ilMassMailTaskProcessor();
237  $processor->run(
238  $mails,
240  "",
241  []
242  );
243  }
244  $log->debug("end... ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^");
245  }
const ANONYMOUS_USER_ID
Definition: constants.php:27
static _lookupFullname(int $a_user_id)
static getNotificationsForObject(int $type, int $id, ?int $page_id=null, bool $ignore_threshold=false)
Get all users/recipients for given object.
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
static truncateHTML(string $a_text, int $a_length=100, string $a_ending='...', bool $a_exact=false, bool $a_consider_html=true)
Truncate (html) string.
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 _getLanguageOfUser(int $a_usr_id)
Get language object of user.
global $DIC
Definition: shib_login.php:22
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.
$lang
Definition: xapiexit.php:25
$message
Definition: xapiexit.php:31
debug(string $message, array $context=[])
static _getInstallationSignature()
static _lookupLogin(int $a_user_id)
+ Here is the call graph for this function:

Field Documentation

◆ $domain

InternalDomainService ILIAS\Wiki\Notification\NotificationGUI::$domain
protected

Definition at line 34 of file NotificationGUI.php.

◆ $gui

InternalGUIService ILIAS\Wiki\Notification\NotificationGUI::$gui
protected

Definition at line 33 of file NotificationGUI.php.

◆ $log

ilLogger ILIAS\Wiki\Notification\NotificationGUI::$log
protected

Definition at line 32 of file NotificationGUI.php.

Referenced by ILIAS\Wiki\Notification\NotificationGUI\send().


The documentation for this class was generated from the following file: