/** * @return QueryBuilder */ protected function doGetQueryBuilder() { $qb = $this->localizationFinder->getQueryBuilder(); $qb = clone $qb; $qb->from(BlockProperty::CN(), 'bp'); $qb->andWhere('bp.localization = l'); $qb->join('bp.localization', 'l3'); $qb->join('bp.block', 'b'); $qb->join('b.placeHolder', 'ph'); $qb->leftJoin('bp.metadata', 'bpm'); $qb->leftJoin('bpm.referencedElement', 're'); $qb->join('l3.master', 'e3'); $qb->join('l3.path', 'lp3'); $qb->select('bp, b, l3, e3, bpm, ph, lp3, re'); $qb = $this->prepareComponents($qb); return $qb; }
protected function prepareData(ClassMetadata $metadata, array $data) { foreach ($data as $name => &$entityData) { switch ($metadata->name) { case Localization::CN(): case PageLocalization::CN(): case TemplateLocalization::CN(): case ApplicationLocalization::CN(): $entityData['publishedRevision'] = null; $args = array($entityData['locale']); break; case PageLocalizationPath::CN(): $args = array(str_ireplace('pageLocalizationPath', '', $name), $entityData['locale']); break; case TemplateLayout::CN(): $args = array($entityData['media']); break; case BlockPropertyMetadata::CN(): $args = array($entityData['name'], $entityData['blockProperty']); break; case BlockProperty::CN(): $args = array($entityData['name']); break; case PagePlaceHolder::CN(): case TemplatePlaceHolder::CN(): $args = array($entityData['name']); break; default: $constructor = new \ReflectionMethod($metadata->name, '__construct'); if ($constructor->getNumberOfRequiredParameters() === 0) { return parent::prepareData($metadata, $data); } throw new \RuntimeException(sprintf('Don\'t know how to build constructor required for [%s].', $metadata->name)); } $entityData = array_merge(array('__construct' => $args), $entityData); } return parent::prepareData($metadata, $data); }
/** * @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; }