Passed
Push — master ( 689c60...4980bd )
by Julito
09:36
created

NewsController::newsAction()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 20
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 10
c 0
b 0
f 0
nc 2
nop 1
dl 0
loc 20
rs 9.9332
1
<?php
2
3
declare(strict_types=1);
4
5
/* For licensing terms, see /license.txt */
6
7
namespace Chamilo\CoreBundle\Controller;
8
9
use Chamilo\CoreBundle\Repository\SysAnnouncementRepository;
10
use Chamilo\CoreBundle\Traits\ControllerTrait;
11
use Display;
12
use Symfony\Component\HttpFoundation\JsonResponse;
13
use Symfony\Component\HttpFoundation\Response;
14
use Symfony\Component\Routing\Annotation\Route;
15
16
/**
17
 * Class IndexController
18
 * author Julio Montoya <[email protected]>.
19
 */
20
class NewsController extends BaseController
21
{
22
    use ControllerTrait;
23
24
    /**
25
     * @Route("/news/list", name="news_index", methods={"GET"}, options={"expose"=true})
26
     */
27
    public function indexAction(SysAnnouncementRepository $sysAnnouncementRepository): Response
28
    {
29
        /*$toolBar = '';
30
        if ($this->isGranted('ROLE_ADMIN')) {
31
            $actionEdit = Display::url(
32
                Display::return_icon('edit.png', $this->trans('EditSystemAnnouncement'), [], ICON_SIZE_MEDIUM),
33
                api_get_path(WEB_PATH).'main/admin/system_announcements.php'
34
            );
35
            $toolBar = Display::toolbarAction('toolbar', [$actionEdit]);
36
        }*/
37
        $user = $this->getUser();
38
39
        $list = [];
40
        if (null !== $user) {
41
            $list = $sysAnnouncementRepository->getAnnouncements(
42
                $this->getUser(),
43
                $this->getAccessUrl(),
44
                $this->getRequest()->getLocale()
45
            );
46
        }
47
48
        return new JsonResponse($list);
49
    }
50
}
51