Conflicts:
	composer.lock
This commit is contained in:
Tim Schumacher 2014-09-30 07:12:55 +02:00
commit 7c2c17c571
14 changed files with 452 additions and 63 deletions

0
composer.lock generated Executable file → Normal file
View file

View file

@ -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;

View file

@ -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 */

View file

@ -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)));
}
}

View file

@ -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);

View file

@ -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");

View file

@ -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() {

View file

@ -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)));
}
}

View file

@ -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;
}
}

View file

@ -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: '&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> 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');
}
});

View file

@ -1,6 +1,6 @@
<form method="post" action="{% if entity.id|default(0) > 0 %}{{ path('_update',{'slug':entity.slug}) }}{% else %}{{ path('_create') }}{% endif %}">
<div class="ui form segment">
<div class="field">
<div class="field{% if(errors|default('0') != 0) %} {% if('startdate' in errors|keys) %}error{% endif %}{% endif %}">
<label class="control-label required" for="event_startdate">Startdatum</label>
<div class="ui left labeled icon input">
@ -11,6 +11,9 @@
value="{{ entity.startdate.format('Y-m-d H:i')|default('') }}"
placeholder="{{ "now"|date('Y-m-d H:i') }}"
class="form-control">
{% if(errors|default('0') != 0) %} {% if('startdate' in errors|keys) %}
<div class="ui red pointing above ui label">{{ errors.startdate }}</div>
{% endif %}{% endif %}
<i class="icon calendar"></i>
@ -19,7 +22,7 @@
</div>
</div>
</div>
<div class="field">
<div class="field{% if(errors|default('0') != 0) %} {% if('enddate' in errors|keys) %}error{% endif %}{% endif %}">
<label class="control-label required" for="event_enddate">Enddatum</label>
<div class="ui left labeled icon input">
@ -30,10 +33,14 @@
placeholder="{{ "now"|date('Y-m-d H:i') }}"
class="form-control">
{% if(errors|default('0') != 0) %} {% if('enddate' in errors|keys) %}
<div class="ui red pointing above ui label">{{ errors.enddate }}</div>
{% endif %}{% endif %}
<i class="icon calendar"></i>
</div>
</div>
<div class="field">
<div class="field{% if(errors|default('0') != 0) %} {% if('summary' in errors|keys) %}error{% endif %}{% endif %}">
<label class="" for="event_summary">Zusammenfassung</label>
<div class="ui left labeled input">
@ -45,6 +52,10 @@
maxlength="255"
class="form-control">
{% if(errors|default('0') != 0) %} {% if('summary' in errors|keys) %}
<div class="ui red pointing above ui label">{{ errors.summary }}</div>
{% endif %}{% endif %}
<div class="ui corner label">
<i class="icon asterisk"></i>
</div>

View file

@ -3,6 +3,7 @@
{% block css %}
{% stylesheets filter="compass"
"@CalciferBundle/Resources/assets/css/events.scss"
"@CalciferBundle/Resources/assets/css/leaflet.scss"
%}
<link rel="stylesheet" href="{{ asset_url }}" />
{% endstylesheets %}
@ -11,6 +12,7 @@
{% block javascripts %}
{% javascripts
"@CalciferBundle/Resources/assets/js/events.js"
"@CalciferBundle/Resources/assets/js/leaflet.js"
%}
<script src="{{ asset_url }}"></script>
{% endjavascripts %}
@ -22,8 +24,47 @@
<h1>
Termine
{% if tag|default(false) %} für Tag „{{ tag.name }}{% endif %}
{% if location|default(false) %} für Ort „{{ location.name }}{% endif %}
{% if location|default(false) %} für Ort „{{ location.name }} <a class="location-edit" href="{{ path("location_edit",{slug:location.slug}) }}"><i class="ui icon edit inverted green circular link" data-content="Ort bearbeiten" title="Ort bearbeiten"></i> </a> {% endif %}
</h1>
{% if tag|default(false) %}
<a href="{{ path('tag_show',{'slug' : tag.slug }) }}.ics"><i class="icon calendar"></i>Link zur Kalenderdatei</a>
{% endif %}
{% if location|default(false) %}
{% if (location.description|length > 0) or location.hasAddress() %}
<div id="location-description" class="ui message green">
{% if (location.description|length > 0) %}
<p>{{ location.description|markdown }}</p>
{% endif %}
{% if (location.hasAddress()) %}
<div class="ui section divider"></div>
<p>
Anschrift:<br/>
{{ location.streetaddress }}{% if(location.streetnumber|length > 0) %} {{ location.streetnumber }}{% endif %}<br/>
{% if(location.zipcode|length > 0) %}{{ location.zipcode }} {% endif %}{{ location.city }}
</p>
{% endif %}
{% if ((location.lon > 0) and (location.lat > 0)) %}
<p><a href="" class="show_map">Auf einer OpenStreetMap-Karte anzeigen</a></p>
<div class="ui modal geo viewer">
<i class="close icon"></i>
<div class="header">
{{ location.name }}<br/>
{{ location.streetaddress }}{% if(location.streetnumber|length > 0) %} {{ location.streetnumber }}{% endif %}<br/>
{% if(location.zipcode|length > 0) %}{{ location.zipcode }} {% endif %}{{ location.city }}
</div>
<div class="content">
<div id="view-map" data-lat="{{ location.lat }}" data-lon="{{ location.lon }}"></div>
</div>
<div class="actions">
<div class="ui button ok">
Schließen
</div>
</div>
</div>
{% endif %}
</div>
{% endif %}
{% endif %}
</div>
</div>

