/**
  * @param string        $permalink
  * @param BlogInterface $blog
  *
  * @return PostInterface
  */
 public function findOneByPermalink($permalink, BlogInterface $blog)
 {
     $repository = $this->getRepository();
     $query = $repository->createQueryBuilder('p');
     $urlParameters = $blog->getPermalinkGenerator()->getParameters($permalink);
     $parameters = array();
     if (isset($urlParameters['year']) && isset($urlParameters['month']) && isset($urlParameters['day'])) {
         $pdqp = $this->getPublicationDateQueryParts(sprintf('%d-%d-%d', $urlParameters['year'], $urlParameters['month'], $urlParameters['day']), 'day');
         $parameters = array_merge($parameters, $pdqp['params']);
         $query->andWhere($pdqp['query']);
     }
     if (isset($urlParameters['slug'])) {
         $query->andWhere('p.slug = :slug');
         $parameters['slug'] = $urlParameters['slug'];
     }
     if (isset($urlParameters['collection'])) {
         $pcqp = $this->getPublicationCollectionQueryParts($urlParameters['collection']);
         $parameters = array_merge($parameters, $pcqp['params']);
         $query->leftJoin('p.collection', 'c')->andWhere($pcqp['query']);
     }
     if (count($parameters) == 0) {
         return null;
     }
     $query->setParameters($parameters);
     $results = $query->getQuery()->getResult();
     if (count($results) > 0) {
         return $results[0];
     }
     return null;
 }
 /**
  * @param $permalink
  * @param \Sonata\NewsBundle\Model\BlogInterface $blog
  * @return null
  */
 public function findOneByPermalink($permalink, BlogInterface $blog)
 {
     try {
         $repository = $this->em->getRepository($this->class);
         $query = $repository->createQueryBuilder('p');
         $urlParameters = $blog->getPermalinkGenerator()->getParameters($permalink);
         $parameters = array();
         if (isset($urlParameters['year']) && isset($urlParameters['month']) && isset($urlParameters['day'])) {
             $pdqp = $this->getPublicationDateQueryParts(sprintf('%d-%d-%d', $urlParameters['year'], $urlParameters['month'], $urlParameters['day']), 'day');
             $parameters = array_merge($parameters, $pdqp['params']);
             $query->andWhere($pdqp['query']);
         }
         if (isset($urlParameters['slug'])) {
             $query->andWhere('p.slug = :slug');
             $parameters['slug'] = $urlParameters['slug'];
         }
         if (isset($urlParameters['category'])) {
             $pcqp = $this->getPublicationCategoryQueryParts($urlParameters['category']);
             $parameters = array_merge($parameters, $pcqp['params']);
             $query->leftJoin('p.category', 'c')->andWhere($pcqp['query']);
         }
         if (count($parameters) == 0) {
             return null;
         }
         $query->setParameters($parameters);
         return $query->getQuery()->getSingleResult();
     } catch (NoResultException $e) {
         return null;
     }
 }
 /**
  * {@inheritdoc}
  */
 protected function getMenu(BlockContextInterface $blockContext)
 {
     $menu = $this->getRootMenu($blockContext);
     if ($post = $blockContext->getBlock()->getSetting('post')) {
         $menu->addChild($post->getTitle(), array('route' => 'sonata_news_view', 'routeParameters' => array('permalink' => $this->blog->getPermalinkGenerator()->generate($post))));
     }
     return $menu;
 }