Example #1
0
 /**
  * BasePage settings
  * @param BasePage $page
  *
  * @Route("/{id}", name="victoire_seo_pageSeo_settings")
  * @Template()
  *
  * @return JsonResponse
  */
 public function settingsAction(BasePage $page)
 {
     //services
     $em = $this->getDoctrine()->getManager();
     $businessProperties = array();
     //if the page is a business entity template page
     if ($page instanceof BusinessEntityPage) {
         //get the id of the business entity
         $businessEntityId = $page->getBusinessEntityName();
         //we can use the business entity properties on the seo
         $businessEntity = $this->get('victoire_core.helper.business_entity_helper')->findById($businessEntityId);
         $businessProperties = $businessEntity->getBusinessPropertiesByType('seoable');
     }
     $pageSeo = $page->getSeo() ? $page->getSeo() : new PageSeo($page);
     //url for the form
     $formUrl = $this->container->get('router')->generate('victoire_seo_pageSeo_settings', array('id' => $page->getId()));
     //create the form
     $form = $this->container->get('form.factory')->create('seo_page', $pageSeo, array('action' => $formUrl, 'method' => 'POST'));
     $form->handleRequest($this->get('request'));
     if ($form->isValid()) {
         $em->persist($pageSeo);
         $page->setSeo($pageSeo);
         $em->persist($page);
         $em->flush();
         //redirect to the page url
         $pageUrl = $page->getUrl();
         $url = $this->generateUrl('victoire_core_page_show', array('url' => $pageUrl));
         return new JsonResponse(array('success' => true, 'url' => $url));
     }
     return new JsonResponse(array('success' => false, 'html' => $this->container->get('victoire_templating')->render('VictoireSeoBundle:PageSeo:settings.html.twig', array('page' => $page, 'form' => $form->createView(), 'businessProperties' => $businessProperties))));
 }
Example #2
0
 /**
  * Generate a seo for the page using the current entity
  *
  * @param Page   $page
  * @param Entity $entity
  */
 public function updateSeoByEntity(BasePage $page, $entity)
 {
     //if no entity is provided
     if ($entity === null) {
         //we look for the entity of the page
         if ($page->getBusinessEntity() !== null) {
             $entity = $page->getBusinessEntity();
         }
     }
     //only if we have an entity instance
     if ($entity !== null) {
         //the page seo
         $pageSeo = $page->getSeo();
         //the page seo might not exist yet
         if ($pageSeo !== null) {
             $businessEntity = $this->businessEntityHelper->findByEntityInstance($entity);
             if ($businessEntity !== null) {
                 $businessProperties = $businessEntity->getBusinessPropertiesByType('seoable');
                 //parse the business properties
                 foreach ($businessProperties as $businessProperty) {
                     //parse of seo attributes
                     foreach ($this->pageSeoAttributes as $seoAttribute) {
                         $string = $this->getEntityAttributeValue($pageSeo, $seoAttribute);
                         $updatedString = $this->parameterConverter->setBusinessPropertyInstance($string, $businessProperty, $entity);
                         $this->setEntityAttributeValue($pageSeo, $seoAttribute, $updatedString);
                     }
                 }
             }
         }
     }
 }
Example #3
0
 /**
  * Generate a seo for the page using the current entity.
  *
  * @param Page   $page
  * @param Entity $entity
  */
 public function updateSeoByEntity(BasePage $page, $entity)
 {
     //if no entity is provided
     if ($entity === null) {
         //we look for the entity of the page
         if ($page->getBusinessEntity() !== null) {
             $entity = $page->getBusinessEntity();
         }
     }
     //only if we have an entity instance
     if ($entity !== null) {
         //the page seo
         $pageSeo = $page->getSeo();
         //the page seo might not exist yet
         if ($pageSeo !== null) {
             $businessEntity = $this->businessEntityHelper->findByEntityInstance($entity);
             if ($businessEntity !== null) {
                 $businessProperties = $businessEntity->getBusinessPropertiesByType('seoable');
                 //parse the business properties
                 foreach ($businessProperties as $businessProperty) {
                     //parse of seo attributes
                     foreach ($this->pageSeoAttributes as $seoAttribute) {
                         $value = $this->getEntityAttributeValue($pageSeo, $seoAttribute);
                         // we only update value if its a string and (if its a VBP or its a BP where value is not defined)
                         if (is_string($value) && ($page instanceof VirtualBusinessPage || $page instanceof BusinessPage && $value == null)) {
                             $value = $this->parameterConverter->setBusinessPropertyInstance($value, $businessProperty, $entity);
                         }
                         $this->setEntityAttributeValue($pageSeo, $seoAttribute, $value);
                     }
                 }
             }
         }
     }
 }
Example #4
0
 /**
  * Create a sitemap priority type.
  *
  * @return \Symfony\Component\Form\Form The form
  **/
 protected function createSitemapPriorityType(BasePage $page)
 {
     $form = $this->createForm('victoire_sitemap_priority_pageseo_type', $page->getSeo(), ['action' => $this->generateUrl('victoire_sitemap_changePriority', ['id' => $page->getId()]), 'method' => 'PUT', 'attr' => ['class' => 'sitemapPriorityForm form-inline', 'data-pageId' => $page->getId(), 'id' => 'sitemap-priority-type-' . $page->getId(), 'style' => 'display: inline;']]);
     return $form;
 }