/**
  * View post
  *
  * @Route("/blog/post/{slug}", name="blog_post_view")
  * @Template()
  *
  * @param Post $post
  *
  * @return array
  */
 public function viewAction(Post $post)
 {
     if ($this->has('application_default.menu.breadcrumbs')) {
         $breadcrumbs = $this->get('application_default.menu.breadcrumbs');
         $breadcrumbs->addChild('Блог', array('route' => 'blog'));
         $breadcrumbs->addChild($post->getTitle())->setCurrent(true);
     }
     return $this->_getRequestArrayWithDisqusShortname(array('post' => $post));
 }
示例#2
0
 /**
  * Create and load posts fixtures to database
  *
  * @param ObjectManager $manager Entity manager object
  */
 public function load(ObjectManager $manager)
 {
     $adminUser = $this->getReference('user-admin');
     $secondUser = $this->getReference('user-second');
     $symfonyTag = $this->getReference('tag-symfony2');
     $doctrine2Tag = $this->getReference('tag-doctrine2');
     // posts
     $postFirst = new Post();
     $postFirst->setTitle('My first post');
     $postFirst->setSlug('my-first-post');
     $postFirst->setText('In work we use Symfony2.<!--more-->And text after cut');
     $postFirst->addTag($symfonyTag);
     $postFirst->addTag($doctrine2Tag);
     $postFirst->setAuthor($adminUser);
     $postFirst->setPublished(true);
     $manager->persist($postFirst);
     $manager->merge($symfonyTag);
     $manager->merge($doctrine2Tag);
     $postAboutPhp = new Post();
     $postAboutPhp->setTitle('Post about php');
     $postAboutPhp->setSlug('post-about-php');
     $postAboutPhp->setText('The PHP development team would like to announce the immediate availability of PHP 5.3.6.');
     $postAboutPhp->addTag($symfonyTag);
     $postAboutPhp->addTag($doctrine2Tag);
     $postAboutPhp->setAuthor($secondUser);
     $postAboutPhp->setPublished(true);
     $manager->persist($postAboutPhp);
     $manager->merge($symfonyTag);
     $manager->merge($doctrine2Tag);
     $manager->flush();
     $this->addReference('post-first', $postFirst);
     $this->addReference('post-about-php', $postAboutPhp);
 }
示例#3
0
 /**
  * Get post first image path
  *
  * @param Post   $post   Current post
  * @param string $filter Image filter
  * @param string $host   Current host
  *
  * @return string
  */
 public function getPostFirstImagePath(Post $post, $filter = '', $host = '')
 {
     $imagePath = '';
     if (preg_match('~<img[^>]+src="([^"]+)"[^>]*>~i', $post->getText(), $matches)) {
         $imagePath = $this->cachePathResolver->getBrowserPath($matches[1], $filter);
     }
     if ('' === $filter && isset($matches[1])) {
         $imagePath = $matches[1];
     }
     return $imagePath;
 }
 /**
  * Synchronization comments count with disqus
  *
  * @param Post $post Post object
  *
  * @return Response
  * @Route("/blog/post/{slug}/disqus-sync", name="blog_post_disqus_sync")
  */
 public function disqusSyncAction(Post $post)
 {
     // @todo. нужно доставать полный список ЗААПРУВЛЕННЫХ комментариев или
     // колличество комментариев к записи (если такой метод появится в API disqus)
     // после чего обновлять их колличество в БД
     $post->setCommentsCount($post->getCommentsCount() + 1);
     $em = $this->get('doctrine.orm.entity_manager');
     $em->persist($post);
     $em->flush($post);
     return new Response(json_encode('ok'));
 }
 /**
  * Create and load posts fixtures to database
  *
  * @param Doctrine\ORM\EntityManager $manager Entity manager object
  *
  * @return void
  */
 public function load(ObjectManager $manager)
 {
     for ($i = 1; $i <= 12; $i++) {
         $post = new Post();
         $post->setTitle('Post for paginator #' . $i);
         $post->setSlug('post-for-paginator-' . $i);
         $post->setText('Generally this bundle is based on Knp Pager component. This component introduces a different way for pagination handling. You can read more about the internal logic on the given documentation link.' . $i);
         $post->setTags(array($manager->merge($this->getReference('tag-php'))));
         $manager->persist($post);
     }
     $manager->flush();
 }
示例#6
0
 /**
  * Create and load posts fixtures to database
  *
  * @param Doctrine\ORM\EntityManager $manager Entity manager object
  *
  * @return void
  */
 public function load(ObjectManager $manager)
 {
     // posts
     $postfirst = new Post();
     $postfirst->setTitle('My first post');
     $postfirst->setSlug('my-first-post');
     $postfirst->setText('In work we use Symfony2.<!--more-->And text after cut');
     $postfirst->setTags(array($manager->merge($this->getReference('tag-symfony2')), $manager->merge($this->getReference('tag-doctrine2'))));
     $manager->persist($postfirst);
     $postaboutphp = new Post();
     $postaboutphp->setTitle('Post about php');
     $postaboutphp->setSlug('post-about-php');
     $postaboutphp->setText('The PHP development team would like to announce the immediate availability of PHP 5.3.6.');
     $postaboutphp->setTags(array($manager->merge($this->getReference('tag-symfony2')), $manager->merge($this->getReference('tag-php'))));
     $manager->persist($postaboutphp);
     $manager->flush();
     $this->addReference('post-first', $postfirst);
     $this->addReference('post-about-php', $postaboutphp);
 }
 /**
  * Create and load posts fixtures to database
  *
  * @param ObjectManager $manager Entity manager object
  */
 public function load(ObjectManager $manager)
 {
     $phpTag = $this->getReference('tag-php');
     $firstUser = $this->getReference('user-first');
     $createdAt = new \DateTime();
     for ($i = 1; $i <= 12; $i++) {
         $post = new Post();
         $title = 'Post for paginator #' . $i;
         $post->setTitle($title);
         $post->setSlug('post-for-paginator-' . $i);
         $text = 'Generally this bundle is based on Knp Pager component. This component introduces a different way for pagination handling. You can read more about the internal logic on the given documentation link.' . $i;
         $post->setText($text);
         $post->addTag($phpTag);
         $post->setAuthor($firstUser);
         $post->setCreated(clone $createdAt->modify("+{$i} day"));
         $post->setPublished(true);
         $post->addTranslation(new PostTranslation('en', 'title', 'EN ' . $title));
         $post->addTranslation(new PostTranslation('en', 'text', 'EN ' . $text));
         $manager->persist($post);
         $manager->merge($phpTag);
     }
     $manager->flush();
 }