Beispiel #1
0
 public function role_permission()
 {
     // auth
     Auth::isAdminAuthorized($this->signedUser, 'admin.user.role', true, '/user/role');
     // check
     $id = Converter::int('id');
     $permissionIds = Converter::arr('permission', 'post');
     $role = \Rebond\Core\Role\Data::loadById($id);
     if (!isset($role)) {
         Session::adminError('itemNotFound', [$id], '/user/role');
     }
     $form = new \Rebond\Core\Role\Form($role);
     // action
     if (isset($_POST['save'])) {
         Auth::isAdminAuthorized($this->signedUser, 'admin.user.role.edit', true, '/user/role-permission?id=' . $id);
         \Rebond\Core\RolePermission\Data::deleteByRoleId($id);
         $newPermissions = [];
         if (isset($permissionIds)) {
             foreach ($permissionIds as $permissionId) {
                 $rolePermission = new \Rebond\Core\RolePermission\Model();
                 $rolePermission->setRoleId($role->getId());
                 $rolePermission->setPermissionId($permissionId);
                 $newPermissions[] = $rolePermission;
             }
         }
         \Rebond\Core\RolePermission\Data::saveAll($newPermissions);
         Session::adminSuccess('saved', '/user/role');
     }
     // view
     $this->setTpl();
     // main
     $tplMain = new Template(Template::MODULE, ['core', 'role']);
     $tplMain->set('item', $form);
     // layout
     if (Auth::isAdminAuthorized($this->signedUser, 'admin.user.role.edit', false)) {
         $this->tplLayout->set('column1', $tplMain->render('editor-permission'));
     } else {
         // @todo create viewer-permission template
         $this->tplLayout->set('column1', $tplMain->render('editor-permission'));
     }
     // master
     $this->tplMaster->set('layout', $this->tplLayout->render('layout-1-col'));
     return $this->tplMaster->render('tpl-default');
 }