mirror of
https://port.numenaute.org/aleajactaest/khanat-opennel-code.git
synced 2024-12-29 12:20:53 +00:00
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!
This commit is contained in:
parent
c45d4a7a3b
commit
f59af9ae4f
4 changed files with 51 additions and 6 deletions
|
@ -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) {
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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{
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
<tr>
|
||||
<td>{$user.tUserId}</td>
|
||||
<td><a href ="index.php?page=show_user&id={$user.tUserId}">{$user.name}</a></td>
|
||||
<td class="center"><a class="btn btn-danger" href="#"><i class="icon-trash icon-white"></i> Delete</a></td>
|
||||
<td class="center"><a class="btn btn-danger" href="index.php?page=show_sgroup&id={$target_id}&delete={$user.tUserId}"><i class="icon-trash icon-white"></i> Delete</a></td>
|
||||
</tr>
|
||||
{/foreach}
|
||||
|
||||
|
|
Loading…
Reference in a new issue