|
|
|
@ -4,13 +4,22 @@ |
|
|
|
|
/** |
|
|
|
|
* Notification class |
|
|
|
|
* This class provides methods for the Notification management. |
|
|
|
|
* Include/require it in your code to use its features. |
|
|
|
|
* Include/require it in your code to use its features. |
|
|
|
|
* @package chamilo.library |
|
|
|
|
*/ |
|
|
|
|
class Notification extends Model |
|
|
|
|
{ |
|
|
|
|
public $table; |
|
|
|
|
public $columns = array('id', 'dest_user_id', 'dest_mail', 'title', 'content', 'send_freq', 'created_at', 'sent_at'); |
|
|
|
|
public $columns = array( |
|
|
|
|
'id', |
|
|
|
|
'dest_user_id', |
|
|
|
|
'dest_mail', |
|
|
|
|
'title', |
|
|
|
|
'content', |
|
|
|
|
'send_freq', |
|
|
|
|
'created_at', |
|
|
|
|
'sent_at' |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
//Max length of the notification.content field |
|
|
|
|
public $max_content_length = 254; |
|
|
|
@ -54,7 +63,12 @@ class Notification extends Model |
|
|
|
|
// If no-reply email doesn't exist use the admin email |
|
|
|
|
if (empty($this->admin_email)) { |
|
|
|
|
$this->admin_email = api_get_setting('emailAdministrator'); |
|
|
|
|
$this->admin_name = api_get_person_name(api_get_setting('administratorName'), api_get_setting('administratorSurname'), null, PERSON_NAME_EMAIL_ADDRESS); |
|
|
|
|
$this->admin_name = api_get_person_name( |
|
|
|
|
api_get_setting('administratorName'), |
|
|
|
|
api_get_setting('administratorSurname'), |
|
|
|
|
null, |
|
|
|
|
PERSON_NAME_EMAIL_ADDRESS |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -64,7 +78,10 @@ class Notification extends Model |
|
|
|
|
*/ |
|
|
|
|
public function send($frequency = 8) |
|
|
|
|
{ |
|
|
|
|
$notifications = $this->find('all', array('where' => array('sent_at IS NULL AND send_freq = ?' => $frequency))); |
|
|
|
|
$notifications = $this->find( |
|
|
|
|
'all', |
|
|
|
|
array('where' => array('sent_at IS NULL AND send_freq = ?' => $frequency)) |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
if (!empty($notifications)) { |
|
|
|
|
foreach ($notifications as $item_to_send) { |
|
|
|
@ -93,14 +110,23 @@ class Notification extends Model |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Save message notification |
|
|
|
|
* @param array message type NOTIFICATION_TYPE_MESSAGE, NOTIFICATION_TYPE_INVITATION, NOTIFICATION_TYPE_GROUP |
|
|
|
|
* @param array recipients: user list of ids |
|
|
|
|
* @param string title |
|
|
|
|
* @param string content of the message |
|
|
|
|
* @param array result of api_get_user_info() or GroupPortalManager:get_group_data() |
|
|
|
|
* @param array $type message type |
|
|
|
|
* NOTIFICATION_TYPE_MESSAGE, |
|
|
|
|
* NOTIFICATION_TYPE_INVITATION, |
|
|
|
|
* NOTIFICATION_TYPE_GROUP |
|
|
|
|
* @param array $user_list recipients: user list of ids |
|
|
|
|
* @param string $title |
|
|
|
|
* @param string $content |
|
|
|
|
* @param array $sender_info |
|
|
|
|
* result of api_get_user_info() or GroupPortalManager:get_group_data() |
|
|
|
|
*/ |
|
|
|
|
public function save_notification($type, $user_list, $title, $content, $sender_info = array()) |
|
|
|
|
{ |
|
|
|
|
public function save_notification( |
|
|
|
|
$type, |
|
|
|
|
$user_list, |
|
|
|
|
$title, |
|
|
|
|
$content, |
|
|
|
|
$sender_info = array() |
|
|
|
|
) { |
|
|
|
|
$this->type = intval($type); |
|
|
|
|
$content = $this->format_content($content, $sender_info); |
|
|
|
|
|
|
|
|
@ -143,7 +169,6 @@ class Notification extends Model |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$params = array(); |
|
|
|
|
|
|
|
|
|
switch ($user_setting) { |
|
|
|
|
//No notifications |
|
|
|
|
case self::NOTIFY_MESSAGE_NO: |
|
|
|
@ -162,7 +187,7 @@ class Notification extends Model |
|
|
|
|
if (!empty($mail)) { |
|
|
|
|
$sender_info['email'] = $mail; |
|
|
|
|
$extra_headers['reply_to']['mail'] = $mail; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} else { |
|
|
|
|
$sender_info['email'] = $this->admin_email; |
|
|
|
|
$extra_headers['reply_to']['mail'] = $this->admin_email; |
|
|
|
@ -190,7 +215,7 @@ class Notification extends Model |
|
|
|
|
$sender_info['email'], |
|
|
|
|
$extra_headers |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
$params['sent_at'] = api_get_utc_datetime(); |
|
|
|
|
// Saving the notification to be sent some day. |
|
|
|
@ -220,27 +245,49 @@ class Notification extends Model |
|
|
|
|
switch ($this->type) { |
|
|
|
|
case self::NOTIFICATION_TYPE_MESSAGE: |
|
|
|
|
if (!empty($sender_info)) { |
|
|
|
|
$sender_name = api_get_person_name($sender_info['firstname'], $sender_info['lastname'], null, PERSON_NAME_EMAIL_ADDRESS); |
|
|
|
|
//$sender_mail = $sender_info['email'] ; |
|
|
|
|
$sender_name = api_get_person_name( |
|
|
|
|
$sender_info['firstname'], |
|
|
|
|
$sender_info['lastname'], |
|
|
|
|
null, |
|
|
|
|
PERSON_NAME_EMAIL_ADDRESS |
|
|
|
|
); |
|
|
|
|
$new_message_text = sprintf(get_lang('YouHaveANewMessageFromX'), $sender_name); |
|
|
|
|
} |
|
|
|
|
$link_to_new_message = Display::url(get_lang('SeeMessage'), api_get_path(WEB_CODE_PATH).'messages/inbox.php'); |
|
|
|
|
$link_to_new_message = Display::url( |
|
|
|
|
get_lang('SeeMessage'), |
|
|
|
|
api_get_path(WEB_CODE_PATH) . 'messages/inbox.php' |
|
|
|
|
); |
|
|
|
|
break; |
|
|
|
|
case self::NOTIFICATION_TYPE_INVITATION: |
|
|
|
|
if (!empty($sender_info)) { |
|
|
|
|
$sender_name = api_get_person_name($sender_info['firstname'], $sender_info['lastname'], null, PERSON_NAME_EMAIL_ADDRESS); |
|
|
|
|
//$sender_mail = $sender_info['email'] ; |
|
|
|
|
$sender_name = api_get_person_name( |
|
|
|
|
$sender_info['firstname'], |
|
|
|
|
$sender_info['lastname'], |
|
|
|
|
null, |
|
|
|
|
PERSON_NAME_EMAIL_ADDRESS |
|
|
|
|
); |
|
|
|
|
$new_message_text = sprintf(get_lang('YouHaveANewInvitationFromX'), $sender_name); |
|
|
|
|
} |
|
|
|
|
$link_to_new_message = Display::url(get_lang('SeeInvitation'), api_get_path(WEB_CODE_PATH).'social/invitations.php'); |
|
|
|
|
$link_to_new_message = Display::url( |
|
|
|
|
get_lang('SeeInvitation'), |
|
|
|
|
api_get_path(WEB_CODE_PATH) . 'social/invitations.php' |
|
|
|
|
); |
|
|
|
|
break; |
|
|
|
|
case self::NOTIFICATION_TYPE_GROUP: |
|
|
|
|
$topic_page = intval($_REQUEST['topics_page_nr']); |
|
|
|
|
if (!empty($sender_info)) { |
|
|
|
|
$sender_name = $sender_info['group_info']['name']; |
|
|
|
|
$new_message_text = sprintf(get_lang('YouHaveReceivedANewMessageInTheGroupX'), $sender_name); |
|
|
|
|
$sender_name = api_get_person_name($sender_info['user_info']['firstname'], $sender_info['user_info']['lastname'], null, PERSON_NAME_EMAIL_ADDRESS); |
|
|
|
|
$sender_name = Display::url($sender_name, api_get_path(WEB_CODE_PATH).'social/profile.php?'.$sender_info['user_info']['user_id']); |
|
|
|
|
$sender_name = api_get_person_name( |
|
|
|
|
$sender_info['user_info']['firstname'], |
|
|
|
|
$sender_info['user_info']['lastname'], |
|
|
|
|
null, |
|
|
|
|
PERSON_NAME_EMAIL_ADDRESS |
|
|
|
|
); |
|
|
|
|
$sender_name = Display::url( |
|
|
|
|
$sender_name, |
|
|
|
|
api_get_path(WEB_CODE_PATH).'social/profile.php?'.$sender_info['user_info']['user_id'] |
|
|
|
|
); |
|
|
|
|
$new_message_text .= '<br />'.get_lang('User').': '.$sender_name; |
|
|
|
|
} |
|
|
|
|
$group_url = api_get_path(WEB_CODE_PATH).'social/group_topics.php?id='.$sender_info['group_info']['id'].'&topic_id='.$sender_info['group_info']['topic_id'].'&msg_id='.$sender_info['group_info']['msg_id'].'&topics_page_nr='.$topic_page; |
|
|
|
@ -261,7 +308,10 @@ class Notification extends Model |
|
|
|
|
|
|
|
|
|
// You have received this message because you are subscribed text |
|
|
|
|
$content = $content.'<br /><hr><i>'. |
|
|
|
|
sprintf(get_lang('YouHaveReceivedThisNotificationBecauseYouAreSubscribedOrInvolvedInItToChangeYourNotificationPreferencesPleaseClickHereX'), Display::url($preference_url, $preference_url)).'</i>'; |
|
|
|
|
sprintf( |
|
|
|
|
get_lang('YouHaveReceivedThisNotificationBecauseYouAreSubscribedOrInvolvedInItToChangeYourNotificationPreferencesPleaseClickHereX'), |
|
|
|
|
Display::url($preference_url, $preference_url) |
|
|
|
|
).'</i>'; |
|
|
|
|
return $content; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|