/**
  * Serialize a snapshot page proxy
  *
  * @return string
  */
 public function serialize()
 {
     if ($this->manager) {
         return serialize(array('pageId' => $this->getPage()->getId(), 'snapshotId' => $this->snapshot->getId()));
     }
     return serialize(array());
 }
 /**
  * @return \Sonata\PageBundle\Model\PageInterface|null
  */
 public function getTarget()
 {
     if ($this->target === null) {
         $content = json_decode($this->snapshot->getContent(), true);
         if (isset($content['target_id'])) {
             $target = $this->manager->getPageById($content['target_id']);
             if ($target) {
                 $this->setTarget($target);
             } else {
                 $this->target = false;
             }
         }
     }
     return $this->target ?: null;
 }
Example #3
0
 /**
  * Add snapshot
  *
  * @param \Sonata\PageBundle\Model\SnapshotInterface $snapshot
  */
 public function addSnapshot(SnapshotInterface $snapshot)
 {
     $this->snapshots[] = $snapshot;
     $snapshot->setPage($this);
 }
 /**
  * @param \Sonata\PageBundle\Model\SnapshotInterface $snapshot
  * @return \Sonata\PageBundle\Model\PageInterface
  */
 public function load(SnapshotInterface $snapshot)
 {
     $page = new Page();
     $page->setRouteName($snapshot->getRouteName());
     $page->setCustomUrl($snapshot->getUrl());
     $page->setUrl($snapshot->getUrl());
     $page->setPosition($snapshot->getPosition());
     $page->setDecorate($snapshot->getDecorate());
     $content = json_decode($snapshot->getContent(), true);
     $page->setId($content['id']);
     $page->setJavascript($content['javascript']);
     $page->setStylesheet($content['stylesheet']);
     $page->setRawHeaders($content['raw_headers']);
     $page->setMetaDescription($content['meta_description']);
     $page->setMetaKeyword($content['meta_keyword']);
     $page->setName($content['name']);
     $page->setSlug($content['slug']);
     $page->setTemplateCode($content['template_code']);
     $page->setRequestMethod($content['request_method']);
     $createdAt = new \DateTime();
     $createdAt->setTimestamp($content['created_at']);
     $page->setCreatedAt($createdAt);
     $updatedAt = new \DateTime();
     $updatedAt->setTimestamp($content['updated_at']);
     $page->setUpdatedAt($updatedAt);
     return $page;
 }
 /**
  * {@inheritdoc}
  */
 public function load(SnapshotInterface $snapshot)
 {
     $page = $this->pageManager->create();
     $page->setRouteName($snapshot->getRouteName());
     $page->setPageAlias($snapshot->getPageAlias());
     $page->setType($snapshot->getType());
     $page->setCustomUrl($snapshot->getUrl());
     $page->setUrl($snapshot->getUrl());
     $page->setPosition($snapshot->getPosition());
     $page->setDecorate($snapshot->getDecorate());
     $page->setSite($snapshot->getSite());
     $page->setEnabled($snapshot->getEnabled());
     $content = $this->fixPageContent($snapshot->getContent());
     $icon = $content['icon_id'] ? $this->registry->getManager()->getRepository('SymbioOrangeGateMediaBundle:Media')->findOneById($content['icon_id']) : null;
     $page->setId($content['id']);
     $page->setJavascript($content['javascript']);
     $page->setStylesheet($content['stylesheet']);
     $page->setRawHeaders($content['raw_headers']);
     $page->setTitle($content['title']);
     $page->setDescription($content['description']);
     $page->setIcon($icon);
     $page->setMetaDescription($content['meta_description']);
     $page->setMetaKeyword($content['meta_keyword']);
     $page->setName($content['name']);
     $page->setSlug($content['slug']);
     $page->setTemplateCode($content['template_code']);
     $page->setRequestMethod($content['request_method']);
     if (array_key_exists('cssClass', $content)) {
         $page->setCssClass($content['cssClass']);
     }
     $createdAt = new \DateTime();
     $createdAt->setTimestamp($content['created_at']);
     $page->setCreatedAt($createdAt);
     $updatedAt = new \DateTime();
     $updatedAt->setTimestamp($content['updated_at']);
     $page->setUpdatedAt($updatedAt);
     foreach ($snapshot->getTranslations() as $locale => $strans) {
         $ptrans = new PageTranslation();
         $ptrans->setObject($page);
         $ptrans->setLocale($locale);
         $ptrans->setEnabled($strans->getEnabled());
         $ptrans->setName($strans->getName());
         $ptrans->setUrl($strans->getUrl());
         $content = $strans->getContent();
         $ptrans->setObject($page);
         $ptrans->setLocale($locale);
         $ptrans->setTitle($content['title']);
         $ptrans->setDescription($content['description']);
         $ptrans->setMetaDescription($content['meta_description']);
         $ptrans->setMetaKeyword($content['meta_keyword']);
         $ptrans->setName($content['name']);
         $ptrans->setSlug($content['slug']);
         $page->addTranslation($ptrans);
     }
     return $page;
 }