Passed
Push — master ( 732152...809fdb )
by Florian
03:32
created

ApiController   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 12
dl 0
loc 35
c 0
b 0
f 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A semestersAction() 0 5 1
A activeEventAction() 0 16 4
1
<?php
2
3
/*
4
 * This file is part of the feedback project.
5
 *
6
 * (c) Florian Moser <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace App\Controller;
13
14
use App\Controller\Base\BaseApiController;
15
use App\Entity\Event;
16
use App\Entity\Semester;
17
use Symfony\Component\HttpFoundation\JsonResponse;
18
use Symfony\Component\Routing\Annotation\Route;
19
20
/**
21
 * @Route("/api")
22
 */
23
class ApiController extends BaseApiController
24
{
25
    /**
26
     * @Route("/active_event", name="api_active_event")
27
     *
28
     * @return JsonResponse
29
     */
30
    public function activeEventAction()
31
    {
32
        $now = new \DateTime();
33
        $today = $now->format('Y-m-d');
34
        $time = $now->format('H:i');
35
36
        $events = $this->getDoctrine()->getRepository(Event::class)->findBy(['date' => $today]);
37
        foreach ($events as $event) {
38
            if ($event->getFeedbackStartTime() < $time && $event->getFeedbackEndTime() > $time) {
39
                $event->loadTemplateIfSafe($this->getParameter('PUBLIC_DIR'));
40
41
                return $this->returnEvent($event);
42
            }
43
        }
44
45
        return $this->returnEvent(null);
46
    }
47
48
    /**
49
     * @Route("/semesters", name="api_semesters")
50
     *
51
     * @return JsonResponse
52
     */
53
    public function semestersAction()
54
    {
55
        $semesters = $this->getDoctrine()->getRepository(Semester::class)->findBy([], ['name' => 'DESC']);
56
57
        return $this->returnSemester($semesters);
58
    }
59
}
60