diff --git a/src/Hackspace/Bundle/CalciferBundle/Controller/RepeatingEventController.php b/src/Hackspace/Bundle/CalciferBundle/Controller/RepeatingEventController.php new file mode 100755 index 0000000..db41dca --- /dev/null +++ b/src/Hackspace/Bundle/CalciferBundle/Controller/RepeatingEventController.php @@ -0,0 +1,262 @@ +getDoctrine()->getManager(); + + /** @var EntityRepository $repo */ + $repo = $em->getRepository('CalciferBundle:RepeatingEvent'); + + $entities = $repo->findAll(); + + return [ + 'entities' => $entities, + ]; + } + + /** + * Displays a form to create a repeating event + * + * @Route("/neu", name="repeating_event_new") + * @Method("GET") + * @Template() + */ + public function newAction() + { + $entity = new RepeatingEvent(); + + return [ + 'entity' => $entity, + ]; + } + + /** + * Creates a repeating event + * + * @Route("/neu", name="repeating_event_create") + * @Method("POST") + * @Template("CalciferBundle:RepeatingEvent:new.html.twig") + */ + public function createAction(Request $request) + { + $entity = new RepeatingEvent(); + $this->fillEntity($request, $entity); + if ($this->validateRepeatingEvent($entity)) { + $ret = $this->saveRepeatingEvent($request, $entity); + if ($entity->id > 0) { + return $this->redirect($this->generateUrl('repeating_event_show')); + } else { + throw new \Exception('Could not save repeating event?!?'); + } + } + return [ + 'entity' => $entity, + ]; + + } + + /** + * Displays a form to edit a repeating event + * + * @Route("/{slug}/bearbeiten",name="repeating_event_edit") + * @Method("GET") + * @Template() + */ + public function editAction($slug) + { + /** @var EntityManager $em */ + $em = $this->getDoctrine()->getManager(); + + /** @var EntityRepository $repo */ + $repo = $em->getRepository('CalciferBundle:RepeatingEvent'); + + /** @var Event $entity */ + $entity = $repo->findOneBy(['slug' => $slug]); + + if (!$entity) { + throw $this->createNotFoundException('Unable to find RepeatingEvent entity.'); + } + + return array( + 'entity' => $entity, + ); + } + + /** + * Updates a repeating event + * + * @Route("/{slug}/bearbeiten",name="repeating_event_update") + * @Method("POST") + * @Template("CalciferBundle:RepeatingEvent:edit.html.twig") + */ + public function updateAction(Request $request, $slug) + { + /** @var EntityManager $em */ + $em = $this->getDoctrine()->getManager(); + + /** @var EntityRepository $repo */ + $repo = $em->getRepository('CalciferBundle:RepeatingEvent'); + + /** @var Event $entity */ + $entity = $repo->findOneBy(['slug' => $slug]); + + if (!$entity) { + throw $this->createNotFoundException('Unable to find RepeatingEvent entity.'); + } + + $this->fillEntity($request, $entity); + if ($this->validateRepeatingEvent($entity)) { + $ret = $this->saveRepeatingEvent($request, $entity); + if ($entity->id > 0) { + return $this->redirect($this->generateUrl('repeating_event_show')); + } else { + throw new \Exception('Could not save repeating event?!?'); + } + } + return [ + 'entity' => $entity, + ]; + } + + private function fillEntity(Request $request, RepeatingEvent $entity) + { + $fields = [ + 'duration', + 'repeating_pattern', + 'summary', + 'description', + 'url', + ]; + foreach ($fields as $field) { + $entity->$field = $request->get($field); + } + if (strlen($entity->duration) == 0) + $entity->duration = null; + $nextdate = $request->get('nextdate'); + $nextdate = new \DateTime($nextdate); + $entity->nextdate = $nextdate; + + } + + private function validateRepeatingEvent(RepeatingEvent $entity) + { + $fields = [ + 'nextdate', + 'repeating_pattern', + 'summary', + ]; + foreach ($fields as $field) { + if ((is_null($entity->$field)) && (strlen($entity->$field) > 0)) + return false; + } + return true; + } + + private function saveRepeatingEvent(Request $request, RepeatingEvent $entity) + { + $location = $request->get('location'); + $location_lat = $request->get('location_lat'); + $location_lon = $request->get('location_lon'); + if (strlen($location) > 0) { + // check if the location already exists + /** @var EntityManager $em */ + $em = $this->getDoctrine()->getManager(); + $repo = $em->getRepository('CalciferBundle:Location'); + $results = $repo->findBy(['name' => $location]); + if (count($results) > 0) { + $location_obj = $results[0]; + if (strlen($location_lat) > 0) { + $location_obj->lat = $location_lat; + } + if (strlen($location_lon) > 0) { + $location_obj->lon = $location_lon; + } + $em->persist($location_obj); + $em->flush(); + $entity->location = $results[0]; + } else { + $location_obj = new Location(); + $location_obj->name = $location; + if (strlen($location_lat) > 0) { + $location_obj->lat = $location_lat; + } + if (strlen($location_lon) > 0) { + $location_obj->lon = $location_lon; + } + $location_obj->slug = \URLify::filter($location_obj->name, 255, 'de'); + $em->persist($location_obj); + $em->flush(); + $entity->location = $location_obj; + } + } else { + $entity->location = null; + } + + $tags = $request->get('tags'); + if (strlen($tags) > 0) { + $tags = explode(',', $tags); + $em = $this->getDoctrine()->getManager(); + $repo = $em->getRepository('CalciferBundle:Tag'); + $entity->clearTags(); + foreach ($tags as $tag) { + $tag = trim($tag); + $results = $repo->findBy(['name' => $tag]); + if (count($results) > 0) { + $entity->addTag($results[0]); + } else { + $tag_obj = new Tag(); + $tag_obj->name = $tag; + $tag_obj->slug = \URLify::filter($tag_obj->name, 255, 'de'); + $em->persist($tag_obj); + $em->flush(); + $entity->addTag($tag_obj); + } + } + } else { + $entity->clearTags(); + } + + $entity->slug = \URLify::filter($entity->summary,255,'de'); + + $em = $this->getDoctrine()->getManager(); + $em->persist($entity); + $em->flush(); + + return $entity; + + } +} diff --git a/src/Hackspace/Bundle/CalciferBundle/Resources/assets/js/repeating_events.js b/src/Hackspace/Bundle/CalciferBundle/Resources/assets/js/repeating_events.js new file mode 100755 index 0000000..3ffdf0e --- /dev/null +++ b/src/Hackspace/Bundle/CalciferBundle/Resources/assets/js/repeating_events.js @@ -0,0 +1,6 @@ +$(document).ready(function(){ + $('.ui.dropdown.selection') + .dropdown() + .dropdown('set value',$('.ui.dropdown.selection input[type=hidden]').val()) + ; +}); diff --git a/src/Hackspace/Bundle/CalciferBundle/Resources/views/RepeatingEvent/edit.html.twig b/src/Hackspace/Bundle/CalciferBundle/Resources/views/RepeatingEvent/edit.html.twig new file mode 100755 index 0000000..25f2f34 --- /dev/null +++ b/src/Hackspace/Bundle/CalciferBundle/Resources/views/RepeatingEvent/edit.html.twig @@ -0,0 +1,37 @@ +{% 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/repeating_events.js" + "@CalciferBundle/Resources/assets/js/events.js" + "@CalciferBundle/Resources/assets/js/leaflet.js" + %} + + {% endjavascripts %} +{% endblock %} + +{% block body -%} +
+
+

Wiederholenden Termin bearbeiten

+
+
+ +
+
+ {{ include('CalciferBundle:RepeatingEvent:repeating_event_form.html.twig',{'entity':entity}) }} +
+
+ +{% endblock %} diff --git a/src/Hackspace/Bundle/CalciferBundle/Resources/views/RepeatingEvent/index.html.twig b/src/Hackspace/Bundle/CalciferBundle/Resources/views/RepeatingEvent/index.html.twig new file mode 100755 index 0000000..ce108c5 --- /dev/null +++ b/src/Hackspace/Bundle/CalciferBundle/Resources/views/RepeatingEvent/index.html.twig @@ -0,0 +1,65 @@ +{% extends 'CalciferBundle::layout.html.twig' %} + +{% block css %} + {% stylesheets filter="compass" + "@CalciferBundle/Resources/assets/css/events.scss" %} + + {% endstylesheets %} +{% endblock %} + +{% block javascripts %} + {% javascripts + "@CalciferBundle/Resources/assets/js/events.js" %} + + {% endjavascripts %} +{% endblock %} + +{% block body -%} +
+
+

+ Wiederholende Termine +

+
+
+ +
+
+ + + + + + + + + + + {% for entity in entities %} + + + + + + + {% endfor %} + + + + + + +
ZusammenfassungNächstes DatumWiederholungsmusterAktionen
+ {{ entity.summary }} + + {{ entity.nextdate.format('Y-m-d H:i') }} + + {{ entity.getFormatedRepeatPattern() }} + + Bearbeiten +
Neuen wiederholenden Termin anlegen
+
+ +
+ +{% endblock %} diff --git a/src/Hackspace/Bundle/CalciferBundle/Resources/views/RepeatingEvent/new.html.twig b/src/Hackspace/Bundle/CalciferBundle/Resources/views/RepeatingEvent/new.html.twig new file mode 100755 index 0000000..22b9509 --- /dev/null +++ b/src/Hackspace/Bundle/CalciferBundle/Resources/views/RepeatingEvent/new.html.twig @@ -0,0 +1,35 @@ +{% 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/repeating_events.js" + "@CalciferBundle/Resources/assets/js/events.js" + "@CalciferBundle/Resources/assets/js/leaflet.js" %} + + {% endjavascripts %} +{% endblock %} + +{% block body -%} +
+
+

Wiederholenden Termin erstellen

+
+
+ +
+
+ {{ include('CalciferBundle:RepeatingEvent:repeating_event_form.html.twig') }} +
+
+ +{% endblock %} diff --git a/src/Hackspace/Bundle/CalciferBundle/Resources/views/RepeatingEvent/repeating_event_form.html.twig b/src/Hackspace/Bundle/CalciferBundle/Resources/views/RepeatingEvent/repeating_event_form.html.twig new file mode 100755 index 0000000..801665d --- /dev/null +++ b/src/Hackspace/Bundle/CalciferBundle/Resources/views/RepeatingEvent/repeating_event_form.html.twig @@ -0,0 +1,166 @@ +
+
+
+ + +
+ + + + +
+ +
+
+
+
+ + +
+ + +
+ Hier gibst du bitte die Dauer der Veranstaltung in Minuten an. +
+
+
+ +
+ + +
+ +
+ +
+ +
+ + +
+ + +
+ +
+
+
+ +
+ + +
+ + +
Du kannst hier Markdown + benutzen. +
+
+
+ +
+ + +
+ + +
+
+ +
+ + +
+ + + + + +
+ Du kannst zu diesem Ort auch Geokoordinaten hinterlegen.
+ {% if entity.location.lat|default(0) > 0 %}Folgende Koordinaten sind angegeben: lat:{{ entity.location.lat }}, lon:{{ entity.location.lon }}{% endif %} +
+ +
+
+ +
+ + +
+ + + +
Du kannst hier kommasepariert Tags angeben. +
+
+
+ + +
+ +
\ No newline at end of file diff --git a/src/Hackspace/Bundle/CalciferBundle/Resources/views/navigation.html.twig b/src/Hackspace/Bundle/CalciferBundle/Resources/views/navigation.html.twig index c2e4ce9..3991996 100755 --- a/src/Hackspace/Bundle/CalciferBundle/Resources/views/navigation.html.twig +++ b/src/Hackspace/Bundle/CalciferBundle/Resources/views/navigation.html.twig @@ -3,6 +3,7 @@
Calcifer
Neuer Termin
+
Wiederholende Termine
\ No newline at end of file