public function transformContent() { // get the current role id $roleId = $this->getRequest()->getParameter('roleid'); // initialize the form $form = $this->getForm('RoleEdit'); $hidden = $form->getFormElementByName('roleid'); $hidden->setAttribute('value', $roleId); $displayName = $form->getFormElementByName('DisplayName'); $description = $form->getFormElementByName('Description'); $uM = $this->getManager(); // load selected roles to be able to highlight them within the select field $role = $uM->loadRoleByID($roleId); if ($form->isSent()) { if ($form->isValid()) { $displayName = $form->getFormElementByName('DisplayName'); $role = new UmgtRole(); $role->setObjectId($roleId); $role->setDisplayName($displayName->getValue()); $role->setDescription($description->getValue()); $uM->saveRole($role); $this->getResponse()->forward($this->generateLink(['mainview' => 'role', 'roleview' => '', 'roleid' => ''])); } else { $form->transformOnPlace(); } } else { // pre-fill form $displayName->setValue($role->getDisplayName()); $description->setValue($role->getDescription()); $form->transformOnPlace(); } }
public function transformContent() { $form = $this->getForm('Roles'); $uM = $this->getManager(); $user = $uM->loadUserByID($this->getRequest()->getParameter('userid')); $roles = $uM->loadRolesWithUser($user); if (count($roles) === 0) { $tmpl = $this->getTemplate('NoMoreRoles'); $tmpl->getLabel('message-1')->setPlaceHolder('display-name', $user->getDisplayName()); $tmpl->getLabel('message-2')->setPlaceHolder('user-view-link', $this->generateLink(['mainview' => 'user', 'groupview' => null, 'userid' => null])); $tmpl->transformOnPlace(); return; } /* @var $rolesControl MultiSelectBoxTag */ $rolesControl = $form->getFormElementByName('Roles'); foreach ($roles as $role) { $rolesControl->addOption($role->getDisplayName(), $role->getObjectId()); } if ($form->isSent() && $form->isValid()) { $options = $rolesControl->getSelectedOptions(); $rolesToRemove = []; foreach ($options as $option) { /* @var $option SelectBoxOptionTag */ $roleToRemove = new UmgtRole(); $roleToRemove->setObjectId($option->getValue()); $rolesToRemove[] = $roleToRemove; unset($roleToRemove); } $uM->detachUserFromRoles($user, $rolesToRemove); // back to user main view $this->getResponse()->forward($this->generateLink(['mainview' => 'user', 'roleview' => null, 'userid' => null])); } else { $form->transformOnPlace(); } }
public function transformContent() { $form = $this->getForm('RoleAdd'); /* @var $permissionControl MultiSelectBoxTag */ $permissionControl = $form->getFormElementByName('Permission'); $uM = $this->getManager(); $roles = $uM->getRoleList(); $count = count($roles); // fill multi-select field for ($i = 0; $i < $count; $i++) { $permissionControl->addOption($roles[$i]->getDisplayName(), $roles[$i]->getObjectId()); } if ($form->isSent() && $form->isValid()) { $uM = $this->getManager(); $role = new UmgtRole(); $displayName = $form->getFormElementByName('DisplayName'); $role->setDisplayName($displayName->getValue()); $description = $form->getFormElementByName('Description'); $role->setDescription($description->getValue()); $options = $permissionControl->getSelectedOptions(); for ($i = 0; $i < count($options); $i++) { $newPermission = new UmgtPermission(); $newPermission->setObjectId($options[$i]->getAttribute('value')); $role->addRelatedObject('Role2Permission', $newPermission); unset($newPermission); } $uM->saveRole($role); $this->getResponse()->forward($this->generateLink(['mainview' => 'role', 'roleview' => '', 'roleid' => ''])); } $form->transformOnPlace(); }
public function transformContent() { $roleId = $this->getRequest()->getParameter('roleid'); $uM = $this->getManager(); $role = $uM->loadRoleByID($roleId); $this->getLabel('display-name')->setPlaceHolder('display-name', $role->getDisplayName()); $formNo = $this->getForm('RoleDelNo'); $formYes = $this->getForm('RoleDelYes'); if ($formYes->isSent()) { $role = new UmgtRole(); $role->setObjectId($roleId); $uM->deleteRole($role); $this->getResponse()->forward($this->generateLink(['mainview' => 'role', 'roleview' => '', 'roleid' => ''])); } elseif ($formNo->isSent()) { $this->getResponse()->forward($this->generateLink(['mainview' => 'role', 'roleview' => '', 'roleid' => ''])); } else { $formNo->transformOnPlace(); $formYes->transformOnPlace(); } }
public function transformContent() { $form = $this->getForm('Roles'); $uM = $this->getManager(); $group = $uM->loadGroupByID($this->getRequest()->getParameter('groupid')); $roles = $uM->loadRolesNotWithGroup($group); if (count($roles) === 0) { $tmpl = $this->getTemplate('NoMoreRoles'); $tmpl->getLabel('message-1')->setPlaceHolder('display-name', $group->getDisplayName()); $tmpl->getLabel('message-2')->setPlaceHolder('group-view-link', $this->generateLink(['mainview' => 'group', 'roleview' => null, 'groupid' => null])); $tmpl->transformOnPlace(); return; } $rolesControl = $form->getFormElementByName('Roles'); /* @var $rolesControl MultiSelectBoxTag */ foreach ($roles as $role) { $rolesControl->addOption($role->getDisplayName(), $role->getObjectId()); } $form->getLabel('display-name')->setPlaceHolder('display-name', $group->getDisplayName()); if ($form->isSent() && $form->isValid()) { $options = $rolesControl->getSelectedOptions(); $additionalRoles = []; foreach ($options as $option) { /* @var $option SelectBoxOptionTag */ $additionalRole = new UmgtRole(); $additionalRole->setObjectId($option->getValue()); $additionalRoles[] = $additionalRole; unset($additionalRole); } $uM->attachGroupToRoles($group, $additionalRoles); // back to group main view $this->getResponse()->forward($this->generateLink(['mainview' => 'group', 'roleview' => null, 'groupid' => null])); } else { $form->transformOnPlace(); } }
/** * Saves a role object within the current application. * * @param UmgtRole $role current role. * * @return int The id of the role. * * @author Christian Achatz * @version * Version 0.1, 15.06.2008<br /> */ public function saveRole(UmgtRole &$role) { $app = $this->getCurrentApplication(); $role->addRelatedObject('Application2Role', $app); return $this->getORMapper()->saveObject($role); }