From 376aae7f88dc06ed2cbbfefe08f579a0611fe45b Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Sat, 15 Sep 2018 17:14:24 +0200 Subject: [PATCH] Further implementations after using the app --- Controller.php | 29 ++++++++++++++++------------ Theme/Backend/modules-create.tpl.php | 2 +- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/Controller.php b/Controller.php index 8ee50e4..33f4f27 100644 --- a/Controller.php +++ b/Controller.php @@ -22,6 +22,7 @@ use Modules\Admin\Models\AccountMapper; use phpOMS\Account\PermissionType; use phpOMS\Message\RequestAbstract; use phpOMS\Message\ResponseAbstract; +use phpOMS\Message\NotificationLevel; use phpOMS\Module\ModuleAbstract; use phpOMS\Module\WebInterface; use phpOMS\Views\View; @@ -236,7 +237,12 @@ final class Controller extends ModuleAbstract implements WebInterface $created[] = $profile->jsonSerialize(); } - $response->set($request->getUri()->__toString(), $created); + $response->set($request->getUri()->__toString(), [ + 'status' => NotificationLevel::OK, + 'title' => 'Profile(s)', + 'message' => 'Profile(s) successfully created.', + 'response' => $created + ]); } /** @@ -251,19 +257,18 @@ final class Controller extends ModuleAbstract implements WebInterface private function createProfilesFromRequest(RequestAbstract $request) : array { $profiles = []; - $accounts = \json_decode($request->getData('iaccount-idlist') ?? '[]', true); - - if ($accounts === false) { - return $profiles; - } - - if (\is_int($accounts)) { - $accounts = [$accounts]; - } + $accounts = $request->getDataList('iaccount-idlist'); foreach ($accounts as $account) { - $account = AccountMapper::get((int) $account); - $profiles[] = new Profile(AccountMapper::get((int) $account)); + $account = (int) \trim($account); + $isInDb = ProfileMapper::getFor($account, 'account'); + + if ($isInDb->getId() !== 0) { + $profiles[] = $isInDb; + continue; + } + + $profiles[] = new Profile(AccountMapper::get($account)); } return $profiles; diff --git a/Theme/Backend/modules-create.tpl.php b/Theme/Backend/modules-create.tpl.php index 38e0859..3e35732 100644 --- a/Theme/Backend/modules-create.tpl.php +++ b/Theme/Backend/modules-create.tpl.php @@ -4,7 +4,7 @@ echo $this->getData('nav')->render(); ?>
-
+

getHtml('CreateProfile'); ?>