Improved conversation get methods

This commit is contained in:
Pierre 2017-06-25 19:11:00 +02:00
parent eed7db90cf
commit df1808c6c3
2 changed files with 23 additions and 2 deletions

View File

@ -305,7 +305,7 @@ class conversationsController{
Rest_fatal_error(401, "Specified user doesn't belongs to the conversation number ".$conversationID." !"); Rest_fatal_error(401, "Specified user doesn't belongs to the conversation number ".$conversationID." !");
//Then we can get the ten las messages of the conversation system //Then we can get the ten las messages of the conversation system
$conversationsMessages[$conversationID] = CS::get()->components->conversations->getLastMessages($conversationID, 10); $conversationsMessages["conversation-".$conversationID] = CS::get()->components->conversations->getLastMessages($conversationID, 10);
} }
} }

View File

@ -557,8 +557,29 @@ class conversations {
$conversationID $conversationID
); );
//Define required fields
$requiredFields = array(
"ID",
"ID_utilisateurs AS ID_user",
"image_path",
"message",
"time_insert"
);
//Try to perform request on the database //Try to perform request on the database
$messages = CS::get()->db->select($tableName, $conditions, $condVals); $messages = CS::get()->db->select($tableName, $conditions, $condVals, $requiredFields);
//Process each message
array_walk($messages, function(&$item){
//Check if image is not null
if($item["image_path"] !== null && $item["image_path"] != ""){
//Replace image name with full URL
$item["image_path"] = path_user_data($item["image_path"]);
}
});
//Revert messages order
$messages = array_reverse($messages);
//Return messages //Return messages
return $messages; return $messages;