Passed
Push — master ( f5688d...87bc65 )
by Julito
09:49
created

NewsController   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 22
dl 0
loc 56
rs 10
c 0
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A indexAction() 0 15 2
A newsAction() 0 21 2
1
<?php
2
/* For licensing terms, see /license.txt */
3
4
namespace Chamilo\CoreBundle\Controller;
5
6
use Chamilo\CoreBundle\Framework\PageController;
7
use Chamilo\PageBundle\Entity\Block;
8
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
9
use Symfony\Component\HttpFoundation\Request;
10
use Symfony\Component\HttpFoundation\Response;
11
use Symfony\Component\Routing\Annotation\Route;
12
use Symfony\Component\Security\Core\Authorization\AuthorizationChecker;
13
14
/**
15
 * Class IndexController
16
 * author Julio Montoya <[email protected]>.
17
 * @Route("/news")
18
 *
19
 * @package Chamilo\CoreBundle\Controller
20
 */
21
class NewsController extends BaseController
22
{
23
    /**
24
     * The Chamilo index home page.
25
     *
26
     * @Route("/", name="news_index", methods={"GET", "POST"}, options={"expose"=true})
27
     *
28
     * @return Response
29
     */
30
    public function indexAction(Request $request): Response
31
    {
32
        $toolBar = '';
33
        if ($this->isGranted('ROLE_ADMIN')) {
34
            $actionEdit = \Display::url(
35
                \Display::return_icon('edit.png', get_lang('EditSystemAnnouncement'), [], ICON_SIZE_MEDIUM),
36
                api_get_path(WEB_PATH).'main/admin/system_announcements.php'
37
            );
38
            $toolBar = \Display::toolbarAction('toolbar', [$actionEdit]);
39
        }
40
41
        return $this->render(
42
            '@ChamiloCore/News/index.html.twig',
43
            [
44
                'toolbar' => $toolBar
45
            ]
46
        );
47
    }
48
49
    /**
50
     * The Chamilo index home page.
51
     *
52
     * @Route("/{id}", name="news", methods={"GET", "POST"}, options={"expose"=true})
53
     *
54
     * @return Response
55
     */
56
    public function newsAction($id = null)
57
    {
58
        $visibility = \SystemAnnouncementManager::getCurrentUserVisibility();
59
60
        $toolBar = '';
61
        if (empty($id)) {
62
            $content = \SystemAnnouncementManager::getAnnouncements($visibility);
63
64
            return $this->render(
65
                '@ChamiloCore/News/slider.html.twig',
66
                [
67
                    'announcements' => $content
68
                ]
69
            );
70
        } else {
71
            $content = \SystemAnnouncementManager::getAnnouncement($id, $visibility);
72
73
            return $this->render(
74
                '@ChamiloCore/News/view.html.twig',
75
                [
76
                    'announcement' => $content
77
                ]
78
            );
79
        }
80
    }
81
}
82