): Response {
$post = $request->getParsedBody();
+ $error_detected = [];
+ $msg = null;
+
switch ($class) {
case 'status':
$entitled = new Status($this->zdb);
$label = trim($post[$entitled::$fields['libelle']]);
$field = (int)trim($post[$entitled::$fields['third']] ?? 0);
- $ret = ($action === 'add' ? $entitled->add($label, $field) : $entitled->update($id, $label, $field));
+ if ($label != '') {
+ $ret = ($action === 'add' ? $entitled->add($label, $field) : $entitled->update($id, $label, $field));
+ } else {
+ $ret = false;
+ $error_detected[] = _T('Missing required %type name!');
+ }
+ $redirect_uri = $this->routeparser->urlFor('entitleds', ['class' => $class]);
if ($ret !== true) {
- $msg_type = 'error_detected';
- $msg = $action === 'add' ?
+ $error_detected[] = $action === 'add' ?
_T("%type has not been added :(") : _T("%type #%id has not been updated");
+ if ($action === 'edit') {
+ $redirect_uri = $this->routeparser->urlFor('editEntitled', ['id' => $id, 'class' => $class]);
+ }
} else {
- $msg_type = 'success_detected';
$msg = $action === 'add' ?
_T("%type has been successfully added!") : _T("%type #%id has been successfully updated!");
}
- $this->flash->addMessage(
- $msg_type,
- str_replace(
- ['%type', '%id'],
- [$entitled->getI18nType(), $id],
- $msg
- )
- );
+ if (count($error_detected) > 0) {
+ foreach ($error_detected as $error) {
+ $this->flash->addMessage(
+ 'error_detected',
+ str_replace(
+ ['%type', '%id'],
+ [$entitled->getI18nType(), $id],
+ $error
+ )
+ );
+ }
+ } else {
+ $this->flash->addMessage(
+ 'success_detected',
+ str_replace(
+ ['%type', '%id'],
+ [$entitled->getI18nType(), $id],
+ $msg
+ )
+ );
+ }
return $response
->withStatus(301)
- ->withHeader(
- 'Location',
- $this->routeparser->urlFor(
- 'entitleds',
- ['class' => $class]
- )
- );
+ ->withHeader('Location', $redirect_uri);
}
->withHeader('Location', $this->cancelUri($this->getArgs($request)));
}
+ $error_detected = [];
+ $msg = null;
+
$ptype = new PaymentType($this->zdb, $id);
$ptype->name = $post['name'];
- $res = $ptype->store();
+ if (isset($post['name']) && $post['name'] != '') {
+ $res = $ptype->store();
+ } else {
+ $res = false;
+ $error_detected[] = _T("Missing required payment type's name!");
+ }
$redirect_uri = $this->redirectUri($this->getArgs($request));
if (!$res) {
if ($id === null) {
- $this->flash->addMessage(
- 'error_detected',
- preg_replace(
- '(%s)',
- $ptype->getName(),
- _T("Payment type '%s' has not been added!")
- )
+ $error_detected[] = preg_replace(
+ '(%s)',
+ $ptype->getName(),
+ _T("Payment type '%s' has not been added!")
);
} else {
- $this->flash->addMessage(
- 'error_detected',
- preg_replace(
- '(%s)',
- $ptype->getName(),
- _T("Payment type '%s' has not been modified!")
- )
+ $error_detected[] = preg_replace(
+ '(%s)',
+ $ptype->getName(),
+ _T("Payment type '%s' has not been modified!")
);
//redirect to payment type edition
$redirect_uri = $this->routeparser->urlFor('editPaymentType', ['id' => $id]);
}
} else {
if ($id === null) {
- $this->flash->addMessage(
- 'success_detected',
- preg_replace(
- '(%s)',
- $ptype->getName(),
- _T("Payment type '%s' has been successfully added.")
- )
+ $error_detected[] = preg_replace(
+ '(%s)',
+ $ptype->getName(),
+ _T("Payment type '%s' has been successfully added.")
);
} else {
- $this->flash->addMessage(
- 'success_detected',
- preg_replace(
- '(%s)',
- $ptype->getName(),
- _T("Payment type '%s' has been successfully modified.")
- )
+ $msg = preg_replace(
+ '(%s)',
+ $ptype->getName(),
+ _T("Payment type '%s' has been successfully modified.")
);
}
}
}
}
+ if (count($error_detected) > 0) {
+ foreach ($error_detected as $error) {
+ $this->flash->addMessage(
+ 'error_detected',
+ $error
+ );
+ }
+ } else {
+ $this->flash->addMessage(
+ 'success_detected',
+ $msg
+ );
+ }
+
return $response
->withStatus(301)
->withHeader('Location', $redirect_uri);
->withHeader('Location', $this->cancelUri($this->getArgs($request)));
}
+ $error_detected = [];
+ $msg = null;
+
$title = new Title($id);
$title->short = $post['short_label'];
$title->long = $post['long_label'];
- $res = $title->store($this->zdb);
+ if ((isset($post['short_label']) && $post['short_label'] != '') && (isset($post['long_label']) && $post['long_label'] != '')) {
+ $res = $title->store($this->zdb);
+ } else {
+ $res = false;
+ $error_detected[] = _T("Missing required title's short or long form!");
+ }
$redirect_uri = $this->redirectUri($this->getArgs($request));
if (!$res) {
if ($id === null) {
- $this->flash->addMessage(
- 'error_detected',
- preg_replace(
- '(%s)',
- $title->short,
- _T("Title '%s' has not been added!")
- )
+ $error_detected[] = preg_replace(
+ '(%s)',
+ $title->short !== null ? $title->short : '',
+ _T("Title '%s' has not been added!")
);
} else {
- $this->flash->addMessage(
- 'error_detected',
- preg_replace(
- '(%s)',
- $title->short,
- _T("Title '%s' has not been modified!")
- )
+ $error_detected[] = preg_replace(
+ '(%s)',
+ $title->short !== null ? $title->short : '',
+ _T("Title '%s' has not been modified!")
);
$redirect_uri = $this->routeparser->urlFor('editTitle', ['id' => $id]);
}
} else {
if ($id === null) {
- $this->flash->addMessage(
- 'success_detected',
- preg_replace(
- '(%s)',
- $title->short,
- _T("Title '%s' has been successfully added.")
- )
+ $error_detected[] = preg_replace(
+ '(%s)',
+ $title->short,
+ _T("Title '%s' has been successfully added.")
);
} else {
+ $msg = preg_replace(
+ '(%s)',
+ $title->short,
+ _T("Title '%s' has been successfully modified.")
+ );
+ }
+ }
+
+ if (count($error_detected) > 0) {
+ foreach ($error_detected as $error) {
$this->flash->addMessage(
- 'success_detected',
- preg_replace(
- '(%s)',
- $title->short,
- _T("Title '%s' has been successfully modified.")
- )
+ 'error_detected',
+ $error
);
}
+ } else {
+ $this->flash->addMessage(
+ 'success_detected',
+ $msg
+ );
}
+
return $response
->withStatus(301)
->withHeader('Location', $redirect_uri);