Ejemplo n.º 1
0
 /**
  * Use only append to fill this object, must start with top elements
  * @param PlaceHolder $placeHolder
  */
 public function append($placeHolder)
 {
     if (!$placeHolder instanceof PlaceHolder) {
         throw new \LogicException(__METHOD__ . " accepts PlaceHolder arguments only");
     }
     if (isset($this->localization)) {
         $placeHolderName = $placeHolder->getName();
         // Add to final in cases when it's the page place or locked one
         if ($placeHolder->getLocked() || $placeHolder->getMaster()->equals($this->localization)) {
             // Ignore if already set locked place with higher hierarchy level
             if ($this->finalPlaceHolderSet->offsetExists($placeHolderName)) {
                 return;
             }
             $this->finalPlaceHolderSet->offsetSet($placeHolderName, $placeHolder);
         } else {
             // collect not matched template place holders to search for locked blocks
             $this->parentPlaceHolderSet->append($placeHolder);
         }
     }
     parent::append($placeHolder);
 }
Ejemplo n.º 2
0
 /**
  * @return Set\PlaceHolderSet
  */
 public function getPlaceHolderSet()
 {
     if (isset($this->placeHolderSet)) {
         return $this->placeHolderSet;
     }
     $localization = $this->getLocalization();
     $localeId = $localization->getLocale();
     $this->placeHolderSet = new Set\PlaceHolderSet($localization);
     $pageSetIds = $this->getPageSetIds();
     $layoutPlaceHolderNames = $this->getLayoutPlaceHolderNames();
     //		$layoutPlaceHolders = $this->getLayoutPlaceHolders();
     $entityManager = $this->getEntityManager();
     // Skip only if empty array is received
     if (is_array($layoutPlaceHolderNames) && empty($layoutPlaceHolderNames)) {
         //		if (is_array($layoutPlaceHolders) && empty($layoutPlaceHolders)) {
         return $this->placeHolderSet;
     }
     $currentPageIsLocalResource = false;
     if ($this->isLocalResource($localization)) {
         // Ignoring the current page when selecting placeholders by DQL, will acquire from the object
         array_pop($pageSetIds);
         $currentPageIsLocalResource = true;
     }
     // Nothing to search for
     if (!empty($pageSetIds)) {
         // Find template place holders
         $qb = $entityManager->createQueryBuilder();
         $qb->select('ph')->from(PlaceHolder::CN(), 'ph')->join('ph.localization', 'pl')->join('pl.master', 'p')->andWhere($qb->expr()->in('p.id', $pageSetIds))->andWhere('pl.locale = ?0')->setParameter(0, $localeId)->orderBy('ph.type', 'ASC')->addOrderBy('p.level', 'ASC');
         if (!empty($layoutPlaceHolderNames)) {
             $qb->andWhere($qb->expr()->in('ph.name', $layoutPlaceHolderNames));
         }
         $query = $qb->getQuery();
         $this->prepareQueryResultCache($query);
         $placeHolderArray = $query->getResult();
         foreach ($placeHolderArray as $placeHolder) {
             /* @var $place PlaceHolder */
             $this->placeHolderSet->append($placeHolder);
         }
     }
     // Merge the local resource localization into the placeholder set
     if ($currentPageIsLocalResource) {
         $placeHolders = $localization->getPlaceHolders();
         foreach ($placeHolders as $placeHolder) {
             /* @var $place PlaceHolder */
             $this->placeHolderSet->append($placeHolder);
         }
     }
     return $this->placeHolderSet;
 }