Changeset View
Changeset View
Standalone View
Standalone View
core/units/helpers/sections_helper.php
Show All 35 Lines | |||||
/** | /** | ||||
* Checks, that we are in super admin mode | * Checks, that we are in super admin mode | ||||
* | * | ||||
* @var bool | * @var bool | ||||
*/ | */ | ||||
var $superAdminMode = false; | var $superAdminMode = false; | ||||
/** | |||||
* Sections, grouped by unit | |||||
* | |||||
* @var array | |||||
*/ | |||||
protected $sectionsByUnit = array(); | |||||
public function __construct() | public function __construct() | ||||
Lint: CodingStandard.Commenting.FunctionComment.Missing: Missing doc comment for function __construct() | |||||
{ | { | ||||
parent::__construct(); | parent::__construct(); | ||||
$this->debugMode = $this->Application->isDebugMode(); | $this->debugMode = $this->Application->isDebugMode(); | ||||
$this->superAdminMode = $this->Application->RecallVar('super_admin'); | $this->superAdminMode = $this->Application->RecallVar('super_admin'); | ||||
} | } | ||||
/** | /** | ||||
Show All 13 Lines | |||||
/** | /** | ||||
* Builds xml for tree in left frame in admin | * Builds xml for tree in left frame in admin | ||||
* | * | ||||
* @return void | * @return void | ||||
* @access public | * @access public | ||||
*/ | */ | ||||
public function BuildTree() | public function BuildTree() | ||||
{ | { | ||||
if ( $this->Application->isCachingType(CACHING_TYPE_MEMORY) ) { | $this->Tree = $this->getFromCache('sections_parsed'); | ||||
$data = $this->Application->getCache('master:sections_parsed', false, CacheSettings::$sectionsParsedRebuildTime); | $this->sectionsByUnit = $this->getFromCache('sections_by_unit'); | ||||
} | |||||
else { | |||||
$data = $this->Application->getDBCache('sections_parsed', CacheSettings::$sectionsParsedRebuildTime); | |||||
} | |||||
if ( $data ) { | if ( $this->Tree && $this->sectionsByUnit ) { | ||||
$this->Tree = unserialize($data); | |||||
return ; | return; | ||||
} | } | ||||
if ( !defined('IS_INSTALL') || !IS_INSTALL ) { | if ( !defined('IS_INSTALL') || !IS_INSTALL ) { | ||||
// don't reread all configs during install, because they are reread on every install step | // don't reread all configs during install, because they are reread on every install step | ||||
$this->Application->UnitConfigReader->ReReadConfigs(); | $this->Application->UnitConfigReader->ReReadConfigs(); | ||||
} | } | ||||
$this->Tree = Array (); | $this->Tree = array(); | ||||
$this->sectionsByUnit = array(); | |||||
// 1. build base tree (don't update parent with children list yet) | // 1. build base tree (don't update parent with children list yet) | ||||
// 1.1. process prefixes without priority | // 1.1. process prefixes without priority | ||||
$prioritized_prefixes = Array (); | $prioritized_prefixes = Array (); | ||||
$prefixes = array_keys($this->Application->UnitConfigReader->configData); | $prefixes = array_keys($this->Application->UnitConfigReader->configData); | ||||
foreach ($prefixes as $prefix) { | foreach ($prefixes as $prefix) { | ||||
Show All 36 Lines | |||||
else { | else { | ||||
// then remove section | // then remove section | ||||
unset($this->Tree[$section_name]); | unset($this->Tree[$section_name]); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
// 3. | // 3. | ||||
foreach ($this->Tree as $section_name => $section_params) { | foreach ($this->Tree as $section_name => $section_params) { | ||||
Expected 1 spaces before "foreach" closing bracket; 0 found Lint: CodingStandard.WhiteSpace.ControlStructureSpacing.SpaceBeforeCloseBrace: Expected 1 spaces before "foreach" closing bracket; 0 found | |||||
Expected 1 spaces after "foreach" opening bracket; 0 found Lint: CodingStandard.WhiteSpace.ControlStructureSpacing.SpacingAfterOpenBrace: Expected 1 spaces after "foreach" opening bracket; 0 found | |||||
$section_prefix = $section_params['SectionPrefix']; | |||||
if ( !isset($this->sectionsByUnit[$section_prefix]) ) { | |||||
$this->sectionsByUnit[$section_prefix] = array(); | |||||
} | |||||
$this->sectionsByUnit[$section_prefix][] = $section_name; | |||||
// 3.1. update parent -> children references | // 3.1. update parent -> children references | ||||
$parent_section = $section_params['parent']; | $parent_section = $section_params['parent']; | ||||
$section_order = "{$section_params['priority']}"; | $section_order = "{$section_params['priority']}"; | ||||
if ( !isset($parent_section) ) { | if ( !isset($parent_section) ) { | ||||
// don't process parent section of "in-portal:root" section | // don't process parent section of "in-portal:root" section | ||||
continue; | continue; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 44 Lines • ▼ Show 20 Line(s) | |||||
if ( !file_exists(FULL_PATH . '/' . $icon_file . '.png') ) { | if ( !file_exists(FULL_PATH . '/' . $icon_file . '.png') ) { | ||||
$this->Tree[$section_name]['icon'] = 'help'; | $this->Tree[$section_name]['icon'] = 'help'; | ||||
$this->Tree[$section_name]['icon_module'] = 'core'; | $this->Tree[$section_name]['icon_module'] = 'core'; | ||||
} | } | ||||
} | } | ||||
$this->Application->HandleEvent(new kEvent('adm:OnAfterBuildTree')); | $this->Application->HandleEvent(new kEvent('adm:OnAfterBuildTree')); | ||||
$this->setToCache('sections_parsed', $this->Tree); | |||||
$this->setToCache('sections_by_unit', $this->sectionsByUnit); | |||||
} | |||||
/** | |||||
* Section names, related to prefix | |||||
* | |||||
* @param string $prefix Prefix. | |||||
* | |||||
* @return array | |||||
*/ | |||||
public function getSectionNames($prefix) | |||||
{ | |||||
return isset($this->sectionsByUnit[$prefix]) ? $this->sectionsByUnit[$prefix] : array(); | |||||
} | |||||
/** | |||||
* Returns value from cache | |||||
* | |||||
* @param string $cache_key Cache key. | |||||
* | |||||
* @return array|boolean | |||||
*/ | |||||
protected function getFromCache($cache_key) | |||||
{ | |||||
if ( $this->Application->isCachingType(CACHING_TYPE_MEMORY) ) { | |||||
$data = $this->Application->getCache( | |||||
'master:' . $cache_key, | |||||
false, | |||||
CacheSettings::$sectionsParsedRebuildTime | |||||
); | |||||
} | |||||
else { | |||||
$data = $this->Application->getDBCache($cache_key, CacheSettings::$sectionsParsedRebuildTime); | |||||
} | |||||
return $data ? unserialize($data) : false; | |||||
} | |||||
/** | |||||
* Sets value to cache | |||||
* | |||||
* @param string $cache_key Cache key. | |||||
* @param array $data Data. | |||||
* | |||||
* @return void | |||||
*/ | |||||
protected function setToCache($cache_key, array $data) | |||||
{ | |||||
if ( $this->Application->isCachingType(CACHING_TYPE_MEMORY) ) { | if ( $this->Application->isCachingType(CACHING_TYPE_MEMORY) ) { | ||||
$this->Application->setCache('master:sections_parsed', serialize($this->Tree)); | $this->Application->setCache('master:' . $cache_key, serialize($data)); | ||||
} | } | ||||
else { | else { | ||||
$this->Application->setDBCache('sections_parsed', serialize($this->Tree)); | $this->Application->setDBCache($cache_key, serialize($data)); | ||||
} | } | ||||
} | } | ||||
function _processPrefixSections($prefix) | function _processPrefixSections($prefix) | ||||
{ | { | ||||
$config =& $this->Application->UnitConfigReader->configData[$prefix]; | $config =& $this->Application->UnitConfigReader->configData[$prefix]; | ||||
/** @var Array $sections */ | /** @var Array $sections */ | ||||
Show All 17 Lines | |||||
if ( is_float($section_params['priority']) ) { | if ( is_float($section_params['priority']) ) { | ||||
$section_params['priority'] = (string)$section_params['priority']; | $section_params['priority'] = (string)$section_params['priority']; | ||||
} | } | ||||
$section_params['SectionPrefix'] = $section_prefix; | $section_params['SectionPrefix'] = $section_prefix; | ||||
$section_params['url']['m_opener'] = 'r'; | $section_params['url']['m_opener'] = 'r'; | ||||
$section_params['url']['no_pass_through'] = 1; | $section_params['url']['no_pass_through'] = 1; | ||||
$pass_section = getArrayValue($section_params, 'url', 'pass_section'); | |||||
if ( $pass_section ) { | |||||
unset($section_params['url']['pass_section']); | unset($section_params['url']['pass_section']); | ||||
$section_params['url']['section'] = $section_name; | $section_params['url']['section'] = $section_name; | ||||
if ( !isset($section_params['url']['module']) ) { | if ( !isset($section_params['url']['module']) ) { | ||||
$module_name = $this->Application->findModule('Path', $config['ModuleFolder'] . '/', 'Name'); | $module_name = $this->Application->findModule('Path', $config['ModuleFolder'] . '/', 'Name'); | ||||
$section_params['url']['module'] = $module_name; | $section_params['url']['module'] = $module_name; | ||||
} | } | ||||
} | |||||
if ( !isset($section_params['url']['t']) ) { | if ( !isset($section_params['url']['t']) ) { | ||||
$section_params['url']['t'] = 'index'; | $section_params['url']['t'] = 'index'; | ||||
} | } | ||||
if ( !isset($section_params['onclick']) ) { | if ( !isset($section_params['onclick']) ) { | ||||
$section_params['onclick'] = 'checkEditMode()'; | $section_params['onclick'] = 'checkEditMode()'; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 85 Lines • ▼ Show 20 Line(s) | |||||
if (!$show_section) { | if (!$show_section) { | ||||
// visibility by section definition | // visibility by section definition | ||||
return false; | return false; | ||||
} | } | ||||
} | } | ||||
// visibility by section permission | // visibility by section permission | ||||
if ($check_permission) { | if ($check_permission) { | ||||
Expected 1 spaces before "if" closing bracket; 0 found Lint: CodingStandard.WhiteSpace.ControlStructureSpacing.SpaceBeforeCloseBrace: Expected 1 spaces before "if" closing bracket; 0 found | |||||
Expected 1 spaces after "if" opening bracket; 0 found Lint: CodingStandard.WhiteSpace.ControlStructureSpacing.SpacingAfterOpenBrace: Expected 1 spaces after "if" opening bracket; 0 found | |||||
$perm_section = $this->getPermSection($section_name); | $perm_section = $this->getPermSection($section_name, $section_data['SectionPrefix']); | ||||
return $this->Application->CheckPermission($perm_section.'.view'); | return $this->Application->CheckPermission($perm_section.'.view'); | ||||
} | } | ||||
return true; | return true; | ||||
} | } | ||||
/** | /** | ||||
* Returns section for permission checking based on given section | * Returns section for permission checking based on given section | ||||
* | * | ||||
* @param string $section_name | * @param string $section_name Section name. | ||||
* @param string $prefix Prefix. | |||||
* | |||||
* @return string | * @return string | ||||
*/ | */ | ||||
function getPermSection($section_name) | public function getPermSection($section_name, $prefix = '') | ||||
{ | { | ||||
$ret = $section_name; | $ret = $section_name; | ||||
if ( $prefix ) { | |||||
$request_section = $this->Application->GetVar('m_section'); | |||||
if ( !$request_section ) { | |||||
$request_section = $section_name; | |||||
} | |||||
if ( isset($this->sectionsByUnit[$prefix]) | |||||
&& in_array($request_section, $this->sectionsByUnit[$prefix]) | |||||
) { | |||||
return $request_section; | |||||
} | |||||
} | |||||
$section_data =& $this->getSectionData($section_name); | $section_data =& $this->getSectionData($section_name); | ||||
if ($section_data && isset($section_data['perm_prefix'])) { | if ( $section_data ) { | ||||
// this section uses other section permissions | $ret = $this->Application->getUnitOption($section_data['SectionPrefix'] . '.main', 'PermSection'); | ||||
$ret = $this->Application->getUnitOption($section_data['perm_prefix'].'.main', 'PermSection'); | |||||
} | } | ||||
return $ret; | return $ret; | ||||
} | } | ||||
} | |||||
No newline at end of file | } | ||||
Expected 0 spaces before closing brace; 4 found Lint: CodingStandard.Classes.ClassDeclaration.SpaceBeforeCloseBrace: Expected 0 spaces before closing brace; 4 found |
Missing doc comment for function __construct()