public function getEntityProxy($entity, BusinessEntity $businessEntity, EntityManager $em)
 {
     $entityProxy = $em->getRepository('Victoire\\Bundle\\CoreBundle\\Entity\\EntityProxy')->findOneBy([$businessEntity->getId() => $entity]);
     if (!$entityProxy) {
         $entityProxy = new EntityProxy();
         $entityProxy->setEntity($entity, $businessEntity->getName());
     }
     return $entityProxy;
 }
Beispiel #2
0
 /**
  * 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;
 }
 /**
  * Generate update the page parameters with the entity
  * @param BusinessEntityPagePattern $bepPattern
  * @param Entity                    $entity
  *
  */
 public function generateEntityPageFromPattern(BusinessEntityPagePattern $bepPattern, $entity)
 {
     $page = new BusinessEntityPage();
     $reflect = new \ReflectionClass($bepPattern);
     $patternProperties = $reflect->getProperties();
     $accessor = PropertyAccess::createPropertyAccessor();
     foreach ($patternProperties as $property) {
         if (!in_array($property->getName(), array('id', 'slug', 'widgetMap', 'slots', 'seo', 'i18n')) && !$property->isStatic()) {
             $value = $accessor->getValue($bepPattern, $property->getName());
             $setMethod = 'set' . ucfirst($property->getName());
             if (method_exists($page, $setMethod)) {
                 $accessor->setValue($page, $property->getName(), $value);
             }
         }
     }
     //find Victoire\Bundle\BusinessEntityBundle\Entity\BusinessEntity object according to the given $entity
     $businessEntity = $this->businessEntityHelper->findByEntityInstance($entity);
     if ($businessEntity !== null) {
         //the business properties usable in a url
         $businessProperties = $this->getBusinessProperties($businessEntity);
         //the url of the page
         $pageUrl = $page->getUrl();
         $pageName = $page->getName();
         //parse the business properties
         foreach ($businessProperties as $businessProperty) {
             $pageUrl = $this->parameterConverter->setBusinessPropertyInstance($pageUrl, $businessProperty, $entity);
             $pageName = $this->parameterConverter->setBusinessPropertyInstance($pageName, $businessProperty, $entity);
         }
         //Check that all twig variables in pattern url was removed for it's generated BusinessEntityPage
         preg_match_all('/\\{\\%\\s*([^\\%\\}]*)\\s*\\%\\}|\\{\\{\\s*([^\\}\\}]*)\\s*\\}\\}/i', $pageUrl, $matches);
         if (count($matches[2])) {
             throw new \Exception(sprintf('The following identifiers are not defined as well, (%s)
                 you need to add the following lines on your businessEntity properties:
                 <br> <pre>@VIC\\BusinessProperty("businessParameter")</pre>', implode($matches[2], ', ')));
         }
         $entityProxy = new EntityProxy();
         $entityProxy->setEntity($entity, $businessEntity->getName());
         //we update the url of the page
         $page->setUrl($pageUrl);
         $page->setName($pageName);
         $page->setEntityProxy($entityProxy);
         $page->setTemplate($bepPattern);
     }
     return $page;
 }