From ad1327cc01e3b9b76aeac5d45885835e6fbaa287 Mon Sep 17 00:00:00 2001 From: "holger.trampe" Date: Fri, 11 Jun 2021 14:32:35 +0200 Subject: [PATCH] Update usw. fertig --- appinfo/routes.php | 2 +- lib/Agency/AgencyManager.php | 13 +++++++------ lib/Controller/AgencyController.php | 14 ++++++-------- lib/Db/AgencyMapper.php | 11 +++++++++++ lib/Service/AgencyService.php | 9 +-------- src/views/AgencyData.vue | 10 ++++++++-- 6 files changed, 34 insertions(+), 25 deletions(-) diff --git a/appinfo/routes.php b/appinfo/routes.php index ebec753..7f9c32b 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -8,7 +8,7 @@ return [ # AGENCY //['name' => 'agency#show', 'url' => '/getagencydata', 'verb' => 'GET'], ['name' => 'agency#show', 'url' => '/getagencydata', 'verb' => 'GET'], - ['name' => 'agency#update', 'url' => '/update', 'verb' => 'PUT'], + ['name' => 'agency#updateagencydata', 'url' => '/updateagencydata', 'verb' => 'PUT'], # DEVELOPMENT ['name' => 'test#filetest', 'url' => '/filetest', 'verb' => 'GET'], ] diff --git a/lib/Agency/AgencyManager.php b/lib/Agency/AgencyManager.php index 048ca83..b3feb0d 100644 --- a/lib/Agency/AgencyManager.php +++ b/lib/Agency/AgencyManager.php @@ -33,7 +33,7 @@ class AgencyManager { } /** - * getAgencyIdByUser + * getAgencyByUser * * @param: * - $request @@ -42,15 +42,16 @@ class AgencyManager { * Return the Agency-ID by filtering the id from default agency-group, ex: agency_1 -> 1 (int) * */ - public function getAgencyIdByUser(IUserSession $userSession){ + public function getAgencyByUser(IUserSession $userSession){ $groups = $this->groupManager->getUserGroups($userSession->getUser()); $agency_group_id = ""; foreach($groups as $group){ - if(str_contains($group->getGId(), 'agency')){ - $agency_group_id = explode("_", strval($group->getGId()))[1]; + if(str_contains($group->getGId(), 'agencymaingroupid_')){ + $agency_group_id_array = explode("_", strval($group->getGId())); + $agency_group_id = $agency_group_id_array[0]."_".$agency_group_id_array[1]; } } - return intval($agency_group_id); + return $this->agencyMapper->getAgencyByGId($agency_group_id); + #return $agency_group_id; } - } \ No newline at end of file diff --git a/lib/Controller/AgencyController.php b/lib/Controller/AgencyController.php index 985dac7..8b5a995 100644 --- a/lib/Controller/AgencyController.php +++ b/lib/Controller/AgencyController.php @@ -44,10 +44,10 @@ class AgencyController extends Controller { * */ public function show() { - $id = $this->agencyManager->getAgencyIdByUser($this->userSession); - return $this->handleNotFound(function () use ($id) { - return $this->service->find($id); - }); + return $this->agencyManager->getAgencyByUser($this->userSession); + #return $this->handleNotFound(function () use ($id) { + # return $this->service->find($id); + #}); } /** @@ -72,14 +72,12 @@ class AgencyController extends Controller { /** * @NoAdminRequired * - * @param string $title */ - public function update(string $name = null, string $inhaber = null, string $street = null, string $plz = null, string $city = null, string $agencymail = null, string $phone = null) { + public function updateagencydata(string $name = null, string $inhaber = null, string $street = null, string $plz = null, string $city = null, string $agencymail = null, string $phone = null) { - $id = $this->agencyManager->getAgencyIdByUser($this->userSession); + $id = $this->agencyManager->getAgencyByUser($this->userSession)->getId(); return $this->handleNotFound(function () use ($id, $name, $inhaber, $street, $plz, $city, $agencymail, $phone) { - # TODO: ABfrage machen! return $this->service->update($id, $name, $inhaber, $street, $plz, $city, $agencymail, $phone); }); } diff --git a/lib/Db/AgencyMapper.php b/lib/Db/AgencyMapper.php index 1cbc7b8..6902a53 100644 --- a/lib/Db/AgencyMapper.php +++ b/lib/Db/AgencyMapper.php @@ -21,4 +21,15 @@ class AgencyMapper extends QBMapper { return $this->findEntity($qb); } + + public function getAgencyByGId(string $gid) { + $qb = $this->db->getQueryBuilder(); + $qb->select('*') + ->from($this->getTableName()) + ->where( + $qb->expr()->eq('agencygid', $qb->createNamedParameter($gid)) + ); + + return $this->findEntity($qb); + } } \ No newline at end of file diff --git a/lib/Service/AgencyService.php b/lib/Service/AgencyService.php index 937f2fa..9e57a8c 100644 --- a/lib/Service/AgencyService.php +++ b/lib/Service/AgencyService.php @@ -37,15 +37,8 @@ class AgencyService { } //Create an Agency - public function create(string $name = null, string $inhaber = null, string $street = null, string $plz = null, string $city = null, string $agencymail = null, string $phone = null, string $agencygid, string $agencydirid, string $standarddirid) { + public function create(string $agencygid, string $agencydirid, string $standarddirid) { $agency = new Agency(); - $agency->setName($name); - $agency->setInhaber($inhaber); - $agency->setStreet($street); - $agency->setPlz($plz); - $agency->setCity($city); - $agency->setAgencymail($agencymail); - $agency->setPhone($phone); $agency->setAgencygid($agencygid); $agency->setAgencydirid($agencydirid); $agency->setStandarddirid($standarddirid); diff --git a/src/views/AgencyData.vue b/src/views/AgencyData.vue index b5ec4e6..dd9da54 100644 --- a/src/views/AgencyData.vue +++ b/src/views/AgencyData.vue @@ -42,7 +42,12 @@ + type="text" + :validation="[ + ['required'], + ['max', 99999], + ['min', 10000] + ]" />