mirror of
https://github.com/pierre42100/ComunicAPI
synced 2025-06-19 00:25:18 +00:00
Can create groups
This commit is contained in:
43
RestControllers/GroupsController.php
Normal file
43
RestControllers/GroupsController.php
Normal file
@ -0,0 +1,43 @@
|
||||
<?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
|
||||
);
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user