/**
  * @return string
  */
 public function role()
 {
     return $this->permission->getRole();
 }
예제 #2
0
 /**
  * {@inheritDoc}
  */
 public function hydrate(Request $request, EntityInterface $entity, ErrorStore $errorStore)
 {
     $this->hydrateOwner($request, $entity);
     if ($this->shouldHydrate($request, 'o:slug')) {
         $entity->setSlug($request->getValue('o:slug'));
     }
     if ($this->shouldHydrate($request, 'o:theme')) {
         $entity->setTheme($request->getValue('o:theme'));
     }
     if ($this->shouldHydrate($request, 'o:title')) {
         $entity->setTitle($request->getValue('o:title'));
     }
     if ($this->shouldHydrate($request, 'o:navigation')) {
         $entity->setNavigation($request->getValue('o:navigation', []));
     }
     if ($this->shouldHydrate($request, 'o:item_pool')) {
         $entity->setItemPool($request->getValue('o:item_pool', []));
     }
     if ($this->shouldHydrate($request, 'o:is_public')) {
         $entity->setIsPublic($request->getValue('o:is_public', true));
     }
     if ($this->shouldHydrate($request, 'o:page')) {
         $pagesData = $request->getValue('o:page', []);
         $adapter = $this->getAdapter('site_pages');
         $retainPages = [];
         foreach ($pagesData as $pageData) {
             if (isset($pageData['o:id'])) {
                 $page = $adapter->findEntity($pageData['o:id']);
                 $retainPages[] = $page;
             }
         }
         $pages = $entity->getPages();
         // Remove pages not included in request.
         foreach ($pages as $page) {
             if (!in_array($page, $retainPages, true)) {
                 $pages->removeElement($page);
             }
         }
     }
     $sitePermissionsData = $request->getValue('o:site_permission');
     if ($this->shouldHydrate($request, 'o:site_permission') && is_array($sitePermissionsData)) {
         $userAdapter = $this->getAdapter('users');
         $sitePermissions = $entity->getSitePermissions();
         $sitePermissionsToRetain = [];
         foreach ($sitePermissionsData as $sitePermissionData) {
             if (!isset($sitePermissionData['o:user']['o:id'])) {
                 continue;
             }
             if (!isset($sitePermissionData['o:role'])) {
                 continue;
             }
             $user = $userAdapter->findEntity($sitePermissionData['o:user']['o:id']);
             $criteria = Criteria::create()->where(Criteria::expr()->eq('user', $user));
             $sitePermission = $sitePermissions->matching($criteria)->first();
             if (!$sitePermission) {
                 $sitePermission = new SitePermission();
                 $sitePermission->setSite($entity);
                 $sitePermission->setUser($user);
                 $entity->getSitePermissions()->add($sitePermission);
             }
             $sitePermission->setRole($sitePermissionData['o:role']);
             $sitePermissionsToRetain[] = $sitePermission;
         }
         foreach ($sitePermissions as $sitePermissionId => $sitePermission) {
             if (!in_array($sitePermission, $sitePermissionsToRetain)) {
                 $sitePermissions->remove($sitePermissionId);
             }
         }
     }
 }
 /**
  * {@inheritDoc}
  */
 public function getResourceId()
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'getResourceId', array());
     return parent::getResourceId();
 }