ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
ilLearningModuleNotification Class Reference

Class ilLearningModuleNotification class. More...

+ Collaboration diagram for ilLearningModuleNotification:

Public Member Functions

 __construct (string $a_action, int $a_type, ilObjLearningModule $a_learning_module, int $a_page_id, string $a_comment=null)
 ilLearningModuleNotification constructor. More...
 
 send ()
 Generate notifications and send them if necessary. More...
 

Data Fields

const ACTION_COMMENT = "comment"
 
const ACTION_UPDATE = "update"
 

Protected Member Functions

 getLink ()
 Get Link to the LM page. More...
 
 getPageTitle ()
 Get formatted title page. More...
 
 getMailSubject (ilLanguage $ulng)
 get Subject of mail/notification More...
 
 getMailBody (ilLanguage $a_ulng, int $a_user_id)
 get email/notification body More...
 
 getPreviewText (ilLanguage $a_ulng)
 Get first 500 characters of the recently added content behavior copied from ilWikiUtil->sendNotification. More...
 

Protected Attributes

 $ilUser
 
 $ilAccess
 
 $lng
 
 $lm_set
 
 $action
 
 $type
 
 $learning_module
 
 $page_id
 
 $comment
 
 $link
 
 $lm_ref_id
 
 $pg_title
 

Detailed Description

Class ilLearningModuleNotification class.

//TODO create an interface for notifications contract.(ilnotification?).Similar code in ilwikipage, ilblogposting

Author
Jesús López lopez.nosp@m.@lei.nosp@m.fos.c.nosp@m.om
Version
$Id$

Definition at line 14 of file class.ilLearningModuleNotification.php.

Constructor & Destructor Documentation

◆ __construct()

ilLearningModuleNotification::__construct ( string  $a_action,
int  $a_type,
ilObjLearningModule  $a_learning_module,
int  $a_page_id,
string  $a_comment = null 
)

ilLearningModuleNotification constructor.

Parameters
string$a_action
int$a_typeNotification type e.g. ilNotification::TYPE_LM_PAGE
ilObjLearningModule$a_learning_module
int$a_page_id
string | null$a_comment

Definition at line 87 of file class.ilLearningModuleNotification.php.

References $DIC, comment(), getLink(), and getPageTitle().

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  }
comment()
Definition: comment.php:2
global $DIC
Definition: goto.php:24
+ Here is the call graph for this function:

Member Function Documentation

◆ getLink()

ilLearningModuleNotification::getLink ( )
protected

Get Link to the LM page.

Returns
string

Definition at line 159 of file class.ilLearningModuleNotification.php.

References ilLink\_getLink().

Referenced by __construct().

159  : 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  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getMailBody()

ilLearningModuleNotification::getMailBody ( ilLanguage  $a_ulng,
int  $a_user_id 
)
protected

get email/notification body

Parameters
ilLanguage$a_ulng
int$a_user_id
Returns
string

Definition at line 207 of file class.ilLearningModuleNotification.php.

References $link, $message, ilObjUser\_lookupFullname(), comment(), ilUserUtil\getNamePresentation(), getPreviewText(), and ilLanguage\txt().

Referenced by send().

207  : 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  }
static _lookupFullname($a_user_id)
Lookup Full Name.
comment()
Definition: comment.php:2
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:
getPreviewText(ilLanguage $a_ulng)
Get first 500 characters of the recently added content behavior copied from ilWikiUtil->sendNotificat...
$message
Definition: xapiexit.php:14
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...
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getMailSubject()

ilLearningModuleNotification::getMailSubject ( ilLanguage  $ulng)
protected

get Subject of mail/notification

Parameters
ilLanguage$ulng
Returns
string

Definition at line 192 of file class.ilLearningModuleNotification.php.

References $pg_title, and ilLanguage\txt().

Referenced by send().

192  : 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  }
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...
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getPageTitle()

ilLearningModuleNotification::getPageTitle ( )
protected

Get formatted title page.

Returns
string

Definition at line 174 of file class.ilLearningModuleNotification.php.

References ilLMPageObject\_getPresentationTitle().

Referenced by __construct().

174  : 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  }
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...
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getPreviewText()