View file

@ -1,34 +0,0 @@
{% 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" %}
<link rel="stylesheet" href="{{ asset_url }}"/>
{% endstylesheets %}
{% endblock %}
{% block javascripts %}
{% javascripts
"@CalciferBundle/Resources/assets/js/jquery.datetimepicker.js"
"@CalciferBundle/Resources/assets/js/events.js"
"@CalciferBundle/Resources/assets/js/leaflet.js" %}
<script src="{{ asset_url }}"></script>
{% endjavascripts %}
{% endblock %}
{% block body -%}
<div class="ui one column page grid">
<div class="ui column">
<h1>Termin bearbeiten</h1>
</div>
</div>
<div class="ui one column page grid">
<div class="ui column">
{{ include('CalciferBundle:Event:event_form.html.twig',{'entity':entity}) }}
</div>
</div>
{% endblock %}

View file

@ -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" %}
<link rel="stylesheet" href="{{ asset_url }}"/>
{% endstylesheets %}
{% endblock %}
{% block javascripts %}
{% javascripts
"@CalciferBundle/Resources/assets/js/jquery.datetimepicker.js"
"@CalciferBundle/Resources/assets/js/events.js"
"@CalciferBundle/Resources/assets/js/leaflet.js" %}
<script src="{{ asset_url }}"></script>
{% endjavascripts %}
{% endblock %}
{% block body -%}
<div class="ui one column page grid">
<div class="ui column">
<h1>Ort bearbeiten</h1>
</div>
</div>
<div class="ui one column page grid">
<div class="ui column">
<form method="post"
action="{{ path('location_update',{'slug':entity.slug}) }}">
<div class="ui form segment">
<div class="field">
<label class="" for="location-name">Name</label>
<div class="ui left labeled input">
<input type="text"
id="location-name"
name="name"
value="{{ entity.name|default('') }}"
required="required"
maxlength="255"
class="form-control">
<div class="ui corner label">
<i class="icon asterisk"></i>
</div>
</div>
</div>
<div class="field">
<label class="control-label required" for="location-description">Beschreibung</label>
<div class="ui left labeled icon input attached-label">
<textarea id="location-description" name="description">{{ entity.description|default('') }}</textarea>
<div class="ui bottom attached label">Du kannst hier <a
href="https://en.wikipedia.org/wiki/Markdown">Markdown</a> benutzen.
</div>
</div>
</div>
<div class="field">
<label class="" for="location-streetaddress">Straße</label>
<div class="ui left labeled input">
<input type="text"
id="location-streetaddress"
name="streetaddress"
value="{{ entity.streetaddress|default('') }}"
required="required"
maxlength="255"
class="form-control">
</div>
</div>
<div class="field">
<label class="" for="location-streetnumber">Hausnummer</label>
<div class="ui left labeled input">
<input type="text"
id="location-streetnumber"
name="streetnumber"
value="{{ entity.streetnumber|default('') }}"
required="required"
maxlength="255"
class="form-control">
</div>
</div>
<div class="field">
<label class="" for="location-zipcode">Postleitzahl</label>
<div class="ui left labeled input">
<input type="text"
id="location-zipcode"
name="zipcode"
value="{{ entity.zipcode|default('') }}"
required="required"
maxlength="255"
class="form-control">
</div>
</div>
<div class="field">
<label class="" for="location-city">Ort</label>
<div class="ui left labeled input">
<input type="text"
id="location-city"
name="city"
value="{{ entity.city|default('') }}"
required="required"
maxlength="255"
class="form-control">
</div>
</div>
<div class="field">
<label class="control-label required" for="location-geocords">Geokoordinaten</label>
<div class="ui left labeled icon input attached-{% if entity.location.lat|default(0) > 0 %}geo-{% endif %}label">
<input type="text"
id="location-geocords"
name="geocords"
maxlength="255"
value="{{ entity.lat|default('0') }},{{ entity.lon|default('0') }}"
class="form-control">
<i class="icon map marker"></i>
<div class="ui bottom attached label">
Gebe entweder Breitengrad und Längengrad (Mit Punkten!) kommasepariert ein oder <a href="#" class="add_geo">wähle einen Punkt auf der Karte aus</a>.
</div>
<div class="ui modal geo chooser">
<i class="close icon"></i>
<div class="header">
Wähle einen Punkt auf der Karte
</div>
<div class="content">
<div id="map"></div>
</div>
<div class="actions">
<div class="ui button cancel">
Cancel
</div>
<div class="ui button ok">
Okay
</div>
</div>
</div>
</div>
</div>
<input type="submit" class="ui button blue" value="Speichern"/>
</div>
</form>
</div>
</div>
{% endblock %}