Minor format code.

1.9.x
Julio Montoya 11 years ago
parent d48dd763e6
commit 43fea35dac
  1. 35
      main/inc/lib/message.lib.php
  2. 96
      main/inc/lib/notification.lib.php

@ -18,11 +18,10 @@ define('MESSAGE_STATUS_INVITATION_DENIED', '7');
/**
* Class MessageManager
*
* This class provides methods for messages management.
* Include/require it in your code to use its features.
*
* @package chamilo.library
* This class provides methods for messages management.
* Include/require it in your code to use its features.
*
* @package chamilo.library
*/
class MessageManager
{
@ -49,7 +48,6 @@ class MessageManager
public static function display_success_message($uid)
{
if ($_SESSION['social_exist'] === true) {
$redirect = "#remote-tab-2";
if (api_get_setting('allow_social_tool') == 'true' && api_get_setting('allow_message_tool') == 'true') {
$success = get_lang('MessageSentTo').
"&nbsp;<b>".
@ -393,10 +391,10 @@ class MessageManager
// get message id from data found early for other receiver user
$sql = "SELECT id FROM $table_message
WHERE
user_sender_id ='{$row_message[user_sender_id]}' AND
title='{$row_message[title]}' AND
content='{$row_message[content]}' AND
group_id='{$row_message[group_id]}' AND
user_sender_id ='{$row_message['user_sender_id']}' AND
title='{$row_message['title']}' AND
content='{$row_message['content']}' AND
group_id='{$row_message['group_id']}' AND
user_receiver_id='$receiver_user_id'";
$rs_msg_id = Database::query($sql);
$row = Database::fetch_array($rs_msg_id);
@ -423,9 +421,8 @@ class MessageManager
$rs = Database::query($sql);
if (Database::num_rows($rs) > 0) {
$row = Database::fetch_array($rs);
// delete attachment file
$res = self::delete_message_attachment_file($id, $user_receiver_id);
self::delete_message_attachment_file($id, $user_receiver_id);
// delete message
$query = "UPDATE $table_message SET msg_status=3
WHERE user_receiver_id=".$user_receiver_id." AND id=".$id;
@ -458,9 +455,8 @@ class MessageManager
$rs = Database::query($sql);
if (Database::num_rows($rs) > 0) {
$row = Database::fetch_array($rs);
// delete attachment file
$res = self::delete_message_attachment_file($id, $user_sender_id);
self::delete_message_attachment_file($id, $user_sender_id);
// delete message
$query = "UPDATE $table_message SET msg_status=3
WHERE user_sender_id='$user_sender_id' AND id='$id'";
@ -579,6 +575,7 @@ class MessageManager
{
if ($message_id != strval(intval($message_id)) || $user_id != strval(intval($user_id)))
return false;
$table_message = Database::get_main_table(TABLE_MESSAGE);
$sql = "UPDATE $table_message SET msg_status = '0'
WHERE
@ -636,7 +633,9 @@ class MessageManager
$table_message = Database::get_main_table(TABLE_MESSAGE);
$group_id = intval($group_id);
$query = "SELECT * FROM $table_message
WHERE group_id= $group_id AND msg_status NOT IN ('".MESSAGE_STATUS_OUTBOX."', '".MESSAGE_STATUS_DELETED."')
WHERE
group_id= $group_id AND
msg_status NOT IN ('".MESSAGE_STATUS_OUTBOX."', '".MESSAGE_STATUS_DELETED."')
ORDER BY id";
$rs = Database::query($query);
$data = array();
@ -661,7 +660,9 @@ class MessageManager
$table_message = Database::get_main_table(TABLE_MESSAGE);
$group_id = intval($group_id);
$query = "SELECT * FROM $table_message
WHERE group_id = $group_id AND msg_status NOT IN ('".MESSAGE_STATUS_OUTBOX."', '".MESSAGE_STATUS_DELETED."')
WHERE
group_id = $group_id AND
msg_status NOT IN ('".MESSAGE_STATUS_OUTBOX."', '".MESSAGE_STATUS_DELETED."')
ORDER BY id ";
$rs = Database::query($query);
@ -752,7 +753,6 @@ class MessageManager
*/
public static function get_message_data_sent($from, $number_of_items, $column, $direction)
{
global $charset;
$from = intval($from);
$number_of_items = intval($number_of_items);
if (!isset($direction)) {
@ -765,7 +765,8 @@ class MessageManager
}
$table_message = Database::get_main_table(TABLE_MESSAGE);
$request = api_is_xml_http_request();
$sql = "SELECT id as col0, user_sender_id as col1, title as col2, send_date as col3, user_receiver_id as col4, msg_status as col5
$sql = "SELECT
id as col0, user_sender_id as col1, title as col2, send_date as col3, user_receiver_id as col4, msg_status as col5
FROM $table_message
WHERE
user_sender_id=".api_get_user_id()." AND

@ -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;
}
}

Loading…
Cancel
Save