ComunicAPI/RestControllers/GroupsController.php
2018-07-02 12:03:33 +02:00

43 lines
782 B
PHP

<?php
/**
* API Groups controller
*
* @author Pierre HUBERT
*/
class GroupsController {
/**
* Create a group
*
* @url POST /groups/create
*/
public function create(){
//Login required
user_login_required();
//Get the name of the new group
$name = postString("name", 3);
//Prepare group creation
$newGroup = new NewGroup();
$newGroup->set_name($name);
$newGroup->set_userID(userID);
$newGroup->set_time_sent(time());
//Try to create the group
$groupID = components()->groups->create($newGroup);
//Check for errors
if($groupID < 1)
Rest_fatal_error(500, "An error occurred while trying to create the group!");
//Success
return array(
"success" => "The group has been successfully created!",
"id" => $groupID
);
}
}