/** * @TODO: maybe optimize by grouping the properties once * * @param Block $block * @return BlockPropertySet */ public function getBlockPropertySet(Block $block) { $blockPropertySet = new BlockPropertySet(); /* @var $blockProperty \Supra\Package\Cms\Entity\BlockProperty */ foreach ($this as $blockProperty) { if ($blockProperty->getBlock()->equals($block)) { $blockPropertySet->append($blockProperty); } } return $blockPropertySet; }
/** * @param string $name * @return BlockProperty */ public function getProperty($name) { $propertyConfig = $this->config->getProperty($name); $property = null; foreach ($this->properties as $candidate) { // $configMatches = $propertyConfig->isMatchingProperty($candidate); $nameMatches = $name == $candidate->getHierarchicalName(); // @TODO: dev if ($nameMatches) { $property = $candidate; break; } } if ($property === null) { $parentProperty = null; if ($propertyConfig->hasParent()) { $dotPos = strrpos($name, '.'); $parentName = substr($name, 0, $dotPos); $name = substr($name, $dotPos + 1); $parentProperty = $this->getProperty($parentName); } $property = $propertyConfig->createProperty($name); $property->setBlock($this->block); $property->setLocalization($this->getRequest()->getLocalization()); if ($parentProperty) { $parentProperty->addProperty($property); } $this->properties->append($property); } return $property; }
/** * @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; }