NoticeController   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 73
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 9

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 6
c 1
b 0
f 1
lcom 1
cbo 9
dl 0
loc 73
ccs 0
cts 40
cp 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A closeAction() 0 10 1
B showAction() 0 35 4
A seeLaterAction() 0 8 1
1
<?php
2
/**
3
 * AnimeDb package.
4
 *
5
 * @author    Peter Gribanov <[email protected]>
6
 * @copyright Copyright (c) 2011, Peter Gribanov
7
 * @license   http://opensource.org/licenses/GPL-3.0 GPL v3
8
 */
9
namespace AnimeDb\Bundle\AppBundle\Controller;
10
11
use AnimeDb\Bundle\AppBundle\Entity\Notice;
12
use AnimeDb\Bundle\AppBundle\Repository\Notice as NoticeRepository;
13
use Symfony\Component\HttpFoundation\JsonResponse;
14
use Symfony\Component\HttpFoundation\Request;
15
16
class NoticeController extends BaseController
17
{
18
    /**
19
     * Show last notice.
20
     *
21
     * @param Request $request
22
     *
23
     * @return JsonResponse
24
     */
25
    public function showAction(Request $request)
26
    {
27
        $em = $this->getDoctrine()->getManager();
28
        /* @var $rep NoticeRepository */
29
        $rep = $em->getRepository('AnimeDbAppBundle:Notice');
30
31
        $notice = $rep->getFirstShow();
32
        // caching
33
        /* @var $response JsonResponse */
34
        $response = $this->getCacheTimeKeeper()->getResponse([], -1, new JsonResponse());
35
        $response->setEtag(md5($notice ? $notice->getId() : 0));
36
        // response was not modified for this request
37
        if ($response->isNotModified($request)) {
38
            return $response;
39
        }
40
41
        // shown notice
42
        if (!is_null($notice)) {
43
            $notice->shown();
44
            $em->persist($notice);
45
            $em->flush();
46
47
            $response->setData([
48
                'notice' => $notice->getId(),
49
                'close' => $this->generateUrl('notice_close', ['id' => $notice->getId()]),
50
                'see_later' => $this->generateUrl('notice_see_later'),
51
                'content' => $this->renderView('AnimeDbAppBundle:Notice:show.html.twig', [
52
                    'notice' => $notice,
53
                    'link_all' => $request->query->getBoolean('all'),
54
                ]),
55
            ]);
56
        }
57
58
        return $response;
59
    }
60
61
    /**
62
     * @param Notice $notice
63
     *
64
     * @return JsonResponse
65
     */
66
    public function closeAction(Notice $notice)
67
    {
68
        // mark as closed
69
        $notice->setStatus(Notice::STATUS_CLOSED);
70
        $em = $this->getDoctrine()->getManager();
71
        $em->persist($notice);
72
        $em->flush();
73
74
        return new JsonResponse([]);
75
    }
76
77
    /**
78
     * @return JsonResponse
79
     */
80
    public function seeLaterAction()
81
    {
82
        /* @var $rep NoticeRepository */
83
        $rep = $this->getDoctrine()->getRepository('AnimeDbAppBundle:Notice');
84
        $rep->seeLater();
85
86
        return new JsonResponse([]);
87
    }
88
}
89