From 7d0ff4fceedcb66311a60258628f79bff440ee9d Mon Sep 17 00:00:00 2001 From: Cris Date: Tue, 26 Jan 2021 10:58:26 +0100 Subject: [PATCH] Added check, when STGL tries to request recommendation for already recommended Antraege Signed-off-by: cris-technikum --- .../ApproveAnrechnungUebersicht.php | 3 ++- application/libraries/AnrechnungLib.php | 27 ++++++++++++++++--- .../approveAnrechnungUebersicht.php | 3 ++- .../anrechnung/approveAnrechnungUebersicht.js | 25 ++++++++++++----- system/phrasesupdate.php | 20 ++++++++++++++ 5 files changed, 66 insertions(+), 12 deletions(-) diff --git a/application/controllers/lehre/anrechnung/ApproveAnrechnungUebersicht.php b/application/controllers/lehre/anrechnung/ApproveAnrechnungUebersicht.php index 0f4354968..c7116baf8 100644 --- a/application/controllers/lehre/anrechnung/ApproveAnrechnungUebersicht.php +++ b/application/controllers/lehre/anrechnung/ApproveAnrechnungUebersicht.php @@ -202,7 +202,8 @@ class approveAnrechnungUebersicht extends Auth_Controller $json[]= array( 'anrechnung_id' => $item['anrechnung_id'], 'status_kurzbz' => self::ANRECHNUNGSTATUS_PROGRESSED_BY_LEKTOR, - 'status_bezeichnung' => $inProgressLektor + 'status_bezeichnung' => $inProgressLektor, + 'empfehlung_anrechnung' => null ); } } diff --git a/application/libraries/AnrechnungLib.php b/application/libraries/AnrechnungLib.php index 907116563..c77d49c93 100644 --- a/application/libraries/AnrechnungLib.php +++ b/application/libraries/AnrechnungLib.php @@ -284,15 +284,36 @@ class AnrechnungLib return success(false); // dont ask for recommendation } + // Start DB transaction + $this->ci->db->trans_start(false); + // Insert new status inProgressLektor $result = $this->ci->AnrechnungModel->saveAnrechnungstatus($anrechnung_id, self::ANRECHNUNGSTATUS_PROGRESSED_BY_LEKTOR); - if (isError($result)) + /** + * Anyway update empfehlung_anrechnung to be null + * Regardless of what empfehlung_anrechnung was already set (true/false/null), it should be (reset to ) null by + * requesting a (new) recommendation. + * **/ + $this->ci->AnrechnungModel->update( + $anrechnung_id, + array( + 'empfehlung_anrechnung' => null, + 'updateamum' => (new DateTime())->format('Y-m-d H:m:i'), + 'updatevon' => getAuthUID() + ) + ); + + // Transaction complete + $this->ci->db->trans_complete(); + + if ($this->ci->db->trans_status() === false) { - show_error(getError($result)); + $this->ci->db->trans_rollback(); + return error($result->msg, EXIT_ERROR); } - return success(true); // rejected + return success(true); // recommended } /** diff --git a/application/views/lehre/anrechnung/approveAnrechnungUebersicht.php b/application/views/lehre/anrechnung/approveAnrechnungUebersicht.php index 5771ff7dd..26a9291a6 100644 --- a/application/views/lehre/anrechnung/approveAnrechnungUebersicht.php +++ b/application/views/lehre/anrechnung/approveAnrechnungUebersicht.php @@ -17,7 +17,8 @@ $this->load->view( ), 'anrechnung' => array( 'nachweisdokumente', - 'empfehlung' + 'empfehlung', + 'confirmTextAntragHatBereitsEmpfehlung' ), 'ui' => array( 'anzeigen', diff --git a/public/js/lehre/anrechnung/approveAnrechnungUebersicht.js b/public/js/lehre/anrechnung/approveAnrechnungUebersicht.js index 861704b75..d8d73b0e4 100644 --- a/public/js/lehre/anrechnung/approveAnrechnungUebersicht.js +++ b/public/js/lehre/anrechnung/approveAnrechnungUebersicht.js @@ -281,13 +281,24 @@ $(function(){ // Request Recommendation for Anrechnungen $("#request-recommendation").click(function(){ // Get selected rows data - let selected_data = $('#tableWidgetTabulator').tabulator('getSelectedData') - .map(function(data){ - // reduce to necessary fields - return { - 'anrechnung_id' : data.anrechnung_id, - } - }); + let selected_data = $('#tableWidgetTabulator').tabulator('getSelectedData'); + + // If some of selected anrechnungen has already been recommended... + if (selected_data.some((data) => data.empfehlung_anrechnung !== null)) + { + // ...confirm before requesting recommendation + if(!confirm(FHC_PhrasesLib.t("anrechnung", "confirmTextAntragHatBereitsEmpfehlung"))) + { + return; + } + } + + selected_data.map(function(data){ + // reduce to necessary fields + return { + 'anrechnung_id' : data.anrechnung_id, + } + }); // Alert and exit if no anrechnung is selected if (selected_data.length == 0) diff --git a/system/phrasesupdate.php b/system/phrasesupdate.php index 9b9effd95..57306ef62 100644 --- a/system/phrasesupdate.php +++ b/system/phrasesupdate.php @@ -8688,6 +8688,26 @@ Any unusual occurrences 'insertvon' => 'system' ) ) + ), + array( + 'app' => 'core', + 'category' => 'anrechnung', + 'phrase' => 'confirmTextAntragHatBereitsEmpfehlung', + 'insertvon' => 'system', + 'phrases' => array( + array( + 'sprache' => 'German', + 'text' => "Mindestens 1 Antrag enthält bereits eine Empfehlung.\nWollen Sie wirklich für Ihre Auswahl eine Empfehlung anfordern und bereits vorhandene Empfehlungen dabei zurücksetzen?", + 'description' => '', + 'insertvon' => 'system' + ), + array( + 'sprache' => 'English', + 'text' => "At least one application was already recommended.\nDo you really want to request for recommendation for your selection?", + 'description' => '', + 'insertvon' => 'system' + ) + ) ) );