diff --git a/src/Hackspace/Bundle/CalciferBundle/Controller/EventController.php b/src/Hackspace/Bundle/CalciferBundle/Controller/EventController.php index b999599..78bfb9e 100755 --- a/src/Hackspace/Bundle/CalciferBundle/Controller/EventController.php +++ b/src/Hackspace/Bundle/CalciferBundle/Controller/EventController.php @@ -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, ); } @@ -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'); @@ -267,7 +273,6 @@ class EventController extends Controller $entity->addTag($tag_obj); } } - return $em; } return $em; } 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/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 @@