Conversation name can be updated

This commit is contained in:
Pierre
2017-06-18 10:41:43 +02:00
parent 952779f527
commit 219e26b4c0
2 changed files with 70 additions and 2 deletions

View File

@ -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;
}
}