forked from camdram/camdram
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ApplicationController.php
75 lines (63 loc) · 2.46 KB
/
ApplicationController.php
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php
namespace Acts\CamdramBundle\Controller;
use FOS\RestBundle\Controller\FOSRestController;
use FOS\RestBundle\Controller\Annotations\RouteResource;
use Symfony\Component\HttpFoundation\Request;
use Acts\CamdramBundle\Entity\Application;
use Doctrine\Common\Collections\Criteria;
/**
* @RouteResource("Application")
*/
class ApplicationController extends FOSRestController
{
/**
* cgetAction
*
* Display application deadlines from now until the end of (camdram) time
*/
public function cgetAction(Request $request)
{
$applications = array_reverse($this->getDoctrine()->getRepository('ActsCamdramBundle:Application')
->findLatest(-1, new \DateTime()));
$view = $this->view($applications, 200)
->setTemplate('ActsCamdramBundle:Application:index.'.$request->getRequestFormat().'.twig')
->setTemplateVar('applications')
;
return $view;
}
public function getAction($identifier, Request $request)
{
$data = $this->getDoctrine()->getRepository('ActsCamdramBundle:Application')
->findOneByShowSlug($identifier, $this->get('acts.time_service')->getCurrentTime());
if (!$data) {
throw $this->createNotFoundException('No application exists with that identifier');
}
if ($request->getRequestFormat() == 'html') {
return $this->redirect($this->generateUrl('get_applications').'#'.$identifier);
}
else {
return $this->view($data);
}
}
/**
* weeksApplicationsAction
*
* Generates the table data for displaying application deadlines in
* the week beggining with $startOfWeek
*
* @param DateTime $startOfWeek The start date of the week.
*/
public function weeksApplicationsAction($startOfWeek)
{
$startDate = $startOfWeek->getTimestamp();
$endDate = clone $startOfWeek;
$endDate = $endDate->modify('+6 days')->getTimestamp();
$repo = $this->getDoctrine()->getEntityManager()->getRepository('ActsCamdramBundle:Application');
$applications = $repo->findScheduledOrderedByDeadline($startDate, $endDate);
$view = $this->view(array('startDate' => $startDate, 'endDate' => $endDate, 'applications' => $applications), 200)
->setTemplate('ActsCamdramBundle:Application:diary.html.twig')
->setTemplateVar('applications')
;
return $view;
}
}