Exemple #1
0
 public function delete_destroy($group_id)
 {
     if (!ctype_digit($group_id)) {
         $this->data['message'] = __('groups::lang.Invalid id')->get(ADM_LANG);
         $this->data['message_type'] = 'error';
         return Redirect::back()->with($this->data);
     }
     if (Bundle::exists('permissions')) {
         $group = Groups\Model\Group::with('permissions')->find($group_id);
     } else {
         $group = Groups\Model\Group::find($group_id);
     }
     if (!isset($group) or empty($group)) {
         $this->data['message'] = __('groups::lang.Sorry cannot find group to delete')->get(ADM_LANG);
         $this->data['message_type'] = 'error';
         return Redirect::back()->with($this->data);
     }
     $users_group = Groups\Model\Group::where('slug', '=', 'users')->first();
     // if there is users on this group
     // set all users back to users group
     if (isset($users_group) and isset($users_group->id)) {
         $update = Users\Model\User::where('group_id', '=', $group->id)->update(array('group_id' => $users_group->id));
     }
     if (isset($group->permissions) and !empty($group->permissions)) {
         $group->permissions()->delete();
     }
     $group->delete();
     Event::fire('mwi.group_deleted', array($group));
     $this->data['message'] = __('groups::lang.Group was successfully destroyed')->get(ADM_LANG);
     $this->data['message_type'] = 'success';
     return Redirect::to(ADM_URI . '/groups')->with($this->data);
 }