Add validation for repeating events.

Ticket #43
This commit is contained in:
Tim Schumacher 2015-05-09 19:43:03 +02:00
parent 6f5ca2d29a
commit 60de4df4e6
3 changed files with 40 additions and 20 deletions

View file

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