mirror of
https://github.com/pierre42100/ComunicAPI
synced 2024-12-23 20:18:57 +00:00
Progress on create a conversation way
This commit is contained in:
parent
475ebcf9e3
commit
1d70e373f3
35
RestControllers/conversationsController.php
Normal file
35
RestControllers/conversationsController.php
Normal file
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
/**
|
||||
* Conversations controller
|
||||
*
|
||||
* @author Pierre HUBERT
|
||||
*/
|
||||
|
||||
class conversationsController{
|
||||
|
||||
/**
|
||||
* Create a new conversation
|
||||
*
|
||||
* @url POST /conversations/create
|
||||
*/
|
||||
public function createConversation(){
|
||||
user_login_required();
|
||||
|
||||
//Check for parametres
|
||||
if(!check_post_parametres(array("name", "follow", "users")))
|
||||
Rest_fatal_error(501, "Please check parametres passed with the request !");
|
||||
|
||||
//Extract parametres
|
||||
$conversationName = ($_POST["name"] == "false" ? false : $_POST['name']);
|
||||
$followConversation = ($_POST['follow'] == "true" ? true : false);
|
||||
$users = users_list_to_array($_POST['users']);
|
||||
|
||||
//Check users
|
||||
if(count($users) < 1)
|
||||
Rest_fatal_erro(501, "Please select at least one user !");
|
||||
|
||||
//Perform the request
|
||||
|
||||
}
|
||||
|
||||
}
|
22
classes/components/conversations.php
Normal file
22
classes/components/conversations.php
Normal file
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
/**
|
||||
* Conversations component
|
||||
*
|
||||
* @author Pierre HUBERT
|
||||
*/
|
||||
|
||||
class conversations {
|
||||
|
||||
/**
|
||||
* Create a new conversation
|
||||
*
|
||||
* @param Integer $userID The ID of the user creating the conversation
|
||||
* @param Boolean $follow Defines if the user creating the conversation will follow it
|
||||
* @param Array $usersList The list of users following the conversation
|
||||
* @param Mixed $name Optionnal, the name of the conversation
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
//Register component
|
||||
Components::register("conversations", new conversations());
|
56
functions/requests.php
Normal file
56
functions/requests.php
Normal file
@ -0,0 +1,56 @@
|
||||
<?php
|
||||
/**
|
||||
* Requests functions
|
||||
*
|
||||
* @author Pierre HUBERT
|
||||
*/
|
||||
|
||||
/**
|
||||
* Check $_POST parametres associated to a request
|
||||
*
|
||||
* @param Array $varList The list of variables to check
|
||||
* @return Boolean True or false depending of the success of the operation
|
||||
*/
|
||||
function check_post_parametres(array $varList){
|
||||
|
||||
//Check each fields
|
||||
foreach($varList as $process){
|
||||
|
||||
//Check variable existence
|
||||
if(!isset($_POST[$process]))
|
||||
return false; //The variable does not exists
|
||||
|
||||
//Check variable content
|
||||
if($_POST[$process] == "")
|
||||
return false; //The variable is empty
|
||||
|
||||
}
|
||||
|
||||
//If we arrive there, it is a success
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a list of user comma-separated to an array
|
||||
*
|
||||
* @param String $list The input list
|
||||
* @return Array The list of user / an empty list in case of errors
|
||||
*/
|
||||
function users_list_to_array($list) : array{
|
||||
//Split the list into an array
|
||||
$array = explode(",", $list);
|
||||
$usersList = array();
|
||||
|
||||
foreach($array as $process){
|
||||
|
||||
//Check the entry is valid
|
||||
if(floor($process*1) < 1)
|
||||
return array();
|
||||
|
||||
//Add the entry to the list
|
||||
$usersList[] = floor($process*1);
|
||||
}
|
||||
|
||||
//Return the result
|
||||
return $usersList;
|
||||
}
|
Loading…
Reference in New Issue
Block a user