From f59af9ae4fca060d676aba40400b9801195906e0 Mon Sep 17 00:00:00 2001 From: Quitta Date: Tue, 16 Jul 2013 16:43:58 +0200 Subject: [PATCH] Delete a user out of a support_group is possible, have to look up how to do the deletion of a group while keeping referential integrity in mind! --- .../ams_lib/autoload/in_support_group.php | 12 +++++-- .../ams_lib/autoload/support_group.php | 34 +++++++++++++++++-- .../ryzom_ams/www/html/inc/show_sgroup.php | 9 +++++ .../www/html/templates/show_sgroup.tpl | 2 +- 4 files changed, 51 insertions(+), 6 deletions(-) diff --git a/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/in_support_group.php b/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/in_support_group.php index f60e9ecb7..b01517db2 100644 --- a/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/in_support_group.php +++ b/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/in_support_group.php @@ -8,7 +8,7 @@ class In_Support_Group{ ////////////////////////////////////////////Functions//////////////////////////////////////////////////// //check if user is in in_support_group - public static function userAlreadyInSGroup( $user_id, $group_id) { + public static function userExistsInSGroup( $user_id, $group_id) { $dbl = new DBLayer("lib"); //check if name is already used if( $dbl->execute(" SELECT * FROM `in_support_group` WHERE `User` = :user_id and `Group` = :group_id ", array('user_id' => $user_id, 'group_id' => $group_id) )->rowCount() ){ @@ -34,7 +34,15 @@ class In_Support_Group{ $query = "INSERT INTO `in_support_group` (`User`,`Group`) VALUES (:user, :group)"; $values = Array('user' => $this->user, 'group' => $this->group); $dbl->execute($query, $values); - } + } + + //delete entry + public function delete() { + $dbl = new DBLayer("lib"); + $query = "DELETE FROM `in_support_group` WHERE `User` = :user_id and `Group` = :group_id"; + $values = array('user_id' => $this->getUser() ,'group_id' => $this->getGroup()); + $dbl->execute($query, $values); + } //Load with sGroupId public function load( $user_id, $group_id) { diff --git a/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/support_group.php b/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/support_group.php index 29478b896..6c3350bcb 100644 --- a/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/support_group.php +++ b/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/support_group.php @@ -106,15 +106,43 @@ class Support_Group{ } - - + + //wrapper for adding user to a support group + public static function deleteUserOfSupportGroup( $user_id, $group_id) { + + //check if group id exists + if (self::supportGroup_Exists($group_id)){ + + //check if user is in supportgroup + //if so, delete entry and return SUCCESS + if(In_Support_Group::userExistsInSGroup($user_id, $group_id) ){ + //delete entry + $inSGroup = new In_Support_Group(); + $inSGroup->setUser($user_id); + $inSGroup->setGroup($group_id); + $inSGroup->delete(); + return "SUCCESS"; + } + else{ + //else return USER_NOT_IN_GROUP + return "USER_NOT_IN_GROUP"; + } + + + }else{ + //return that group doesn't exist + return "GROUP_NOT_EXISTING"; + } + + } + //wrapper for adding user to a support group public static function addUserToSupportGroup( $user_id, $group_id) { //check if group id exists if (self::supportGroup_Exists($group_id)){ //check if user isn't in supportgroup yet //if not, create entry and return SUCCESS - if(! In_Support_Group::userAlreadyInSGroup($user_id, $group_id) ){ + if(! In_Support_Group::userExistsInSGroup($user_id, $group_id) ){ //create entry $inSGroup = new In_Support_Group(); $inSGroup->setUser($user_id); diff --git a/code/ryzom/tools/server/ryzom_ams/www/html/inc/show_sgroup.php b/code/ryzom/tools/server/ryzom_ams/www/html/inc/show_sgroup.php index 3fe1d5934..5b4767e4b 100644 --- a/code/ryzom/tools/server/ryzom_ams/www/html/inc/show_sgroup.php +++ b/code/ryzom/tools/server/ryzom_ams/www/html/inc/show_sgroup.php @@ -7,6 +7,14 @@ function show_sgroup(){ if( isset($_GET['id'])){ $result['target_id'] = filter_var($_GET['id'], FILTER_SANITIZE_NUMBER_INT); + + if(isset($_GET['delete'])){ + $delete_id = filter_var($_GET['delete'], FILTER_SANITIZE_NUMBER_INT); + $result['delete'] = Support_Group::deleteUserOfSupportGroup( $delete_id, $result['target_id'] ); + header("Location: index.php?page=show_sgroup&id=1"); + exit; + + } $group = Support_Group::getGroup($result['target_id']); $result['groupsname'] = $group->getName(); @@ -17,6 +25,7 @@ function show_sgroup(){ $i++; } return $result; + }else{ diff --git a/code/ryzom/tools/server/ryzom_ams/www/html/templates/show_sgroup.tpl b/code/ryzom/tools/server/ryzom_ams/www/html/templates/show_sgroup.tpl index 449989847..b8ef0245a 100644 --- a/code/ryzom/tools/server/ryzom_ams/www/html/templates/show_sgroup.tpl +++ b/code/ryzom/tools/server/ryzom_ams/www/html/templates/show_sgroup.tpl @@ -25,7 +25,7 @@ {$user.tUserId} {$user.name} - Delete + Delete {/foreach}