Ejemplo n.º 1
0
 /**
  * @return Set\BlockPropertySet
  */
 public function getBlockPropertySet()
 {
     if (isset($this->blockPropertySet)) {
         return $this->blockPropertySet;
     }
     $this->blockPropertySet = new Set\BlockPropertySet();
     $entityManager = $this->getEntityManager();
     $qb = $entityManager->createQueryBuilder();
     $expr = $qb->expr();
     $or = $expr->orX();
     $cnt = 0;
     $blockSet = $this->getBlockSet();
     //$sharedPropertyFinder = new SharedPropertyFinder($entityManager);
     $localResourceLocalizations = array();
     // Loop generates condition for property getter
     foreach ($blockSet as $block) {
         /* @var $block Block */
         $blockId = $block->getId();
         // Skip if the block response is read from the cache already
         if (in_array($blockId, $this->skipBlockPropertyLoading)) {
             continue;
         }
         $data = null;
         if ($block->getLocked()) {
             $data = $block->getPlaceHolder()->getMaster();
         } else {
             $data = $this->getLocalization();
         }
         $dataId = $data->getId();
         if (!$this->isLocalResource($data)) {
             $and = $expr->andX();
             $and->add($expr->eq('bp.block', '?' . ++$cnt));
             $qb->setParameter($cnt, $blockId);
             $and->add($expr->eq('bp.localization', '?' . ++$cnt));
             $qb->setParameter($cnt, $dataId);
             $or->add($and);
         } else {
             // In reality there can be only one local resource localization
             $localResourceLocalizations[$dataId] = $data;
         }
         //$sharedPropertyFinder->addBlock($block, $data);
     }
     $result = array();
     // Load only if any condition is added to the query
     if ($cnt != 0) {
         $qb->select('bp')->from(BlockProperty::CN(), 'bp')->where($or);
         $query = $qb->getQuery();
         $this->prepareQueryResultCache($query);
         $result = $query->getResult();
     }
     // Now merge local resource block properties
     foreach ($localResourceLocalizations as $localization) {
         /* @var $localization Localization */
         $localProperties = $localization->getBlockProperties()->getValues();
         $result = array_merge($result, $localProperties);
     }
     $this->blockPropertySet->exchangeArray($result);
     return $this->blockPropertySet;
 }