Implemented UnreadConversation object

This commit is contained in:
Pierre 2018-04-25 16:57:06 +02:00
parent cd367382a2
commit 55becbe2e9
2 changed files with 46 additions and 7 deletions

View File

@ -417,6 +417,10 @@ class ConversationsController{
//Get the list of unread conversations of the user
$list_unread_conversations = components()->conversations->get_list_unread(userID);
//Process the results
foreach($list_unread_conversations as $num => $conv)
$list_unread_conversations[$num] = self::UnreadConversationToAPI($conv);
//Return result
return $list_unread_conversations;
}
@ -497,4 +501,23 @@ class ConversationsController{
return $data;
}
/**
* Turn UnreadConversation object into API entry
*
* @param UnreadConversation $conversation The conversation to convert
* @return array Generated entry
*/
private static function UnreadConversationToAPI(UnreadConversation $conversation) : array {
$data = array();
$data["id"] = $conversation->get_id();
$data["conv_name"] = $conversation->has_conv_name() ? $conversation->get_conv_name() : "";
$data["last_active"] = $conversation->get_last_active();
$data["userID"] = $conversation->get_userID();
$data["message"] = $conversation->has_message() ? $conversation->get_message() : "";
return $data;
}
}

View File

@ -775,13 +775,7 @@ class Conversations {
foreach($results as $result){
//Generate the entry
$entry = array(
"id" => $result['ID_comunic_conversations_list'],
"conv_name" => $result["name"],
"last_active" => $result['last_active'],
"userID" => $result["ID_utilisateurs"],
"message" => $result["message"]
);
$entry = $this->dbToUnreadConversation($result);
$list[] = $entry;
}
@ -866,6 +860,28 @@ class Conversations {
}
/**
* Turn a database entry into a UnreadConversation object
*
* @param array $entry Conversation entry in the database
* @return UnreadConversation Generated object
*/
private function dbToUnreadConversation(array $entry) : UnreadConversation {
$conversation = new UnreadConversation();
$conversation->set_id($entry["ID_comunic_conversations_list"]);
if($entry["name"] != null)
$conversation->set_conv_name($entry["name"]);
$conversation->set_last_active($entry["last_active"]);
$conversation->set_userID($entry["ID_utilisateurs"]);
if($entry["message"] != null)
$conversation->set_message($entry["message"]);
return $conversation;
}
}
//Register component