/** * Create an instance of the business entity page. * * @param BusinessTemplate $BusinessTemplate The business entity page * @param entity $entity The entity * @param string $url The new url * * @return \Victoire\Bundle\PageBundle\Entity\Page */ public function createPageInstanceFromBusinessTemplate(BusinessTemplate $BusinessTemplate, $entity, $url) { //create a new page $newPage = new Page(); $parentPage = $BusinessTemplate->getParent(); //set the page parameter by the business entity page $newPage->setParent($parentPage); $newPage->setTemplate($BusinessTemplate); $newPage->setUrl($url); $newPage->setTitle($BusinessTemplate->getTitle()); //update the parameters of the page $this->businessPageBuilder->updatePageParametersByEntity($newPage, $entity); $businessEntity = $this->businessEntityHelper->findByEntityInstance($entity); $entityProxy = new EntityProxy(); $entityProxy->setEntity($entity, $businessEntity->getName()); $newPage->setEntityProxy($entityProxy); return $newPage; }
/** * Get the entity from the page and the id given. * Must be called by the service victoire_core.helper.queriable_business_entity_helper. * * @param BusinessTemplate $page The page * @param string $entityIdentifier The identifier for the business entity * @param string $attributeName The name of the attribute used to identify an entity * * @throws \Exception * * @return entity */ public function getEntityByPageAndBusinessIdentifier(BusinessTemplate $page, $entityIdentifier, $attributeName) { if (!$this->entityManager) { throw new \Exception('EntityManager not defined, you should use the "victoire_core.helper.queriable_business_entity_helper" service'); } $entity = null; $businessEntityId = $page->getBusinessEntityId(); $businessEntity = $this->findById($businessEntityId); //test the result if ($businessEntity === null) { throw new \Exception('The business entity [' . $businessEntityId . '] was not found.'); } $entity = $this->findEntityByBusinessEntityAndAttribute($businessEntity, $attributeName, $entityIdentifier); //test the result if ($entity === null) { throw new \Exception('The entity [' . $entityIdentifier . '] was not found.'); } return $entity; }
/** * Get an array of business properties by the business entity page pattern. * * @param BusinessTemplate $view * * @return array of business properties */ private function getBusinessProperties(BusinessTemplate $view) { $businessTemplateHelper = $this->get('victoire_business_page.business_page_helper'); //the business property link to the page $businessEntityId = $view->getBusinessEntityId(); $businessEntity = $this->get('victoire_core.helper.business_entity_helper')->findById($businessEntityId); $businessProperties = $businessTemplateHelper->getBusinessProperties($businessEntity); return $businessProperties; }
/** * Get the position of the identifier in the url of a business entity page pattern. * * @param BusinessTemplate $businessTemplate * * @return int The position */ public function getIdentifierPositionInUrl(BusinessTemplate $businessTemplate) { $position = null; $url = $businessTemplate->getUrl(); // split on the / character $keywords = preg_split("/\\//", $url); // preg_match_all('/\{\%\s*([^\%\}]*)\s*\%\}|\{\{\s*([^\}\}]*)\s*\}\}/i', $url, $matches); //the business property link to the page $businessEntityId = $businessTemplate->getBusinessEntityId(); $businessEntity = $this->businessEntityHelper->findById($businessEntityId); //the business properties usable in a url $businessProperties = $businessEntity->getBusinessPropertiesByType('businessParameter'); //we parse the words of the url foreach ($keywords as $index => $keyword) { foreach ($businessProperties as $businessProperty) { $entityProperty = $businessProperty->getEntityProperty(); $searchWord = '{{item.' . $entityProperty . '}}'; if ($searchWord === $keyword) { //the array start at index 0 but we want the position to start at 1 $position = ['position' => $index + 1, 'businessProperty' => $businessProperty]; } } } return $position; }
/** * Get an array of business properties by the business entity page pattern. * * @param BusinessTemplate $view * * @return array of business properties */ private function getBusinessProperties(BusinessTemplate $view) { $businessEntityHelper = $this->get('victoire_core.helper.business_entity_helper'); //the name of the business entity link to the business entity page pattern $businessEntityId = $view->getBusinessEntityId(); $businessEntity = $businessEntityHelper->findById($businessEntityId); $businessProperties = $businessEntity->getBusinessPropertiesByType('businessParameter'); $businessProperty = []; foreach ($businessProperties as $bp) { $entityProperty = $bp->getEntityProperty(); $businessProperty[$entityProperty] = $entityProperty; } return $businessProperty; }
/** * @param VirtualBusinessPage $page * @param BusinessTemplate $businessTemplate * @param array $businessProperties * @param EntityManager $em * @param $entity * * @throws IdentifierNotDefinedException * @throws \Exception * * @return VirtualBusinessPage */ private function populatePage(VirtualBusinessPage $page, BusinessTemplate $businessTemplate, array $businessProperties, EntityManager $em, $entity) { $pageName = $businessTemplate->getName(); $pageSlug = $businessTemplate->getSlug(); $page->setSlug($pageSlug); $page->setName($pageName); $pageUrl = $this->urlBuilder->buildUrl($page); //parse the business properties foreach ($businessProperties as $businessProperty) { $pageUrl = $this->parameterConverter->setBusinessPropertyInstance($pageUrl, $businessProperty, $entity); $pageSlug = $this->parameterConverter->setBusinessPropertyInstance($pageSlug, $businessProperty, $entity); $pageName = $this->parameterConverter->setBusinessPropertyInstance($pageName, $businessProperty, $entity); } //Check that all twig variables in pattern url was removed for it's generated BusinessPage preg_match_all('/\\{\\%\\s*([^\\%\\}]*)\\s*\\%\\}|\\{\\{\\s*([^\\}\\}]*)\\s*\\}\\}/i', $pageUrl, $matches); if (count($matches[2])) { throw new IdentifierNotDefinedException($matches[2]); } $page->setUrl($pageUrl); $page->setSlug($pageSlug); $page->setName($pageName); $page->setReference($this->viewReferenceBuilder->buildViewReference($page, $em)); return $page; }