Finaly got the routing right.
This commit is contained in:
parent
6f0b6eabef
commit
8f66f58965
2 changed files with 67 additions and 87 deletions
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace Hackspace\Bundle\CalciferBundle\Controller;
|
||||
|
||||
use Doctrine\Common\Annotations\Annotation\Required;
|
||||
use Doctrine\ORM\EntityManager;
|
||||
use Doctrine\ORM\EntityRepository;
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
|
@ -35,11 +36,11 @@ class LocationController extends Controller
|
|||
/**
|
||||
* Finds and displays a Event entity.
|
||||
*
|
||||
* @Route("/{slug}(?!\.ics)", name="location_show")
|
||||
* @Route("/{slug}.{format}", name="location_show", defaults={"format" = "html"})
|
||||
* @Method("GET")
|
||||
* @Template("CalciferBundle:Event:index.html.twig")
|
||||
*/
|
||||
public function showAction($slug)
|
||||
public function showAction($slug,$format)
|
||||
{
|
||||
/** @var EntityManager $em */
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
|
@ -67,52 +68,41 @@ class LocationController extends Controller
|
|||
->andWhere('e.locations_id = :location')
|
||||
->orderBy('e.startdate')
|
||||
->setParameter('startdate',$now)
|
||||
->setParameter('location',$location->getId());
|
||||
->setParameter('location',$location->id);
|
||||
$entities = $qb->getQuery()->execute();
|
||||
|
||||
return array(
|
||||
'entities' => $entities,
|
||||
'location' => $location,
|
||||
);
|
||||
}
|
||||
if ($format == 'ics') {
|
||||
$calendar = new Calendar();
|
||||
$calendar->setProdId('-//My Company//Cool Calendar App//EN');
|
||||
|
||||
/**
|
||||
* Finds and displays a Event entity.
|
||||
*
|
||||
* @Route("/{slug}\.ics", name="location_show_ics")
|
||||
* @Method("GET")
|
||||
*/
|
||||
public function showActionICS($slug)
|
||||
{
|
||||
$results = $this->showAction(str_replace('.ics','',$slug));
|
||||
$entities = $results['entities'];
|
||||
foreach ($entities as $entity) {
|
||||
/** @var Event $entity */
|
||||
$event = new CalendarEvent();
|
||||
$event->setStart($entity->startdate);
|
||||
$event->setEnd($entity->enddate);
|
||||
$event->setSummary($entity->summary);
|
||||
$event->setDescription($entity->description);
|
||||
$location = new \Jsvrcek\ICS\Model\Description\Location();
|
||||
$location->setName($entity->getLocation()->name);
|
||||
$event->setLocations([$location]);
|
||||
$calendar->addEvent($event);
|
||||
}
|
||||
|
||||
$calendar = new Calendar();
|
||||
$calendar->setProdId('-//My Company//Cool Calendar App//EN');
|
||||
$calendarExport = new CalendarExport(new CalendarStream, new Formatter());
|
||||
$calendarExport->addCalendar($calendar);
|
||||
|
||||
foreach($entities as $entity) {
|
||||
/** @var Event $entity */
|
||||
$event = new CalendarEvent();
|
||||
$event->setStart($entity->getStartdate());
|
||||
if ($entity->getEnddate() instanceof DateTime)
|
||||
$event->setEnd($entity->getEnddate());
|
||||
$event->setSummary($entity->getSummary());
|
||||
$event->setDescription($entity->getDescription());
|
||||
$location = new \Jsvrcek\ICS\Model\Description\Location();
|
||||
$location->setName($entity->getLocation()->getName());
|
||||
$event->setLocations([$location]);
|
||||
$calendar->addEvent($event);
|
||||
//output .ics formatted text
|
||||
$result = $calendarExport->getStream();
|
||||
|
||||
$response = new Response($result);
|
||||
$response->headers->set('Content-Type', 'text/calendar');
|
||||
|
||||
return $response;
|
||||
} else {
|
||||
return array(
|
||||
'entities' => $entities,
|
||||
'location' => $location,
|
||||
);
|
||||
}
|
||||
|
||||
$calendarExport = new CalendarExport(new CalendarStream, new Formatter());
|
||||
$calendarExport->addCalendar($calendar);
|
||||
|
||||
//output .ics formatted text
|
||||
$result = $calendarExport->getStream();
|
||||
|
||||
$response = new Response($result);
|
||||
$response->headers->set('Content-Type', 'text/calendar');
|
||||
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,11 +35,11 @@ class TagController extends Controller
|
|||
/**
|
||||
* Finds and displays a Event entity.
|
||||
*
|
||||
* @Route("/{slug}(?!\.ics)", name="tag_show")
|
||||
* @Route("/{slug}.{format}", defaults={"format" = "html"}, name="tag_show")
|
||||
* @Method("GET")
|
||||
* @Template("CalciferBundle:Event:index.html.twig")
|
||||
*/
|
||||
public function showAction($slug)
|
||||
public function showAction($slug, $format)
|
||||
{
|
||||
/** @var EntityManager $em */
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
|
@ -55,60 +55,50 @@ class TagController extends Controller
|
|||
}
|
||||
|
||||
$now = new \DateTime();
|
||||
$now->setTime(0,0,0);
|
||||
$now->setTime(0, 0, 0);
|
||||
|
||||
/** @var QueryBuilder $qb */
|
||||
$qb = $em->createQueryBuilder();
|
||||
$qb ->select(array('e'))
|
||||
$qb->select(array('e'))
|
||||
->from('CalciferBundle:Event', 'e')
|
||||
->join('e.tags', 't', 'WITH', $qb->expr()->in('t.id', $tag->getId()))
|
||||
->where('e.startdate >= :startdate')
|
||||
->orderBy('e.startdate')
|
||||
->setParameter('startdate',$now);
|
||||
->setParameter('startdate', $now);
|
||||
$entities = $qb->getQuery()->execute();
|
||||
|
||||
return array(
|
||||
'entities' => $entities,
|
||||
'tag' => $tag,
|
||||
);
|
||||
}
|
||||
if ($format == 'ics') {
|
||||
$calendar = new Calendar();
|
||||
$calendar->setProdId('-//My Company//Cool Calendar App//EN');
|
||||
|
||||
/**
|
||||
* Finds and displays a Event entity.
|
||||
*
|
||||
* @Route("/{slug}.ics", name="tag_show_ics")
|
||||
* @Method("GET")
|
||||
*/
|
||||
public function showActionICS($slug)
|
||||
{
|
||||
$results = $this->showAction(str_replace('.ics','',$slug));
|
||||
$entities = $results['entities'];
|
||||
foreach ($entities as $entity) {
|
||||
/** @var Event $entity */
|
||||
$event = new CalendarEvent();
|
||||
$event->setStart($entity->startdate);
|
||||
$event->setEnd($entity->enddate);
|
||||
$event->setSummary($entity->summary);
|
||||
$event->setDescription($entity->description);
|
||||
$location = new \Jsvrcek\ICS\Model\Description\Location();
|
||||
$location->setName($entity->getLocation()->name);
|
||||
$event->setLocations([$location]);
|
||||
$calendar->addEvent($event);
|
||||
}
|
||||
|
||||
$calendar = new Calendar();
|
||||
$calendar->setProdId('-//My Company//Cool Calendar App//EN');
|
||||
$calendarExport = new CalendarExport(new CalendarStream, new Formatter());
|
||||
$calendarExport->addCalendar($calendar);
|
||||
|
||||
foreach($entities as $entity) {
|
||||
/** @var Event $entity */
|
||||
$event = new CalendarEvent();
|
||||
$event->setStart($entity->getStartdate());
|
||||
$event->setEnd($entity->getEnddate());
|
||||
$event->setSummary($entity->getSummary());
|
||||
$event->setDescription($entity->getDescription());
|
||||
$location = new \Jsvrcek\ICS\Model\Description\Location();
|
||||
$location->setName($entity->getLocation()->getName());
|
||||
$event->setLocations([$location]);
|
||||
$calendar->addEvent($event);
|
||||
//output .ics formatted text
|
||||
$result = $calendarExport->getStream();
|
||||
|
||||
$response = new Response($result);
|
||||
$response->headers->set('Content-Type', 'text/calendar');
|
||||
|
||||
return $response;
|
||||
} else {
|
||||
return array(
|
||||
'entities' => $entities,
|
||||
'tag' => $tag,
|
||||
);
|
||||
}
|
||||
|
||||
$calendarExport = new CalendarExport(new CalendarStream, new Formatter());
|
||||
$calendarExport->addCalendar($calendar);
|
||||
|
||||
//output .ics formatted text
|
||||
$result = $calendarExport->getStream();
|
||||
|
||||
$response = new Response($result);
|
||||
$response->headers->set('Content-Type', 'text/calendar');
|
||||
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue