当前位置: 首页>>代码示例>>PHP>>正文


PHP Roles::getAllAncestors方法代码示例

本文整理汇总了PHP中Roles::getAllAncestors方法的典型用法代码示例。如果您正苦于以下问题:PHP Roles::getAllAncestors方法的具体用法?PHP Roles::getAllAncestors怎么用?PHP Roles::getAllAncestors使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Roles的用法示例。


在下文中一共展示了Roles::getAllAncestors方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: array

	function __construct($role_id, $locale_code = "en-us", $config = null, $restricted = null)
	{
		// TODO: finish changing this into a params array being passed in
		// $this->role_id = $params['role_id'];
		// $this->locale_code = $params['locale_code'];

		$this->role_id = $role_id;
		$this->locale_code = $locale_code;

		if (is_array($this->role_id))
		{
			$all_roles = $this->role_id;
		}
		else
		{
			$all_roles = array($this->role_id);
		}
  		$roles_table = new Roles();
		foreach ($all_roles as $role)
		{
			$all_roles = array_merge($all_roles, $roles_table->getAllAncestors($role));
		}
		$this->all_roles = array_unique($all_roles);
		return parent::__construct($config);
	}
开发者ID:richjoslin,项目名称:rivety,代码行数:25,代码来源:Navigation.php

示例2: array

 function __construct($role_id, $locale_code = "en-us", $config = null, $restricted = null)
 {
     $this->locale_code = $locale_code;
     $this->role_id = $role_id;
     if (is_array($this->role_id)) {
         $all_roles = $this->role_id;
     } else {
         $all_roles = array($this->role_id);
     }
     $roles_table = new Roles();
     foreach ($all_roles as $role) {
         $all_roles = array_merge($all_roles, $roles_table->getAllAncestors($role));
     }
     $this->all_roles = array_unique($all_roles);
     return parent::__construct($config);
 }
开发者ID:jaybill,项目名称:Bolts,代码行数:16,代码来源:Navigation.php

示例3: isAllowed

	static function isAllowed($resource,$module = "default",$username = null,$controller = null){
		$users_roles_table = new UsersRoles();
		$roles_table = new Roles();
		if(!is_null($username)){
			$users_roles_db = $users_roles_table->fetchAll($users_roles_table->select()->where("username = ?",$username));
			
			if(count($users_roles_db) > 0){
				$user_roles = array();
				$users_roles_db = $users_roles_db->toArray();
				
				foreach($users_roles_db as $role){
					$ancs = $roles_table->getAllAncestors($role['role_id']);
					
					foreach ($ancs as $anc => $value) {
						$user_roles[] = $value;
					}
					
					array_push($user_roles, $role['role_id']);
				}
				$user_roles = array_unique($user_roles);
			}
		} else {
			$user_roles = array($roles_table->getIdByShortname("guest"));			
		}
		if (is_null($controller)) {
			$controller = "@@EXTRA";
		} 
		$resource_name = $module ."-". $controller ."-". $resource;
		$out = array();
		
		
		if(Zend_Registry::isRegistered('acl')){
			$acl = Zend_Registry::get('acl');
			if($acl->has($resource_name)){
				
				foreach($user_roles as $role){
					if($acl->isAllowed($role, $resource_name)){
						$out[] = $role;
					}
				}
				
			}
		}	
		return $out;	
	}
开发者ID:richjoslin,项目名称:rivety,代码行数:45,代码来源:ResourceCheck.php

示例4: _checkMatch

	protected function _checkMatch($match) {
		$roles_resources_table = new RolesResources();
		$roles_table = new Roles();
		$this_access = array();
		$request = $this->getRequest();
		$resource_name = 	$request->getModuleName() . "-" .ucfirst(strtolower($request->getControllerName())) . "-" .$request->getActionName();
		if(Zend_Registry::isRegistered('acl')){
			$acl = Zend_Registry::get('acl');

			if($acl->has($resource_name)){

				if($acl->isAllowed($match, $resource_name)){
					$this_access[] = $match;
				}

				$indirect = $roles_table->getAllAncestors($match); //maybe they inherit access
				$indirect_access = array();

				foreach($indirect as $role){
					if($acl->isAllowed($role, $resource_name)){
						$this_access[] = $role;
						$this_access[] = $match;
					}
				}

			}

		}
		return array_unique($this_access); // in not null, they inherit access
	}
开发者ID:richjoslin,项目名称:rivety,代码行数:30,代码来源:Admin.php

示例5: editAction

 function editAction()
 {
     $request = new Bolts_Request($this->getRequest());
     $roles_table = new Roles();
     $role = null;
     if ($request->has('id')) {
         if (!is_null($request->id)) {
             $role = $roles_table->fetchRow($roles_table->select()->where("id = ?", $request->id));
             if (!is_null($role)) {
                 // we do not edit the guest role
                 if ($role->shortname == "guest") {
                     $this->_redirect("/bolts/role");
                 }
                 $this->view->role = $role->toArray();
                 $this->view->role_tree = $roles_table->getRoleTree(null, $role->id);
                 $this->view->inherited_ids = $roles_table->getInheritedRoles($role->id);
             }
         }
     }
     if (is_null($role)) {
         $this->view->role_tree = $roles_table->getRoleTree();
     }
     if ($this->getRequest()->isPost()) {
         $errors = array();
         if ($request->has('inherit_role')) {
             $parents = array();
             foreach ($request->inherit_role as $inherit_role) {
                 $parents = array_merge($parents, $roles_table->getAllAncestors($inherit_role));
             }
             $inherit_ids = array();
             foreach ($request->inherit_role as $inherit_role) {
                 if (!in_array($inherit_role, $parents)) {
                     $inherit_ids[] = $inherit_role;
                 }
             }
         }
         if ($request->has('shortname')) {
             $shortname = $request->shortname;
             if (!Bolts_Validate::checkLength($request->shortname, 1, 255)) {
                 $errors[] = $this->_T("Shortname must be between 1 and 255 chars.");
             }
         } else {
             $errors[] = $this->_T("Shortname is a requried field.");
         }
         $description = $request->description;
         $isadmin = (int) $request->checkbox('isadmin');
         if (count($errors) == 0) {
             $data = array('shortname' => $shortname, 'description' => $description, 'isadmin' => $isadmin);
             //If we have an id, this is an update.
             $id = (int) $this->_request->getPost('id');
             if ($id != 0) {
                 $where = 'id = ' . $id;
                 $roles_table->update($data, $where);
             } else {
                 //We don't, this is an insert.
                 $id = $roles_table->insert($data);
             }
             $roles_table->removeInheritedRole($id);
             foreach ($inherit_ids as $in_id) {
                 $roles_table->setInheritedRole($id, $in_id);
             }
             $this->_redirect("/bolts/role");
         } else {
             $this->view->errors = $errors;
         }
     }
     if ($request->has('id')) {
         // this is an edit
         $id = $request->id;
         if ($id > 0) {
             $this->view->role = $roles_table->fetchRow('id = ' . $id)->toArray();
         }
         $this->view->inherited_ids = $roles_table->getInheritedRoles($id);
     } else {
         foreach ($roles_table->fetchAll()->toArray() as $role) {
             $role_choices[$role['id']] = $role['shortname'];
         }
         $this->view->role_choices = $role_choices;
     }
 }
开发者ID:jaybill,项目名称:Bolts,代码行数:80,代码来源:RoleController.php

示例6: isExtraResourceInherited

	protected function isExtraResourceInherited($module, $resource, $role_id)
	{
		$inheritsResource = false;
		$roles_table = new Roles();
		$roles_roles_table = new RolesRoles();
		$roles_res_extra_table = new RolesResourcesExtra();
		$inherited_ids = $roles_table->getAllAncestors($role_id);
		if (count($inherited_ids) > 0)
		{
			foreach ($inherited_ids as $inherited_id)
			{
				// determine if parent has access to this resource
				$select = $roles_res_extra_table->select();
				$select->where("role_id = ?", $inherited_id);
				$select->where("module = ?", $module);
				$select->where("resource = ?", $resource);
				$roles_resource = $roles_res_extra_table->fetchRow($select);
				if (!is_null($roles_resource))
				{
					//parent has it, role is inherited
					$inheritsResource = true;
				}
			}
		}
		return $inheritsResource;
	}
开发者ID:richjoslin,项目名称:rivety,代码行数:26,代码来源:ResourceController.php

