/** * Reorder roles * * @return string json encoded object */ public function moveRole() { if ($this->input) { $roles = get_json('items'); foreach ($roles as $key => $role_arr) { $role = $this->model->find($role_arr['id']); if (!\Access::isSystemRole($role->name)) { if (array_key_exists($key - 1, $roles)) { $prev_role = $this->model->find($roles[$key - 1]['id']); $role->level = $prev_role->level - 1; if ($role->level <= 0) { $role->level = 0; } $role->save(); $this->events->fire('role.move', array($role)); } } } return $this->setSuccess('alert.success.order_saved'); } }