mirror of
https://github.com/pierre42100/ComunicAPI
synced 2024-11-27 07:49:27 +00:00
Conversation name can be updated
This commit is contained in:
parent
952779f527
commit
219e26b4c0
@ -122,8 +122,27 @@ class conversationsController{
|
||||
Rest_fatal_error(500, "Couldn't update user follow state !");
|
||||
}
|
||||
|
||||
//Check if user asked to change moderation settings
|
||||
if(isset($_POST['members']) OR isset($_POST['name'])){
|
||||
|
||||
//Check if user is allowed to change such settings
|
||||
if(!CS::get()->components->conversations->userIsModerator(userID, $conversationID))
|
||||
Rest_fatal_error(401, "The user isn't a moderator, he can't updates such settings !");
|
||||
|
||||
//Update conversation name (if required)
|
||||
if(isset($_POST["name"])){
|
||||
$conversationName = $_POST['name'] == "false" ? "" : $_POST['name'];
|
||||
|
||||
//Update conversation name
|
||||
if(!CS::get()->components->conversations->changeName($conversationID, $conversationName))
|
||||
Rest_fatal_error(500, "Couldn't update conversation name !");
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
//Success
|
||||
return array("success" => "User informations were successfully updated !");
|
||||
return array("success" => "Conversation informations were successfully updated !");
|
||||
}
|
||||
}
|
@ -238,13 +238,62 @@ class conversations {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change conversation name
|
||||
*
|
||||
* @param Integer $conversationID The ID of the conversation
|
||||
* @param String $conversationName The name of the conversation
|
||||
* @return Boolean True for a success
|
||||
*/
|
||||
public function changeName($conversationID, $conversationName){
|
||||
//Prepare database request
|
||||
$tableName = $this->conversationsListTable;
|
||||
$conditions = "ID = ?";
|
||||
$condVals = array($conversationID);
|
||||
|
||||
//Changes
|
||||
$changes = array(
|
||||
"name" => $conversationName,
|
||||
);
|
||||
|
||||
//Try to perform request
|
||||
if(!CS::get()->db->updateDB($tableName, $conditions, $changes, $condVals))
|
||||
return false; //An error occured
|
||||
|
||||
//Success
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a user is a conversation moderator or not
|
||||
*
|
||||
* @param Integer $userID The ID of the user to check
|
||||
* @param Integer $conversationID The ID of the conversation to check
|
||||
* @return Boolean True if the user is a conversation moderator or not
|
||||
* @return Boolean True if the user is a conversation moderator / false else
|
||||
*/
|
||||
public function userIsModerator($userID, $conversationID){
|
||||
//Prepare database request
|
||||
$tableName = $this->conversationsListTable;
|
||||
$conditions = "WHERE ID = ?";
|
||||
$values = array($conversationID);
|
||||
$requiredFields = array(
|
||||
"ID_utilisateurs"
|
||||
);
|
||||
|
||||
//Peform a request on the database
|
||||
$results = CS::get()->db->select($tableName, $conditions, $values, $requiredFields);
|
||||
|
||||
//Check for errors
|
||||
if($results === false)
|
||||
return false; // An error occured
|
||||
|
||||
//Check if there was results
|
||||
if(count($results) === 0)
|
||||
return false;
|
||||
|
||||
//Check the first result only
|
||||
return $results[0]["ID_utilisateurs"] == $userID;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user