/** * Create a new ACL Resource * * @param string $module * @param string $controller * @param string $name */ public static function createResource($module, $controller, $name = null) { if (!empty($module) && !empty($controller)) { $resource = self::getResource($module, $controller); if (0 == $resource->count()) { $resource = new AdminResources(); $resource->name = !empty($name) ? $name : $controller; $resource->module = $module; $resource->controller = $controller; if ($resource->trySave()) { return $resource; } } else { return $resource[0]; } } }
/** * Init all the resources */ protected function initResources() { self::initRoles(); $resources = AdminResources::getResources(); if (!empty($resources)) { foreach ($resources as $module) { foreach ($module as $keyresource => $resource) { if (!$this->has($keyresource)) { // echo "> Adding the resource: $theresource<br/>"; $this->add(new Zend_Acl_Resource($keyresource)); } } } } }
/** * Add a new permission in the database for a specific resource * @param integer $roleID * @param integer $resourceID */ public static function addPermission($roleID, $module, $controller, $permission = "allow") { $resource = AdminResources::createResource($module, $controller); if (!empty($resource)) { $adminpermission = new AdminPermissions(); $adminpermission['role_id'] = $roleID; $adminpermission['resource_id'] = (string) $resource->resource_id; $adminpermission['permission'] = $permission; if ($adminpermission->trySave()) { return $adminpermission; } } return false; }
/** * editAction * Get a record and populate the application form * @return unknown_type */ public function editAction() { $auth = Zend_Auth::getInstance(); // Get the common resources of ShineISP from the ACL file $aclConfig = new Zend_Config_Xml(APPLICATION_PATH . '/configs/acl.xml', 'acl'); $form = $this->getForm('/admin/roles/process'); $id = $this->getRequest()->getParam('id'); // Create the buttons in the edit form $this->view->buttons = array(array("url" => "#", "label" => $this->translator->translate('Save'), "params" => array('css' => null, 'id' => 'submit')), array("url" => "/admin/roles/list", "label" => $this->translator->translate('List'), "params" => array('css' => null)), array("url" => "/admin/roles/new/", "label" => $this->translator->translate('New'), "params" => array('css' => null))); if (!empty($id) && is_numeric($id)) { $rs = AdminRoles::find($id, null, true); if (!empty($rs[0])) { // Load the users connected to this role $users = AdminUser::getUserbyRoleID($id); // Load the roles of each resource $roles = AdminPermissions::getPermissionByRoleID($id); // Load the resources $this->view->resources = json_encode(AdminResources::createResourcesTree($aclConfig->modules, $roles)); // Join the roles and the users $rs[0]['users'] = $users; $form->populate($rs[0]); $this->view->buttons[] = array("url" => "/admin/roles/confirm/id/{$id}", "label" => $this->translator->translate('Delete'), "params" => array('css' => null)); } } $this->view->mex = $this->getRequest()->getParam('mex'); $this->view->mexstatus = $this->getRequest()->getParam('status'); $this->view->title = $this->translator->translate("Role edit"); $this->view->description = $this->translator->translate("Here you can edit the role permissions."); $this->view->form = $form; $this->render('applicantform'); }