From b591f008a4bbf5e988ab548da906b4fade9528fe Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Wed, 4 Jul 2018 11:36:32 +0200 Subject: [PATCH] Can update the name of the group --- RestControllers/GroupsController.php | 22 +++++++++++++++++ classes/components/GroupsComponent.php | 34 ++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/RestControllers/GroupsController.php b/RestControllers/GroupsController.php index 7fa18b8..6968a5f 100644 --- a/RestControllers/GroupsController.php +++ b/RestControllers/GroupsController.php @@ -114,6 +114,28 @@ class GroupsController { return self::GroupSettingsToAPI($settings); } + /** + * Set (update) the settings of a group + * + * @url POST /groups/set_settings + */ + public function setSettings(){ + + //Get the ID of the group (with admin access) + $groupID = $this->getPostGroupIDWithAdmin("id"); + + //Create and fill a GroupSettings object with new values + $settings = new GroupSettings(); + $settings->set_id($groupID); + $settings->set_name(postString("name", 3)); + + //Try to save the new settings of the group + if(!components()->groups->set_settings($settings)) + Rest_fatal_error(500, "An error occured while trying to update group settings!"); + + return array("success" => "Group settings have been successfully updated!"); + } + /** * Get and return a group ID specified in the POST request * in which the current user has admin rigths diff --git a/classes/components/GroupsComponent.php b/classes/components/GroupsComponent.php index 8c973ae..9f92ba1 100644 --- a/classes/components/GroupsComponent.php +++ b/classes/components/GroupsComponent.php @@ -128,6 +128,26 @@ class GroupsComponent { } + /** + * Set (update) group settings + * + * @param GroupSettings $settings The settings to update + * @return bool TRUE for a success / FALSE + */ + public function set_settings(GroupSettings $settings) : bool { + + //Generate database entry + $modif = $this->GroupSettingsToDB($settings); + + //Apply update + return db()->updateDB( + self::GROUPS_LIST_TABLE, + "id = ?", + $modif, + array($settings->get_id())); + + } + /** * Insert a new group member * @@ -268,6 +288,20 @@ class GroupsComponent { return $info; } + + /** + * Turn a GroupSettings object into a database entry + * + * @param GroupSettings $settings The object to convert + * @return array Generated database entry + */ + private function GroupSettingsToDB(GroupSettings $settings) : array { + $data = array(); + + $data["name"] = $settings->get_name(); + + return $data; + } } //Register component