示例#1
0
 /**
  * @return array of all module rights data
  */
 public static function getAllModuleRightsDataByPermitable(Permitable $permitable)
 {
     $data = array();
     $modules = Module::getModuleObjects();
     foreach ($modules as $module) {
         if ($module instanceof SecurableModule) {
             $moduleClassName = get_class($module);
             $rights = $moduleClassName::getRightsNames();
             $rightLabels = $moduleClassName::getTranslatedRightsLabels();
             $reflectionClass = new ReflectionClass($moduleClassName);
             if (!empty($rights)) {
                 $rightsData = array();
                 foreach ($rights as $right) {
                     if (!isset($rightLabels[$right])) {
                         throw new NotSupportedException($right);
                     }
                     $explicit = $permitable->getExplicitActualRight($moduleClassName, $right);
                     $inherited = $permitable->getInheritedActualRight($moduleClassName, $right);
                     $effective = $permitable->getEffectiveRight($moduleClassName, $right);
                     $constants = $reflectionClass->getConstants();
                     $constantId = array_search($right, $constants);
                     $rightsData[$constantId] = array('displayName' => $rightLabels[$right], 'explicit' => RightsUtil::getRightStringFromRight($explicit), 'inherited' => RightsUtil::getRightStringFromRight($inherited), 'effective' => RightsUtil::getRightStringFromRight($effective));
                 }
                 $data[$moduleClassName] = ArrayUtil::subValueSort($rightsData, 'displayName', 'asort');
             }
         }
     }
     return $data;
 }