diff --git a/composer.lock b/composer.lock old mode 100755 new mode 100644 diff --git a/src/Hackspace/Bundle/CalciferBundle/Command/GenerateEventsCommand.php b/src/Hackspace/Bundle/CalciferBundle/Command/GenerateEventsCommand.php index d16fda5..c74573a 100755 --- a/src/Hackspace/Bundle/CalciferBundle/Command/GenerateEventsCommand.php +++ b/src/Hackspace/Bundle/CalciferBundle/Command/GenerateEventsCommand.php @@ -60,7 +60,7 @@ class GenerateEventsCommand extends ContainerAwareCommand /** @var \DateTime $enddate */ $enddate = clone $next_date; $enddate->add($duration); - $entity->enddate = $enddate; + $event->enddate = $enddate; } $event->summary = $entity->summary; $event->description = $entity->description; diff --git a/src/Hackspace/Bundle/CalciferBundle/Controller/EventController.php b/src/Hackspace/Bundle/CalciferBundle/Controller/EventController.php index 9792d4c..876fecd 100755 --- a/src/Hackspace/Bundle/CalciferBundle/Controller/EventController.php +++ b/src/Hackspace/Bundle/CalciferBundle/Controller/EventController.php @@ -54,7 +54,7 @@ class EventController extends Controller * * @Route("/termine/", name="_create") * @Method("POST") - * @Template("CalciferBundle:Event:new.html.twig") + * @Template("CalciferBundle:Event:edit.html.twig") */ public function createAction(Request $request) { @@ -63,7 +63,8 @@ class EventController extends Controller $em = $this->saveEvent($request, $entity); - if ($entity->isValid()) { + $errors = $entity->isValid(); + if ($errors === true) { $em = $this->getDoctrine()->getManager(); $em->persist($entity); $em->flush(); @@ -73,6 +74,7 @@ class EventController extends Controller return array( 'entity' => $entity, + 'errors' => $errors, ); } @@ -81,7 +83,7 @@ class EventController extends Controller * * @Route("/termine/neu", name="_new") * @Method("GET") - * @Template() + * @Template("CalciferBundle:Event:edit.html.twig") */ public function newAction() { @@ -171,7 +173,8 @@ class EventController extends Controller $em = $this->saveEvent($request, $entity); - if ($entity->isValid()) { + $errors = $entity->isValid(); + if ($errors === true) { $em = $this->getDoctrine()->getManager(); $em->persist($entity); $em->flush(); @@ -180,7 +183,8 @@ class EventController extends Controller } return array( - 'entity' => $entity, + 'entity' => $entity, + 'errors' => $errors, ); } @@ -199,8 +203,10 @@ class EventController extends Controller $entity->summary = $request->get('summary'); $entity->url = $request->get('url'); $startdate = $request->get('startdate'); - $startdate = new \DateTime($startdate); - $entity->startdate = $startdate; + if (strlen($startdate) > 0) { + $startdate = new \DateTime($startdate); + $entity->startdate = $startdate; + } $entity->slug = $entity->generateSlug($entity->summary,$em); $enddate = $request->get('enddate'); @@ -240,7 +246,7 @@ class EventController extends Controller if (strlen($location_lon) > 0) { $location_obj->lon = $location_lon; } - $location_obj->slug = $location_obj->generateSlug($location->name,$em); + $location_obj->slug = $location_obj->generateSlug($location_obj->name,$em); $em->persist($location_obj); $em->flush(); $entity->setLocation($location_obj); @@ -267,7 +273,6 @@ class EventController extends Controller $entity->addTag($tag_obj); } } - return $em; } return $em; } @@ -314,7 +319,7 @@ class EventController extends Controller * * @Route("/termine/{slug}/kopieren", name="_copy") * @Method("GET") - * @Template("CalciferBundle:Event:new.html.twig") + * @Template("CalciferBundle:Event:edit.html.twig") */ public function copyAction(Request $request, $slug) { /** @var EntityManager $em */ diff --git a/src/Hackspace/Bundle/CalciferBundle/Controller/LocationController.php b/src/Hackspace/Bundle/CalciferBundle/Controller/LocationController.php index 631892a..fc07a8c 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,74 @@ 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'); + $location->description = $request->get('description'); + + $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/Controller/TagController.php b/src/Hackspace/Bundle/CalciferBundle/Controller/TagController.php index dfb63f5..1d0c43b 100755 --- a/src/Hackspace/Bundle/CalciferBundle/Controller/TagController.php +++ b/src/Hackspace/Bundle/CalciferBundle/Controller/TagController.php @@ -71,6 +71,7 @@ class TagController extends Controller if ($format == 'ics') { $calendar = new Calendar(); $calendar->setProdId('-//My Company//Cool Calendar App//EN'); + $calendar->setTimeZone(new \DateTimeZone('Europe/Berlin')); foreach ($entities as $entity) { /** @var Event $entity */ @@ -81,6 +82,7 @@ class TagController extends Controller $event->setSummary($entity->summary); $event->setDescription($entity->description); $event->setUrl($entity->url); + $event->setUid($entity->slug); if ($entity->location instanceof Location) { $location = new \Jsvrcek\ICS\Model\Description\Location(); $location->setName($entity->location->name); diff --git a/src/Hackspace/Bundle/CalciferBundle/Entity/BaseEntity.php b/src/Hackspace/Bundle/CalciferBundle/Entity/BaseEntity.php index a33a608..ba972ee 100755 --- a/src/Hackspace/Bundle/CalciferBundle/Entity/BaseEntity.php +++ b/src/Hackspace/Bundle/CalciferBundle/Entity/BaseEntity.php @@ -56,7 +56,11 @@ abstract class BaseEntity { public function __set($name,$value) { if (property_exists($this,$name)) { - $this->$name = $value; + if ($value == '') { + $this->$name = null; + } else { + $this->$name = $value; + } return $this; } else { throw new \Exception("Property {$name} does not Exists"); diff --git a/src/Hackspace/Bundle/CalciferBundle/Entity/Event.php b/src/Hackspace/Bundle/CalciferBundle/Entity/Event.php index 8a3a791..68104d4 100755 --- a/src/Hackspace/Bundle/CalciferBundle/Entity/Event.php +++ b/src/Hackspace/Bundle/CalciferBundle/Entity/Event.php @@ -3,6 +3,7 @@ namespace Hackspace\Bundle\CalciferBundle\Entity; use Doctrine\ORM\Mapping as ORM; +use Symfony\Component\Validator\Constraints\DateTime; /** * Event @@ -102,7 +103,18 @@ class Event extends BaseEntity } public function isValid() { - return true; + $errors = []; + if (!($this->startdate instanceof \DateTime)) { + $errors['startdate'] = 'Bitte gebe ein Startdatum ein.'; + } + if ((!is_null($this->startdate)) && (!is_null($this->enddate)) && ($this->enddate < $this->startdate)) { + $errors['enddate'] = 'Bitte setze ein Enddatum das nach dem Startdatum ist.'; + } + if (strlen($this->summary) == 0) { + $errors['summary'] = 'Bitte gebe eine Zusammenfassung an.'; + } + + return (count($errors) > 0) ? $errors : true; } public function getFormatedDate() { diff --git a/src/Hackspace/Bundle/CalciferBundle/Entity/Location.php b/src/Hackspace/Bundle/CalciferBundle/Entity/Location.php index afd6feb..477d42f 100755 --- a/src/Hackspace/Bundle/CalciferBundle/Entity/Location.php +++ b/src/Hackspace/Bundle/CalciferBundle/Entity/Location.php @@ -8,8 +8,13 @@ use Doctrine\ORM\Mapping as ORM; * Location * * @property string $name + * @property string $description * @property float $lon * @property float $lat + * @property string $streetaddress + * @property string $streetnumber + * @property string $zipcode; + * @property string $city * * @ORM\Table(name="locations") * @ORM\Entity @@ -23,6 +28,41 @@ class Location extends BaseEntity */ protected $name; + /** + * @var string + * + * @ORM\Column(name="description", type="text", nullable=true) + */ + protected $description; + + /** + * @var string + * + * @ORM\Column(name="streetaddress", type="string", length=255, nullable=true) + */ + protected $streetaddress; + + /** + * @var string + * + * @ORM\Column(name="streetnumber", type="string", length=255, nullable=true) + */ + protected $streetnumber; + + /** + * @var string + * + * @ORM\Column(name="zipcode", type="string", length=255, nullable=true) + */ + protected $zipcode; + + /** + * @var string + * + * @ORM\Column(name="city", type="string", length=255, nullable=true) + */ + protected $city; + /** * @var float * @@ -37,5 +77,9 @@ class Location extends BaseEntity */ protected $lat; + public function hasAddress() { + return ((strlen($this->streetaddress) > 0) && (strlen($this->city))); + } + } diff --git a/src/Hackspace/Bundle/CalciferBundle/Resources/assets/css/events.scss b/src/Hackspace/Bundle/CalciferBundle/Resources/assets/css/events.scss index 6b615cb..7e0730a 100755 --- a/src/Hackspace/Bundle/CalciferBundle/Resources/assets/css/events.scss +++ b/src/Hackspace/Bundle/CalciferBundle/Resources/assets/css/events.scss @@ -42,6 +42,22 @@ form .ui.form { } } -#map { +#view-map, #map { height: 20rem; +} + +.location-edit { + text-decoration: none; +} + +#location-description { + p { + margin-top: 0.5rem; + margin-bottom: 0.5rem; + } + + .ui.section.divider { + margin-top: 0; + margin-bottom: 0; + } } \ No newline at end of file diff --git a/src/Hackspace/Bundle/CalciferBundle/Resources/assets/js/events.js b/src/Hackspace/Bundle/CalciferBundle/Resources/assets/js/events.js index b7a1dcc..c4dddbd 100755 --- a/src/Hackspace/Bundle/CalciferBundle/Resources/assets/js/events.js +++ b/src/Hackspace/Bundle/CalciferBundle/Resources/assets/js/events.js @@ -46,18 +46,30 @@ jQuery(document).ready(function () { closable: false, onApprove: function () { var coords = marker.getLatLng(); - jQuery('input[name=location_lat]').val(coords.lat); - jQuery('input[name=location_lon]').val(coords.lng); - jQuery('input[name=location]').css('margin-bottom', '3.2rem'); - jQuery('span.coords').text('Folgende Koordinaten sind angegeben: lat:' + coords.lat + ', lon:' + coords.lng); + if (!(jQuery('input[name=location_lat]').val() == undefined)) { + jQuery('input[name=location_lat]').val(coords.lat); + jQuery('input[name=location_lon]').val(coords.lng); + jQuery('input[name=location]').css('margin-bottom', '3.2rem'); + jQuery('span.coords').text('Folgende Koordinaten sind angegeben: lat:' + coords.lat + ', lon:' + coords.lng); + } else { + jQuery('input[name=geocords]').val(coords.lat + ',' + coords.lng); + } }, onDeny: function () { }, onVisible: function () { map.invalidateSize(true); - var lat = parseFloat(jQuery('input[name=location_lat]').val()); - var lon = parseFloat(jQuery('input[name=location_lon]').val()); + var lat = 0; + var lon = 0; + if (!(jQuery('input[name=location_lat]').val() == undefined)) { + lat = parseFloat(jQuery('input[name=location_lat]').val()); + lon = parseFloat(jQuery('input[name=location_lon]').val()); + } else { + var latlon = jQuery('input[name=geocords]').val(); + lat = latlon.split(',')[0]; + lon = latlon.split(',')[1]; + } if ((lat > 0) && (lon > 0)) { map.setView([lat, lon], 16); var latlng = new L.LatLng(lat, lon); @@ -70,3 +82,43 @@ jQuery(document).ready(function () { }).modal('attach events', '.add_geo', 'show'); } }); + +$(document).ready(function() { + + if (jQuery('#view-map').length == 1) { + jQuery('.show_map').click(addGeoCoordinates); + map = L.map('view-map'); + + // add an OpenStreetMap tile layer + L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', { + attribution: '© OpenStreetMap contributors' + }).addTo(map); + + map.setView([51.505, -0.09], 0); + + L.Icon.Default.imagePath = '/css/images'; + var popup = L.popup(); + + var marker = L.marker(); + + jQuery('.geo.viewer').modal('setting', { + closable: true, + onDeny: function () { + + }, + onVisible: function () { + map.invalidateSize(true); + var lat = $('#view-map').data('lat'); + var lon = $('#view-map').data('lon'); + if ((lat > 0) && (lon > 0)) { + map.setView([lat, lon], 16); + var latlng = new L.LatLng(lat, lon); + marker.setLatLng(latlng); + marker.addTo(map); + } else { + map.locate({setView: true}); + } + } + }).modal('attach events', '.show_map', 'show'); + } +}); \ No newline at end of file diff --git a/src/Hackspace/Bundle/CalciferBundle/Resources/views/Event/event_form.html.twig b/src/Hackspace/Bundle/CalciferBundle/Resources/views/Event/event_form.html.twig index d2f1e82..39ac995 100755 --- a/src/Hackspace/Bundle/CalciferBundle/Resources/views/Event/event_form.html.twig +++ b/src/Hackspace/Bundle/CalciferBundle/Resources/views/Event/event_form.html.twig @@ -1,6 +1,6 @@