mirror of
https://github.com/pierre42100/ComunicAPI
synced 2024-11-27 15:59:29 +00:00
Created get conversations list method
This commit is contained in:
parent
bba8de04a0
commit
3729b56ff4
@ -7,6 +7,25 @@
|
|||||||
|
|
||||||
class conversationsController{
|
class conversationsController{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the conversations list
|
||||||
|
*
|
||||||
|
* @url POST /conversations/getList
|
||||||
|
*/
|
||||||
|
public function getConversationsList(){
|
||||||
|
user_login_required();
|
||||||
|
|
||||||
|
//Try to get the list
|
||||||
|
$conversationsList = CS::get()->components->conversations->getList(userID);
|
||||||
|
|
||||||
|
//Check for errors
|
||||||
|
if($conversationsList === false)
|
||||||
|
Rest_fatal_error(500, "Couldn't get conversations list !");
|
||||||
|
|
||||||
|
//Return results
|
||||||
|
return $conversationsList;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new conversation
|
* Create a new conversation
|
||||||
*
|
*
|
||||||
|
@ -26,6 +26,60 @@ class conversations {
|
|||||||
$this->conversationUsersTable = CS::get()->config->get("dbprefix")."conversations_users";
|
$this->conversationUsersTable = CS::get()->config->get("dbprefix")."conversations_users";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the conversations list of a specified user
|
||||||
|
*
|
||||||
|
* @param Integer $userID The ID of the user to get the list
|
||||||
|
* @return Mixed Array in case of result / False else
|
||||||
|
*/
|
||||||
|
public function getList($userID){
|
||||||
|
|
||||||
|
//Prepare database request
|
||||||
|
$tablesName = $this->conversationListTable.", ".$this->conversationUsersTable;
|
||||||
|
|
||||||
|
//Prepare conditions
|
||||||
|
$tableJoinCondition = $this->conversationListTable.".ID = ".$this->conversationUsersTable.".ID_".$this->conversationListTable."";
|
||||||
|
$userCondition = $this->conversationUsersTable.".ID_utilisateurs = ?";
|
||||||
|
$orderResults = "ORDER BY ".$this->conversationListTable.".last_active DESC";
|
||||||
|
|
||||||
|
//Compile conditions
|
||||||
|
$conditions = "WHERE ".$tableJoinCondition." AND (".$userCondition.") ".$orderResults;
|
||||||
|
$conditionsValues = array($userID);
|
||||||
|
|
||||||
|
//Fields list
|
||||||
|
$requiredFields = array(
|
||||||
|
$this->conversationListTable.".ID",
|
||||||
|
$this->conversationListTable.".last_active",
|
||||||
|
$this->conversationListTable.".name",
|
||||||
|
$this->conversationListTable.".ID_utilisateurs AS ID_owner",
|
||||||
|
$this->conversationUsersTable.".following",
|
||||||
|
$this->conversationUsersTable.".saw_last_message",
|
||||||
|
);
|
||||||
|
|
||||||
|
//Perform database request
|
||||||
|
$results = CS::get()->db->select($tablesName, $conditions, $conditionsValues, $requiredFields);
|
||||||
|
|
||||||
|
//Check for errors
|
||||||
|
if($results === false)
|
||||||
|
return false; //An error occurred
|
||||||
|
|
||||||
|
//Process results
|
||||||
|
$conversationsList = array();
|
||||||
|
foreach($results as $processConversation){
|
||||||
|
$conversationsList[] = array(
|
||||||
|
"ID" => $processConversation["ID"],
|
||||||
|
"ID_owner" => $processConversation["ID_owner"],
|
||||||
|
"last_active" => $processConversation["last_active"],
|
||||||
|
"name" => ($processConversation["name"] == "" ? false : $processConversation["name"]),
|
||||||
|
"following" => $processConversation["following"],
|
||||||
|
"saw_last_message" => $processConversation["saw_last_message"]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
//Return results
|
||||||
|
return $conversationsList;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new conversation
|
* Create a new conversation
|
||||||
*
|
*
|
||||||
@ -62,7 +116,8 @@ class conversations {
|
|||||||
$userInformations = array(
|
$userInformations = array(
|
||||||
"ID_".$this->conversationListTable => $conversationID,
|
"ID_".$this->conversationListTable => $conversationID,
|
||||||
"time_add" => time(),
|
"time_add" => time(),
|
||||||
"saw_last_message" => 1
|
"saw_last_message" => 1,
|
||||||
|
"ID_utilisateurs" => $processUser,
|
||||||
);
|
);
|
||||||
|
|
||||||
//Make user follow the conversation if required
|
//Make user follow the conversation if required
|
||||||
|
Loading…
Reference in New Issue
Block a user