diff --git a/src/Hackspace/Bundle/CalciferBundle/Controller/LocationController.php b/src/Hackspace/Bundle/CalciferBundle/Controller/LocationController.php index 631892a..bdf0945 100755 --- a/src/Hackspace/Bundle/CalciferBundle/Controller/LocationController.php +++ b/src/Hackspace/Bundle/CalciferBundle/Controller/LocationController.php @@ -40,7 +40,7 @@ class LocationController extends Controller * @Method("GET") * @Template("CalciferBundle:Event:index.html.twig") */ - public function showAction($slug,$format) + public function showAction($slug, $format) { /** @var EntityManager $em */ $em = $this->getDoctrine()->getManager(); @@ -58,17 +58,17 @@ class LocationController extends Controller $em = $this->getDoctrine()->getManager(); $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') ->where('e.startdate >= :startdate') ->andWhere('e.locations_id = :location') ->orderBy('e.startdate') - ->setParameter('startdate',$now) - ->setParameter('location',$location->id); + ->setParameter('startdate', $now) + ->setParameter('location', $location->id); $entities = $qb->getQuery()->execute(); if ($format == 'ics') { @@ -118,4 +118,73 @@ class LocationController extends Controller ); } } + + /** + * Finds and displays a Event entity. + * + * @Route("/{slug}/bearbeiten", name="location_edit") + * @Method("GET") + * @Template() + */ + public function editAction($slug) + { + /** @var EntityManager $em */ + $em = $this->getDoctrine()->getManager(); + + /** @var EntityRepository $repo */ + $repo = $em->getRepository('CalciferBundle:Location'); + + /** @var Location $location */ + $location = $repo->findOneBy(['slug' => $slug]); + + if (!$location) { + throw $this->createNotFoundException('Unable to find Location entity.'); + } + + return [ + 'entity' => $location + ]; + } + + /** + * Finds and displays a Event entity. + * + * @Route("/{slug}/bearbeiten", name="location_update") + * @Method("POST") + */ + public function updateAction(Request $request, $slug) { + /** @var EntityManager $em */ + $em = $this->getDoctrine()->getManager(); + + /** @var EntityRepository $repo */ + $repo = $em->getRepository('CalciferBundle:Location'); + + /** @var Location $location */ + $location = $repo->findOneBy(['slug' => $slug]); + + if (!$location) { + throw $this->createNotFoundException('Unable to find Location entity.'); + } + + if ($location->name != $request->get('name')) { + $location->name = $request->get('name'); + $location->slug = $location->generateSlug($location->name,$em); + } + $location->streetaddress = $request->get('streetaddress'); + $location->streetnumber = $request->get('streetnumber'); + $location->zipcode = $request->get('zipcode'); + $location->city = $request->get('city'); + + $latlon = $request->get('geocords'); + $latlon = explode(',',$latlon); + if (count($latlon) == 2) { + $location->lat = $latlon[0]; + $location->lon = $latlon[1]; + } + + $em->persist($location); + $em->flush(); + + return $this->redirect($this->generateUrl('location_show', array('slug' => $location->slug))); + } } diff --git a/src/Hackspace/Bundle/CalciferBundle/Resources/assets/css/events.scss b/src/Hackspace/Bundle/CalciferBundle/Resources/assets/css/events.scss index 6b615cb..30f8f07 100755 --- a/src/Hackspace/Bundle/CalciferBundle/Resources/assets/css/events.scss +++ b/src/Hackspace/Bundle/CalciferBundle/Resources/assets/css/events.scss @@ -44,4 +44,9 @@ form .ui.form { #map { height: 20rem; + +.location-edit { + text-decoration: none; +} + } \ No newline at end of file diff --git a/src/Hackspace/Bundle/CalciferBundle/Resources/views/Location/edit.html.twig b/src/Hackspace/Bundle/CalciferBundle/Resources/views/Location/edit.html.twig new file mode 100644 index 0000000..f511f12 --- /dev/null +++ b/src/Hackspace/Bundle/CalciferBundle/Resources/views/Location/edit.html.twig @@ -0,0 +1,166 @@ +{% extends 'CalciferBundle::layout.html.twig' %} + +{% block css %} + {% stylesheets filter="compass" + "@CalciferBundle/Resources/assets/css/jquery.datetimepicker.scss" + "@CalciferBundle/Resources/assets/css/events.scss" + "@CalciferBundle/Resources/assets/css/leaflet.scss" %} + + {% endstylesheets %} +{% endblock %} + +{% block javascripts %} + {% javascripts + "@CalciferBundle/Resources/assets/js/jquery.datetimepicker.js" + "@CalciferBundle/Resources/assets/js/events.js" + "@CalciferBundle/Resources/assets/js/leaflet.js" %} + + {% endjavascripts %} +{% endblock %} + +{% block body -%} +