-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathPostController.php
More file actions
118 lines (104 loc) · 3.43 KB
/
PostController.php
File metadata and controls
118 lines (104 loc) · 3.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<?php
namespace Stfalcon\Bundle\BlogBundle\Controller;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/**
* PostController
*
* @author Stepan Tanasiychuk <ceo@stfalcon.com>
*/
class PostController extends Controller
{
/**
* List of posts for admin
*
* @param int $page Page number
*
* @return array
*
* @Route("/blog/{title}/{page}", name="blog",
* requirements={"page"="\d+", "title"="page"},
* defaults={"page"="1", "title"="page"})
* @Template()
*/
public function indexAction($page)
{
$allPostsQuery = $this->get('stfalcon_blog.post.repository')->findAllPostsAsQuery();
$posts= $this->get('knp_paginator')->paginate($allPostsQuery, $page, 10);
if ($this->has('application_default.menu.breadcrumbs')) {
$breadcrumbs = $this->get('application_default.menu.breadcrumbs');
$breadcrumbs->addChild('Блог')->setCurrent(true);
}
return array(
'posts' => $posts,
'disqus_shortname' => $this->container->getParameter('stfalcon_blog.disqus_shortname')
);
}
/**
* View post
*
* @Route("/blog/post/{slug}", name="blog_post_view")
* @Template()
*
* @param string $slug
*
* @return array
*
* @throws NotFoundHttpException
*/
public function viewAction($slug)
{
$post = $this->get('stfalcon_blog.post.repository')->findOneBy(array('slug' => $slug));
if (!$post) {
throw new NotFoundHttpException();
}
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 array(
'post' => $post,
'disqus_shortname' => $this->container->getParameter('stfalcon_blog.disqus_shortname')
);
}
/**
* RSS feed
*
* @Route("/blog/rss", name="blog_rss")
*
* @return Response
*/
public function rssAction()
{
$feed = new \Zend\Feed\Writer\Feed();
$feed->setTitle($this->container->getParameter('stfalcon_blog.rss.title'));
$feed->setDescription($this->container->getParameter('stfalcon_blog.rss.description'));
$feed->setLink($this->generateUrl('blog_rss', array(), true));
$posts = $this->get('stfalcon_blog.post.repository')->findAllPosts();
foreach ($posts as $post) {
$entry = new \Zend\Feed\Writer\Entry();
$entry->setTitle($post->getTitle());
$entry->setLink($this->generateUrl('blog_post_view', array('slug' => $post->getSlug()), true));
$feed->addEntry($entry);
}
return new Response($feed->export('rss'));
}
/**
* Show last blog posts
*
* @Template()
*
* @param int $count A count of posts
*
* @return array()
*/
public function lastAction($count = 1)
{
$posts = $this->get('stfalcon_blog.post.repository')->findLastPosts($count);
return array('posts' => $posts);
}
}