mirror of
https://github.com/pierre42100/ComunicAPI
synced 2024-12-28 06:28:58 +00:00
Implemented UnreadConversation object
This commit is contained in:
parent
cd367382a2
commit
55becbe2e9
@ -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;
|
||||
}
|
||||
}
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user