mirror of
https://github.com/pierre42100/ComunicAPI
synced 2024-11-23 22:09:29 +00:00
43 lines
782 B
PHP
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
|
|
);
|
|
}
|
|
|
|
} |