-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathCommentController.php
More file actions
47 lines (39 loc) · 1.49 KB
/
CommentController.php
File metadata and controls
47 lines (39 loc) · 1.49 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
<?php
namespace Stfalcon\Bundle\BlogBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/**
* Controller for actions with DISQUS comments
*
* @author Stepan Tanasiychuk <ceo@stfalcon.com>
*/
class CommentController extends Controller
{
/**
* Synchronization comments count with disqus
*
* @param string $slug Slug of post
*
* @return Response
* @Route("/blog/post/{slug}/disqus-sync", name="blog_post_disqus_sync")
*
* @throws NotFoundHttpException
*/
public function disqusSyncAction($slug)
{
// @todo. нужно доставать полный список ЗААПРУВЛЕННЫХ комментариев или
// колличество комментариев к записи (если такой метод появится в API disqus)
// после чего обновлять их колличество в БД
$post = $this->get('stfalcon_blog.post.repository')->findOneBy(array('slug' => $slug));
if (!$post) {
throw new NotFoundHttpException();
}
$post->setCommentsCount($post->getCommentsCount() + 1);
$em = $this->get('doctrine.orm.entity_manager');
$em->persist($post);
$em->flush($post);
return new Response(json_encode('ok'));
}
}