示例7: init


//.........这里部分代码省略.........
             $this->view->format_date = "%e %b %Y, %l:%M:%S";
             $this->view->format_datetime = "%A %e %B %Y à %l:%M:%S%p";
             $this->view->format_datetime_small = "%e %b %Y, %l:%M%p";
             break;
         default:
             $this->view->format_date = Bolts_Registry::get('format_date');
             $this->view->format_datetime = Bolts_Registry::get('format_datetime');
             $this->view->format_datetime_small = Bolts_Registry::get('format_datetime_small');
             break;
     }
     $this->view->current_year = date("Y");
     // SAVED FOR FUTURE USE - changing the language pack based on locale
     // $locale_table = new Locales();
     // $locale_data = $locale_table->fetchByLocaleCode($this->view->locale_code);
     // if (count($locale_data) > 0) {
     // 	$this->locale_data = $locale_data['0'];
     // 	$this->view->locale_data = $this->locale_data;
     // 	$lan_pk = $this->locale_data['language_code'].'_'.$this->locale_data['country_code'].'.UTF-8';
     // 	setlocale(LC_ALL, $lan_pk);
     // 	setlocale(LC_NUMERIC, 'en_US.UTF-8');
     // 	setlocale(LC_COLLATE, 'en_US.UTF-8');
     // }
     // this is a way to force the browser to reload some scripts
     if (Bolts_Registry::get('uncache_css_js_version')) {
         $this->view->uncache_version = "?v=" . Bolts_Registry::get('uncache_css_js_version');
     }
     if (Bolts_Registry::get('uncache_flash_version')) {
         $this->view->uncache_flash = "?v=" . Bolts_Registry::get('uncache_flash_version');
     }
     // Set the content type to UTF-8
     header('Content-type: text/html; charset=UTF-8');
     // get navigation items from database or cache
     // check for role of identity, if we don't have one, use guest.
     // TODO - move this to the place where role is determined, there should only be one place
     if ($this->_auth->hasIdentity()) {
         $tmp_ids = $loggedInRoleIds;
         $this->my_roles = $roles_table->fetchRolesByUsername($this->_identity->username)->toArray();
         $username = $this->_identity->username;
         $this->view->username = $username;
     } else {
         $tmp_ids = array($roles_table->getIdByShortname("guest"));
         $this->my_roles = array(0 => array("id" => "1", "shortname" => "guest", "description" => "Guest", "is_admin" => "0", "isguest" => "1", "isdefault" => "0"));
     }
     $this->view->my_roles = $this->my_roles;
     // find the parent roles, add the parent role IDs to the nav_role_ids for inheritance.
     $nav_parent_role_ids = array();
     foreach ($tmp_ids as $nav_role) {
         $nav_parent_role_ids = array_merge($nav_parent_role_ids, $roles_table->getAllAncestors($nav_role));
     }
     $nav_role_ids = array();
     $nav_role_ids = array_merge($nav_parent_role_ids, $tmp_ids);
     $unique_ids = array_unique($nav_role_ids);
     sort($unique_ids);
     $nav_table = new Navigation($unique_ids, $this->locale_code);
     $cache_name = 'navigation_' . $this->locale_code . '-' . md5(implode($unique_ids, "-"));
     // MD5 The Unique IDs to shorten the cache name
     $cache_tags = array('navigation', $this->locale_code);
     $nav_items_temp = false;
     if (Bolts_Registry::get('enable_navigation_cache') == '1') {
         $nav_items_temp = Bolts_Cache::load($cache_name);
     }
     if ($nav_items_temp === false || !isset($nav_items_temp)) {
         $nav_items_temp = array();
         foreach ($unique_ids as $nav_role_id) {
             $nav_items_temp = array_merge($nav_items_temp, $nav_table->getNavTree($nav_role_id));
         }
         if (Bolts_Registry::get('enable_navigation_cache') == '1') {
             Bolts_Cache::save($nav_items_temp, $cache_name, $cache_tags);
         }
     }
     $navparams = array('nav_items' => $nav_items_temp, 'request' => $this->_request, 'locale_code' => $this->locale_code);
     $navparams = $this->_Bolts_plugin->doFilter('controller_nav', $navparams);
     // FILTER HOOK
     $this->view->nav_items = $navparams['nav_items'];
     // TODO - Rich fix this
     // // VIEW STATES
     // if (!$this->session->view_states) {
     // 	$this->session->view_states = array();
     // }
     // // TODO - allow use of regular expressions such as /auth/*
     // $last_visited_pages_filter = explode('|', Bolts_Registry::get('last_visited_pages_filter'));
     // if (!in_array($this->_uri, $last_visited_pages_filter)) {
     // 	$this->session->view_states['last_visited'] = $this->_uri;
     // }
     // $this->view->view_states = $this->session->view_states;
     // CONTROLLER INIT HOOK
     $params['request'] = $this->_request;
     $params['locale_code'] = $this->locale_code;
     $params['session'] = $this->session;
     $additional = $this->_Bolts_plugin->doFilter('controller_init', $params);
     // FILTER HOOK
     unset($additional['request']);
     // we don't want to send the request to the view
     if (isset($additional['filter_redirect'])) {
         $this->_redirect($additional['filter_redirect']);
     }
     foreach ($additional as $key => $value) {
         $this->view->{$key} = $value;
     }
 }