ilLearningModuleNotification::getPreviewText ( ilLanguage  $a_ulng)
protected

Get first 500 characters of the recently added content behavior copied from ilWikiUtil->sendNotification.

Parameters
ilLanguage$a_ulng
Returns
string

Definition at line 232 of file class.ilLearningModuleNotification.php.

References ilPageObject\truncateHTML(), and ilLanguage\txt().

Referenced by getMailBody().

232  : 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  }
Extension of ilPageObjectGUI for learning modules.
static truncateHTML( $a_text, $a_length=100, $a_ending='...', $a_exact=false, $a_consider_html=true)
Truncate (html) string.
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...
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ send()

ilLearningModuleNotification::send ( )

Generate notifications and send them if necessary.

Definition at line 109 of file class.ilLearningModuleNotification.php.

References $message, ilLanguageFactory\_getLanguageOfUser(), ilObjUser\_lookupLogin(), ANONYMOUS_USER_ID, getMailBody(), getMailSubject(), ilNotification\getNotificationsForObject(), ilNotification\TYPE_LM, ilNotification\TYPE_LM_PAGE, and ilNotification\updateNotificationTime().

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 
128  ilNotification::updateNotificationTime(ilNotification::TYPE_LM, $lm_id, $users, $this->page_id);
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
135  $ulng = ilLanguageFactory::_getLanguageOfUser($user_id);
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  }
static _lookupLogin($a_user_id)
lookup login
const ANONYMOUS_USER_ID
Definition: constants.php:25
getMailSubject(ilLanguage $ulng)
get Subject of mail/notification
static updateNotificationTime($type, $id, array $user_ids, $page_id=false)
Update the last mail timestamp for given object and users.
static getNotificationsForObject($type, $id, $page_id=null, $ignore_threshold=false)
Get all users for given object.
static _getLanguageOfUser($a_usr_id)
Get language object of user.
$message
Definition: xapiexit.php:14
getMailBody(ilLanguage $a_ulng, int $a_user_id)
get email/notification body
+ Here is the call graph for this function:

Field Documentation

◆ $action

ilLearningModuleNotification::$action
protected

Definition at line 42 of file class.ilLearningModuleNotification.php.

◆ $comment

ilLearningModuleNotification::$comment
protected

Definition at line 62 of file class.ilLearningModuleNotification.php.

◆ $ilAccess

ilLearningModuleNotification::$ilAccess
protected

Definition at line 26 of file class.ilLearningModuleNotification.php.

◆ $ilUser

ilLearningModuleNotification::$ilUser
protected

Definition at line 21 of file class.ilLearningModuleNotification.php.

◆ $learning_module

ilLearningModuleNotification::$learning_module
protected

Definition at line 52 of file class.ilLearningModuleNotification.php.

◆ $link

ilLearningModuleNotification::$link
protected

Definition at line 67 of file class.ilLearningModuleNotification.php.

Referenced by getMailBody().

◆ $lm_ref_id

ilLearningModuleNotification::$lm_ref_id
protected

Definition at line 72 of file class.ilLearningModuleNotification.php.

◆ $lm_set

ilLearningModuleNotification::$lm_set
protected

Definition at line 36 of file class.ilLearningModuleNotification.php.

◆ $lng

ilLearningModuleNotification::$lng
protected

Definition at line 31 of file class.ilLearningModuleNotification.php.

◆ $page_id

ilLearningModuleNotification::$page_id
protected

Definition at line 57 of file class.ilLearningModuleNotification.php.

◆ $pg_title

ilLearningModuleNotification::$pg_title
protected

Definition at line 77 of file class.ilLearningModuleNotification.php.

Referenced by getMailSubject().

◆ $type

ilLearningModuleNotification::$type
protected

Definition at line 47 of file class.ilLearningModuleNotification.php.

◆ ACTION_COMMENT

const ilLearningModuleNotification::ACTION_COMMENT = "comment"

◆ ACTION_UPDATE

const ilLearningModuleNotification::ACTION_UPDATE = "update"

Definition at line 17 of file class.ilLearningModuleNotification.php.

Referenced by ilLMPage\afterUpdate().


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