public function assign_rol_to_user($id_role, $id_user) { $rol_user = new RolesUsers(); $rol_user->setIdRole($id_role); $rol_user->setIdUser($id_user); $rol_user->save(); }
/** * Change user roles * @param <type> $user_id */ public function action_role($user_id) { $user_id = intval($user_id); $data = array(); $user = BLL_User::getUserWithRoleById($user_id); if (!$user) { Request::instance()->redirect('admin/user/index'); } if (Request::$method == 'POST' && isset($_POST['user_id'])) { //print_r($_POST);die(); $_id = intval($_POST['user_id']); if ($_id != $user_id) { Request::instance()->redirect('admin/user/role/' . $user_id); } #check role "login" exists $check = false; if (is_array($user['Roles'])) { foreach ($user['Roles'] as $index => $role) { if ($role['name'] == 'login') { $check = true; break; } } } # if not existed => insert login role if (!$check) { $lnk = new RolesUsers(); $lnk->user_id = $user_id; $lnk->role_id = BLL_Role::getInstance()->findOneBy('name', 'login')->id; $lnk->save(); } BLL_User::deleteUserRoles($user_id); if (isset($_POST['roles']) && count($_POST['roles']) > 0) { foreach ($_POST['roles'] as $index => $role_id) { //print_r($role_id); $lnk = new RolesUsers(); $lnk->user_id = $user_id; $lnk->role_id = $role_id; $lnk->save(); } } Request::instance()->redirect('admin/user/index'); } $data['user'] = $user; $this->template->section_title = __("Sửa quyền tài khoản"); $this->template->title = __("Sửa quyền tài khoản"); //$data['user_id'] = $user_id; $data['roles'] = BLL_Role::getAllRoles(); //print_r($data['user']); $this->template->content = View::factory('admin/user/role', $data); }