From b9955c14a6620e2845561fae340ae531a34857f3 Mon Sep 17 00:00:00 2001 From: Cris Date: Tue, 13 Apr 2021 16:33:53 +0200 Subject: [PATCH] Minor code changes for better maintainance Signed-off-by: cris-technikum --- .../anrechnung/ApproveAnrechnungDetail.php | 18 +++++++----- .../ApproveAnrechnungUebersicht.php | 16 +++++----- application/libraries/AnrechnungLib.php | 29 ++++++++++++------- 3 files changed, 37 insertions(+), 26 deletions(-) diff --git a/application/controllers/lehre/anrechnung/ApproveAnrechnungDetail.php b/application/controllers/lehre/anrechnung/ApproveAnrechnungDetail.php index 62b01f371..ae685f301 100644 --- a/application/controllers/lehre/anrechnung/ApproveAnrechnungDetail.php +++ b/application/controllers/lehre/anrechnung/ApproveAnrechnungDetail.php @@ -114,7 +114,8 @@ class approveAnrechnungDetail extends Auth_Controller { $data = $this->input->post('data'); - if(isEmptyArray($data)) + // Validate data + if (isEmptyArray($data)) { return $this->outputJsonError('Fehler beim Übertragen der Daten.'); } @@ -124,11 +125,11 @@ class approveAnrechnungDetail extends Auth_Controller { show_error('Failed retrieving person data'); } - + + // Approve Anrechnung foreach ($data as $item) { - // Approve Anrechnung - if(getData($this->anrechnunglib->approveAnrechnung($item['anrechnung_id']))) + if ($this->anrechnunglib->approveAnrechnung($item['anrechnung_id'])) { $json[]= array( 'anrechnung_id' => $item['anrechnung_id'], @@ -158,7 +159,8 @@ class approveAnrechnungDetail extends Auth_Controller { $data = $this->input->post('data'); - if(isEmptyArray($data)) + // Validate data + if (isEmptyArray($data)) { return $this->outputJsonError('Fehler beim Übertragen der Daten.'); } @@ -168,11 +170,11 @@ class approveAnrechnungDetail extends Auth_Controller { show_error('Failed retrieving person data'); } - + + // Reject Anrechnung foreach ($data as $item) { - // Reject Anrechnung - if(getData($this->anrechnunglib->rejectAnrechnung($item['anrechnung_id'], $item['begruendung']))) + if ($this->anrechnunglib->rejectAnrechnung($item['anrechnung_id'], $item['begruendung'])) { $json[]= array( 'anrechnung_id' => $item['anrechnung_id'], diff --git a/application/controllers/lehre/anrechnung/ApproveAnrechnungUebersicht.php b/application/controllers/lehre/anrechnung/ApproveAnrechnungUebersicht.php index 3b5f8e8b3..d59d97514 100644 --- a/application/controllers/lehre/anrechnung/ApproveAnrechnungUebersicht.php +++ b/application/controllers/lehre/anrechnung/ApproveAnrechnungUebersicht.php @@ -92,15 +92,16 @@ class approveAnrechnungUebersicht extends Auth_Controller { $data = $this->input->post('data'); - if(isEmptyArray($data)) + // Validate data + if (isEmptyArray($data)) { return $this->outputJsonError('Fehler beim Übertragen der Daten.'); } - + + // Approve Anrechnung foreach ($data as $item) { - // Approve Anrechnung - if(getData($this->anrechnunglib->approveAnrechnung($item['anrechnung_id']))) + if ($this->anrechnunglib->approveAnrechnung($item['anrechnung_id'])) { $json[]= array( 'anrechnung_id' => $item['anrechnung_id'], @@ -128,15 +129,16 @@ class approveAnrechnungUebersicht extends Auth_Controller { $data = $this->input->post('data'); - if(isEmptyArray($data)) + // Validate data + if (isEmptyArray($data)) { return $this->outputJsonError('Fehler beim Übertragen der Daten.'); } + // Reject Anrechnung foreach ($data as $item) { - // Reject Anrechnung - if(getData($this->anrechnunglib->rejectAnrechnung($item['anrechnung_id'], $item['begruendung']))) + if ($this->anrechnunglib->rejectAnrechnung($item['anrechnung_id'], $item['begruendung'])) { $json[]= array( 'anrechnung_id' => $item['anrechnung_id'], diff --git a/application/libraries/AnrechnungLib.php b/application/libraries/AnrechnungLib.php index a4fd8690d..edc3d5ea2 100644 --- a/application/libraries/AnrechnungLib.php +++ b/application/libraries/AnrechnungLib.php @@ -420,7 +420,7 @@ class AnrechnungLib // Exit if already approved or rejected if ($status_kurzbz == self::ANRECHNUNGSTATUS_APPROVED || $status_kurzbz == self::ANRECHNUNGSTATUS_REJECTED) { - return success(false); // dont approve + return false; // dont approve } // Start DB transaction @@ -445,10 +445,10 @@ class AnrechnungLib if ($this->ci->db->trans_status() === false) { $this->ci->db->trans_rollback(); - return error($result->msg, EXIT_ERROR); + return false; } - return success(true); // approved + return true; // approved } /** @@ -469,16 +469,14 @@ class AnrechnungLib // Exit if already approved or rejected if ($status_kurzbz == self::ANRECHNUNGSTATUS_APPROVED || $status_kurzbz == self::ANRECHNUNGSTATUS_REJECTED) { - return success(false); // dont reject + return false; // dont reject } + + // Start DB transaction + $this->ci->db->trans_start(false); // Insert new status rejected - $result = $this->ci->AnrechnungModel->saveAnrechnungstatus($anrechnung_id, self::ANRECHNUNGSTATUS_REJECTED); - - if (isError($result)) - { - show_error(getError($result)); - } + $this->ci->AnrechnungModel->saveAnrechnungstatus($anrechnung_id, self::ANRECHNUNGSTATUS_REJECTED); // Add begruendung as notiz $this->ci->load->model('person/Notiz_model', 'NotizModel'); @@ -488,8 +486,17 @@ class AnrechnungLib $begruendung, getAuthUID() ); + + // Transaction complete + $this->ci->db->trans_complete(); + + if ($this->ci->db->trans_status() === false) + { + $this->ci->db->trans_rollback(); + return false; + } - return success(true); // rejected + return true; // rejected } /**