/** * 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 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) { $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 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; }