<?php
 namespace App\UserAccess; class CurrentUserAccessFast extends CurrentUserAccess { public function becomeSuperUser() { if ($this->isSuperUser) { throw new \Exception("Trying to become SuperUser when you are already SuperUser is forbidden"); } $this->isSuperUser = true; return $this; } public function becomeNormalUser() { if (!$this->isSuperUser) { throw new \Exception("Trying to become NormalUser when you are already NormalUser is forbidden"); } $this->isSuperUser = false; return $this; } public function isSuperUser() { return $this->isSuperUser; } public function hasAccessToSection($section) { if ($this->isSuperUser) { $sectionFound = false; ReferenceUserAccess::getInstance()->walkTreeSections(ReferenceUserAccess::getInstance()->getAccessTree(), function($k, $v, $o) use (&$sectionFound, $section) { if (!$sectionFound && $v['id']==$section) { $sectionFound = true; } }); return $sectionFound; } global $S; return $S['auth']['usersAccess'][$section]??false; } public function hasAccessToOption($option) { if ($this->isSuperUser) { $optionFound = false; ReferenceUserAccess::getInstance()->walkTreeSections(ReferenceUserAccess::getInstance()->getAccessTree(), function($k, $v, $o) use (&$optionFound, $option) { if (!$optionFound) { foreach ($v['options'] as $opt) { if (!$optionFound && $opt['id']==$option) { $optionFound = true; } } } }); return $optionFound; } global $S; return (bool)$S['auth']['userOptionsAccess'][$option]; } public function getAccessOptionValue($option) { if ($this->isSuperUser) { $optionData = null; ReferenceUserAccess::getInstance()->walkTreeSections(ReferenceUserAccess::getInstance()->getAccessTree(), function($k, $v, $o) use (&$optionData, $option) { if (!$optionData) { foreach ($v['options'] as $opt) { if (!$optionData && $opt['id']==$option) { $optionData = $opt; } } } }); if ($optionData) { if (isset($optionData['superUserValue'])) { return $optionData['superUserValue']; } elseif($optionData['type']=='checkbox') { return true; } } return false; } if ($this->hasAccessToOption($option)) { global $S; return $S['auth']['userOptionsAccess'][$option]; } return null; } public function isAuthenticated() { if ($this->isSuperUser) { return true; } return $this->isAuthenticated_checkSession(); } public function getAccessibleSectionsList() { global $S; return array_keys(array_filter((array)$S['auth']['usersAccess'])); } } 