开发者ID:jaybill,项目名称:Bolts,代码行数:101,代码来源:Abstract.php

示例8: preDispatch

	public function preDispatch(Zend_Controller_Request_Abstract $request)
	{
		$frontController = Zend_Controller_Front :: getInstance();
		$auth = Zend_Auth :: getInstance();
		$roles_table = new Roles();

		$appNamespace = new Zend_Session_Namespace('RivetyCore_Temp');

		if (Zend_Registry :: isRegistered('acl'))
		{
			$acl = Zend_Registry :: get('acl');
		}
		else
		{
			$acl = new RivetyCore_Acl($auth);
			Zend_Registry::set('acl', $acl);
		}

		// determine role
		if ($auth->hasIdentity())
		{
			$user = Zend_Auth :: getInstance()->getIdentity();
			$users_roles_table = new UsersRoles();
			$users_roles_db = $users_roles_table->fetchAll($users_roles_table->select()->where("username = ?", $user->username));
			$user_roles = array();
			if (count($users_roles_db) > 0)
			{
				foreach ($users_roles_db as $role)
				{
					$user_roles[] = $role->role_id;
					$user_roles = array_merge($user_roles, $roles_table->getAllAncestors($role->role_id));
				}
			}
			$user_roles = array_unique($user_roles);
			$user_is_guest = false;
            $defaultNamespace = new Zend_Session_Namespace('Zend_Auth');

			// REFRESH THE SESSION EXPIRATION
	        $defaultNamespace->setExpirationSeconds((int)RivetyCore_Registry::get('session_timeout'));
		}
		else
		{
			$user_roles = array($roles_table->getIdByShortname("guest"));
			$user_is_guest = true;
		}

		$requested = $request->getModuleName() . "-" . ucfirst(strtolower($request->getControllerName())) . "-" . $request->getActionName();
		$url = $frontController->getBaseUrl() . "/";

		if (!$acl->has($requested))
		{
			// this doesn't exist, throw to 404
			$request->setModuleName('default');
			$request->setControllerName('auth');
			$request->setActionName('missing');
		}
		else
		{
			$isAllowed = array();
			foreach ($user_roles as $user_role)
			{
				$isAllowed[$user_role] = $acl->isAllowed($user_role, $requested);

				// if ($acl->isAllowed($user_role, $requested))
				// {
				// 	$isAllowed[$user_role] = true;
				// }
				// else
				// {
				// 	$isAllowed[$user_role] = false;
				// }
			}
			if (!in_array(true, $isAllowed))
			{
				if ($user_is_guest)
				{
					$url .= $request->getModuleName() . "/";
					$url .= $request->getControllerName() . "/";
					$url .= $request->getActionName() . "/";

					$params = $request->getParams();

					while ($param = current($params))
					{
				    	if (key($params) != "module" && key($params) != "controller" && key($params) != "action") $url .= key($params) . '/' . $param . "/";
	    				next($params);
					}
					if (substr($url,strlen($url) - 1, 1) == "/")
					{
						$url = substr($url, 0, strlen($url) - 1);
					}

					// place requested url in the session, unless this is the login controller

					if ($request->getControllerName() != "auth")
					{
						$request->setParam('ourl', base64_encode($url));
						// $appNamespace->requestedUrl = $url;
					}

//.........这里部分代码省略.........
开发者ID:richjoslin,项目名称:rivety,代码行数:101,代码来源:AclPlugin.php

示例9: preDispatch

 public function preDispatch(Zend_Controller_Request_Abstract $request)
 {
     $frontController = Zend_Controller_Front::getInstance();
     $auth = Zend_Auth::getInstance();
     $roles_table = new Roles();
     $appNamespace = new Zend_Session_Namespace('Bolts_Temp');
     if (Zend_Registry::isRegistered('acl')) {
         $acl = Zend_Registry::get('acl');
     } else {
         $acl = new Bolts_Acl($auth);
         Zend_Registry::set('acl', $acl);
     }
     // determine role
     if ($auth->hasIdentity()) {
         $user = Zend_Auth::getInstance()->getIdentity();
         $users_roles_table = new UsersRoles();
         $users_roles_db = $users_roles_table->fetchAll($users_roles_table->select()->where("username = ?", $user->username));
         $user_roles = array();
         if (count($users_roles_db) > 0) {
             foreach ($users_roles_db as $role) {
                 $user_roles[] = $role->role_id;
                 $user_roles = array_merge($user_roles, $roles_table->getAllAncestors($role->role_id));
             }
         }
         $user_roles = array_unique($user_roles);
         $user_is_guest = false;
         $defaultNamespace = new Zend_Session_Namespace('Zend_Auth');
         $defaultNamespace->setExpirationSeconds(86400);
     } else {
         $user_roles = array($roles_table->getIdByShortname("guest"));
         $user_is_guest = true;
     }
     $requested = $request->getModuleName() . "-" . ucfirst(strtolower($request->getControllerName())) . "-" . $request->getActionName();
     $url = $frontController->getBaseUrl() . "/";
     if (!$acl->has($requested)) {
         // this doesn't exist, throw to 404
         $request->setModuleName('bolts');
         $request->setControllerName('auth');
         $request->setActionName('missing');
     } else {
         $isAllowed = array();
         foreach ($user_roles as $user_role) {
             if ($acl->isAllowed($user_role, $requested)) {
                 $isAllowed[$user_role] = true;
             } else {
                 $isAllowed[$user_role] = false;
             }
         }
         if (!in_array(true, $isAllowed)) {
             if ($user_is_guest) {
                 $url .= $request->getModuleName() . "/";
                 $url .= $request->getControllerName() . "/";
                 $url .= $request->getActionName() . "/";
                 $params = $request->getParams();
                 while ($param = current($params)) {
                     if (key($params) != "module" and key($params) != "controller" and key($params) != "action") {
                         $url .= key($params) . '/' . $param . "/";
                     }
                     next($params);
                 }
                 if (substr($url, strlen($url) - 1, 1) == "/") {
                     $url = substr($url, 0, strlen($url) - 1);
                 }
                 //Zend_debug::dump($params);
                 //Zend_debug::dump($url);
                 // place requested url in the sesson,
                 // unless this is the login controller
                 if ($request->getControllerName() != "auth") {
                     $request->setParam('url', base64_encode($url));
                     //$appNamespace->requestedUrl = $url;
                 }
                 // send on to the login scipt
                 $request->setModuleName('bolts');
                 $request->setControllerName('auth');
                 $request->setActionName('login');
             } else {
                 $admin = "bolts-Admin-index";
                 $isAdmin = array();
                 foreach ($user_roles as $user_role) {
                     if ($acl->isAllowed($user_role, $admin)) {
                         $isAdmin[$user_role] = true;
                     } else {
                         $isAdmin[$user_role] = false;
                     }
                 }
                 if (!in_array(true, $isAdmin)) {
                     $request->setModuleName('bolts');
                     $request->setControllerName('auth');
                     $request->setActionName('denied');
                 } else {
                     $request->setModuleName('bolts');
                     $request->setControllerName('admin');
                     $request->setActionName('index');
                 }
             }
         }
     }
 }
开发者ID:jaybill,项目名称:Bolts,代码行数:98,代码来源:AclPlugin.php


注:本文中的Roles::getAllAncestors方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。