示例#1
0
 public function parseResults(LoopResult $loopResult)
 {
     foreach ($loopResult->getResultDataCollection() as $resource) {
         $loopResultRow = new LoopResultRow($resource);
         $loopResultRow->set("ID", $resource->getId())->set("IS_TRANSLATED", $resource->getVirtualColumn('IS_TRANSLATED'))->set("LOCALE", $this->locale)->set("CODE", $resource->getCode())->set("TITLE", $resource->getVirtualColumn('i18n_TITLE'))->set("CHAPO", $resource->getVirtualColumn('i18n_CHAPO'))->set("DESCRIPTION", $resource->getVirtualColumn('i18n_DESCRIPTION'))->set("POSTSCRIPTUM", $resource->getVirtualColumn('i18n_POSTSCRIPTUM'));
         if (null !== $this->getProfile()) {
             $accessValue = $resource->getVirtualColumn('access');
             $manager = new AccessManager($accessValue);
             $loopResultRow->set("VIEWABLE", $manager->can(AccessManager::VIEW) ? 1 : 0)->set("CREATABLE", $manager->can(AccessManager::CREATE) ? 1 : 0)->set("UPDATABLE", $manager->can(AccessManager::UPDATE) ? 1 : 0)->set("DELETABLE", $manager->can(AccessManager::DELETE) ? 1 : 0);
         }
         $loopResult->addRow($loopResultRow);
     }
     return $loopResult;
 }
示例#2
0
 /**
  * @param ProfileEvent $event
  */
 public function updateModuleAccess(ProfileEvent $event)
 {
     if (null !== ($profile = ProfileQuery::create()->findPk($event->getId()))) {
         ProfileModuleQuery::create()->filterByProfileId($event->getId())->delete();
         foreach ($event->getModuleAccess() as $moduleCode => $accesses) {
             $manager = new AccessManager(0);
             $manager->build($accesses);
             $profileModule = new ProfileModule();
             $profileModule->setProfileId($event->getId())->setModule(ModuleQuery::create()->findOneByCode($moduleCode))->setAccess($manager->getAccessValue());
             $profileModule->save();
         }
         $event->setProfile($profile);
     }
 }
示例#3
0
 /**
  * @param ProfileModel $profile
  * @depends testUpdate
  */
 public function testUpdateResourceAccess(ProfileModel $profile)
 {
     $event = new ProfileEvent();
     $event->setId($profile->getId())->setResourceAccess(array('admin.address' => array(AccessManager::CREATE)));
     $action = new Profile($this->getMockEventDispatcher());
     $action->updateResourceAccess($event);
     $updatedProfile = $event->getProfile();
     $this->assertInstanceOf('Thelia\\Model\\Profile', $updatedProfile);
     $resources = $updatedProfile->getResources();
     $this->assertEquals(1, count($resources));
     $resource = $resources->getFirst();
     $this->assertEquals('admin.address', $resource->getCode());
     $profileResource = $updatedProfile->getProfileResources()->getFirst();
     $accessManager = new AccessManager($profileResource->getAccess());
     $this->assertTrue($accessManager->can(AccessManager::CREATE));
 }
示例#4
0
文件: Module.php 项目: badelas/thelia
 public function parseResults(LoopResult $loopResult)
 {
     /** @var \Thelia\Model\Module $module */
     foreach ($loopResult->getResultDataCollection() as $module) {
         try {
             new \ReflectionClass($module->getFullNamespace());
             $exists = true;
         } catch (\ReflectionException $ex) {
             $exists = false;
         }
         if ($exists || $this->getBackendContext()) {
             $loopResultRow = new LoopResultRow($module);
             $loopResultRow->set("ID", $module->getId())->set("IS_TRANSLATED", $module->getVirtualColumn('IS_TRANSLATED'))->set("LOCALE", $this->locale)->set("TITLE", $module->getVirtualColumn('i18n_TITLE'))->set("CHAPO", $module->getVirtualColumn('i18n_CHAPO'))->set("DESCRIPTION", $module->getVirtualColumn('i18n_DESCRIPTION'))->set("POSTSCRIPTUM", $module->getVirtualColumn('i18n_POSTSCRIPTUM'))->set("CODE", $module->getCode())->set("TYPE", $module->getType())->set("CATEGORY", $module->getCategory())->set("ACTIVE", $module->getActivate())->set("VERSION", $module->getVersion())->set("CLASS", $module->getFullNamespace())->set("POSITION", $module->getPosition())->set("EXISTS", $exists);
             $hasConfigurationInterface = false;
             /* first test if module defines it's own config route  */
             if ($module->getActivate()) {
                 // test if a hook
                 $hookConfiguration = ModuleHookQuery::create()->filterByModuleId($module->getId())->filterByActive(true)->useHookQuery()->filterByCode('module.configuration')->filterByType(TemplateDefinition::BACK_OFFICE)->endUse()->findOne();
                 $hasConfigurationInterface = null !== $hookConfiguration;
                 if (false === $hasConfigurationInterface) {
                     // Works only fo activated modules - see Thelia\Core\DependencyInjection\Compiler\RegisterRouterPass
                     $routerId = "router." . $module->getBaseDir();
                     if ($this->container->has($routerId)) {
                         try {
                             if ($this->container->get($routerId)->match('/admin/module/' . $module->getCode())) {
                                 $hasConfigurationInterface = true;
                             }
                         } catch (ResourceNotFoundException $e) {
                             /* $hasConfigurationInterface stays false */
                         }
                     }
                 }
                 /* if not ; test if it uses admin inclusion : module_configuration.html */
                 if (false === $hasConfigurationInterface) {
                     if (file_exists($module->getAbsoluteAdminIncludesPath() . DS . "module_configuration.html")) {
                         $hasConfigurationInterface = true;
                     }
                 }
             } else {
                 // Make a quick and dirty test on the module's config.xml file
                 $configContent = @file_get_contents($module->getAbsoluteConfigPath() . DS . "config.xml");
                 $hasConfigurationInterface = $configContent && preg_match('/event\\s*=\\s*[\'"]module.configuration[\'"]/', $configContent) !== false;
                 if (false === $hasConfigurationInterface) {
                     // Make a quick and dirty test on the module's routing.xml file
                     $routing = @file_get_contents($module->getAbsoluteConfigPath() . DS . "routing.xml");
                     if ($routing && strpos($routing, '/admin/module/') !== false) {
                         $hasConfigurationInterface = true;
                     } else {
                         if (file_exists($module->getAbsoluteAdminIncludesPath() . DS . "module_configuration.html")) {
                             $hasConfigurationInterface = true;
                         }
                     }
                 }
             }
             $loopResultRow->set("CONFIGURABLE", $hasConfigurationInterface ? 1 : 0);
             // Does module have hook(s)
             $hookable = false;
             $moduleHookCount = ModuleHookQuery::create()->filterByModuleId($module->getId())->count();
             $hookable = $moduleHookCount > 0;
             $loopResultRow->set("HOOKABLE", $hookable ? 1 : 0);
             if (null !== $this->getProfile()) {
                 $accessValue = $module->getVirtualColumn('access');
                 $manager = new AccessManager($accessValue);
                 $loopResultRow->set("VIEWABLE", $manager->can(AccessManager::VIEW) ? 1 : 0)->set("CREATABLE", $manager->can(AccessManager::CREATE) ? 1 : 0)->set("UPDATABLE", $manager->can(AccessManager::UPDATE) ? 1 : 0)->set("DELETABLE", $manager->can(AccessManager::DELETE) ? 1 : 0);
             }
             $loopResult->addRow($loopResultRow);
         }
     }
     return $loopResult;
 }