diff --git a/src/Hackspace/Bundle/CalciferBundle/Controller/RepeatingEventController.php b/src/Hackspace/Bundle/CalciferBundle/Controller/RepeatingEventController.php index 18b22e6..28b1341 100755 --- a/src/Hackspace/Bundle/CalciferBundle/Controller/RepeatingEventController.php +++ b/src/Hackspace/Bundle/CalciferBundle/Controller/RepeatingEventController.php @@ -75,7 +75,8 @@ class RepeatingEventController extends Controller { $entity = new RepeatingEvent(); $this->fillEntity($request, $entity); - if ($this->validateRepeatingEvent($entity)) { + $errors = $entity->isValid(); + if (count($errors) == 0) { $ret = $this->saveRepeatingEvent($request, $entity); if ($entity->id > 0) { return $this->redirect($this->generateUrl('repeating_event_show')); @@ -85,6 +86,7 @@ class RepeatingEventController extends Controller } return [ 'entity' => $entity, + 'errors' => $errors, ]; } @@ -139,7 +141,8 @@ class RepeatingEventController extends Controller } $this->fillEntity($request, $entity); - if ($this->validateRepeatingEvent($entity)) { + $errors = $entity->isValid(); + if (count($errors) == 0) { $ret = $this->saveRepeatingEvent($request, $entity); if ($entity->id > 0) { return $this->redirect($this->generateUrl('repeating_event_show')); @@ -149,6 +152,7 @@ class RepeatingEventController extends Controller } return [ 'entity' => $entity, + 'errors' => $errors, ]; } @@ -172,20 +176,6 @@ class RepeatingEventController extends Controller } - 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'); diff --git a/src/Hackspace/Bundle/CalciferBundle/Entity/RepeatingEvent.php b/src/Hackspace/Bundle/CalciferBundle/Entity/RepeatingEvent.php index a9ff31c..d2f867a 100755 --- a/src/Hackspace/Bundle/CalciferBundle/Entity/RepeatingEvent.php +++ b/src/Hackspace/Bundle/CalciferBundle/Entity/RepeatingEvent.php @@ -4,6 +4,7 @@ namespace Hackspace\Bundle\CalciferBundle\Entity; use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\PersistentCollection; +use enko\RelativeDateParser\RelativeDateParser; /** * RepeatEvent @@ -84,4 +85,25 @@ class RepeatingEvent extends BaseEntity * ) */ protected $tags = []; + + public function isValid() { + $errors = []; + if ((is_null($this->nextdate)) && (strlen($this->nextdate) > 0)) { + $errors['nextdate'] = "Bitte gebe einen nächsten Termin an."; + } + if ((is_null($this->repeating_pattern)) && (strlen($this->repeating_pattern) > 0)) { + $errors['repeating_pattern'] = "Bitte gebe ein gültiges Wiederholungsmuster an."; + } else { + $this->nextdate->setTimezone(new \DateTimeZone('Europe/Berlin')); + try { + $parser = new RelativeDateParser($this->repeating_pattern,$this->nextdate,'de'); + } catch (\Exception $e) { + $errors['repeating_pattern'] = "Bitte gebe ein gültiges Wiederholungsmuster an."; + } + } + if ((is_null($this->summary)) && (strlen($this->summary) > 0)) { + $errors['summary'] = "Bitte gebe eine Zusammenfassung an."; + } + return $errors; + } } \ No newline at end of file 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 index 0bd20f3..f258b28 100755 --- 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 @@ -1,6 +1,6 @@
-
+
@@ -11,7 +11,9 @@ value="{{ entity.nextdate.format('Y-m-d H:i')|default('') }}" placeholder="{{ "now"|date('d.m.Y H:00') }}" class="form-control"> - + {% if(errors|default('0') != 0) %} {% if('nextdate' in errors|keys) %} +
{{ errors.nextdate }}
+ {% endif %}{% endif %}
@@ -37,7 +39,7 @@
-
+
@@ -48,6 +50,9 @@ required="required" maxlength="255" class="form-control"> + {% if(errors|default('0') != 0) %} {% if('repeating_pattern' in errors|keys) %} +
{{ errors.repeating_pattern }}
+ {% endif %}{% endif %}
@@ -56,7 +61,7 @@
-
+
@@ -67,6 +72,9 @@ required="required" maxlength="255" class="form-control"> + {% if(errors|default('0') != 0) %} {% if('summary' in errors|keys) %} +
{{ errors.summary }}
+ {% endif %}{% endif %}