Add information about whether there is attachments - refs #7338

1.9.x
Angel Fernando Quiroz Campos 11 years ago
parent 47922c724f
commit 4c39ea00d2
  1. 32
      main/inc/lib/message.lib.php
  2. 3
      main/inc/lib/webservices/MessagesWebService.class.php
  3. 6
      webservices/rest.php

@ -1584,4 +1584,36 @@ class MessageManager
return $messages;
}
/**
* Check whether a message has attachments
* @param int $messageId The message id
* @return boolean Whether the message has attachments return true. Otherwise return false
*/
public static function hasAttachments($messageId)
{
$messageId = intval($messageId);
if (empty($messageId)) {
return false;
}
$messageAttachmentTable = Database::get_main_table(TABLE_MESSAGE_ATTACHMENT);
$conditions = array(
'where' => array(
'message_id = ?' => $messageId
)
);
$result = Database::select('COUNT(1) AS qty', $messageAttachmentTable, $conditions, 'first');
if (!empty($result)) {
if ($result['qty'] > 0) {
return true;
}
}
return false;
}
}

@ -102,6 +102,8 @@ class MessagesWebService extends WebService
$lastMessages = MessageManager::getMessagesFromLastReceivedMessage($userId, $lastId);
foreach ($lastMessages as $message) {
$hasAttachments = MessageManager::hasAttachments($message['id']);
$messages[] = array(
'id' => $message['id'],
'title' => $message['title'],
@ -112,6 +114,7 @@ class MessagesWebService extends WebService
'completeName' => api_get_person_name($message['firstname'], $message['lastname']),
),
'content' => $message['content'],
'hasAttachments' => $hasAttachments,
'platform' => array(
'website' => api_get_path(WEB_PATH),
'messagingTool' => api_get_path(WEB_PATH) . 'main/messages/inbox.php'

@ -62,10 +62,12 @@ switch ($action) {
$messages = $webService->getNewMessages($username, $lastId);
$json = $messages;
} else {
$json = array(
'status' => true,
'messages' => $messages
);
} else {
$json = array(
'status' => false
);
}

Loading…
Cancel
Save