public function getPermissions() { if (null == $this->_permissions) { $groupId = $this->getUserGroupId(); $groupRight = new Sam_Model_User_Group_Right(); $groupRights = $groupRight->fetchAll($groupRight->select()->where("groupid=?", $groupId)); foreach ($groupRights as $right) { $resource = $right->resource; $action = $right->action; $isAllow = $right->isAllow; //echo "$resource $action = $isAllow <br/>"; $this->_permissions[$resource][$action] = $isAllow; } } return $this->_permissions; }
public function savePermissionHendle($request) { // $resource =strtolower( "$module:view"); // $resourceName = $resource; $resourceslist = $this->_resourceslist; $permissions = $this->_permissions; try { $groupid = $this->_group->getId(); if ($groupid == '') { throw new Exception(" group id cannot be null"); } else { if (isset($_POST)) { $db = Zend_Registry::get('db'); $db->query("DELETE FROM sys_group_rights WHERE groupid=?", array($groupid)); foreach ($_POST as $key => $val) { $arKey = explode('#', $key); $resourceName = $arKey[0]; $actionName = $arKey[1]; $gr = new Sam_Model_User_Group_Right(); $gr->setGroupid($groupid)->setResource($resourceName)->setAction($actionName); if ($val == "Yes") { $gr->setIsAllow("Yes"); } else { $gr->setIsAllow("No"); } $gr->save(); } $result = array('result' => 'success'); } else { $result = array('result' => 'failed', 'message' => 'no post data'); } } } catch (Exception $e) { $result = array('result' => 'failed', 'message' => $e->gettMessage()); } echo json_encode($result); }
public function permissionAction() { $request = $this->getRequest(); $this->_useAjaxLayout(); $groupid = $this->_request->getParam('id', ''); if ($groupid == '') { return $this->render('blank', null, true); } else { if ($request->getPost()) { $db = Zend_Registry::get('db'); $db->query("DELETE FROM sys_group_rights WHERE groupid=?", array($groupid)); foreach ($_POST as $key => $val) { $arKey = explode('#', $key); $resourceName = $arKey[0]; $actionName = $arKey[1]; $gr = new Sam_Model_User_Group_Right(); $gr->setGroupid($groupid)->setResource($resourceName)->setAction($actionName)->save(); } $this->view->infocode = 8; } $groupRight = new Sam_Model_User_Group_Right(); $select = $groupRight->select()->where("groupid=?", $groupid)->order("resource"); $result = $groupRight->fetchAll($select); $permissions = array(); foreach ($result as $right) { $action = $right->action; $allow = $right->isAllow; $resurce = $right->resource; $permissions[$resurce][$action] = $allow == 'Yes' ? 'Yes' : 'No'; } $resource = new Sam_Model_Resource(); $resources = $resource->fetchAll(null, 'name'); $resourceslist = array(); foreach ($resources as $re) { $resourceName = $re->name; $strActions = $re->actions; $arActions = explode(';', $strActions); $resourceslist[$resourceName]['description'] = $re->description; $resourceslist[$resourceName]['actions'] = $arActions; } $this->view->resources = $resourceslist; $this->view->permissions = $permissions; // $this->render ( 'ajaxform', null, true ); } }
/** * get Singleton Sam_Model_User_Group_Right * * @return Sam_Model_User_Group_Right */ public static function getObjectByID($id) { $obj = new Sam_Model_User_Group_Right(); $obj->find($id); return $obj; }