From 683e9ffdda664009476485445990fee19ce4e84d Mon Sep 17 00:00:00 2001 From: Cris Date: Wed, 24 Mar 2021 16:22:56 +0100 Subject: [PATCH] Modified to request recommendation (+send mails) ONLY if LV has lectors Modifications done for STGL Overview and Detailview Signed-off-by: cris-technikum --- .../anrechnung/ApproveAnrechnungDetail.php | 64 ++++++++++++------- .../ApproveAnrechnungUebersicht.php | 45 ++++++++----- application/libraries/AnrechnungLib.php | 22 ++++++- .../approveAnrechnungUebersicht.php | 1 + .../anrechnung/approveAnrechnungUebersicht.js | 21 ++++-- system/phrasesupdate.php | 20 ++++++ 6 files changed, 125 insertions(+), 48 deletions(-) diff --git a/application/controllers/lehre/anrechnung/ApproveAnrechnungDetail.php b/application/controllers/lehre/anrechnung/ApproveAnrechnungDetail.php index 8fed40f48..bbaab393b 100644 --- a/application/controllers/lehre/anrechnung/ApproveAnrechnungDetail.php +++ b/application/controllers/lehre/anrechnung/ApproveAnrechnungDetail.php @@ -241,13 +241,26 @@ class approveAnrechnungDetail extends Auth_Controller $inProgressLektor = getUserLanguage() == 'German' ? $inProgressLektor->bezeichnung_mehrsprachig[0] : $inProgressLektor->bezeichnung_mehrsprachig[1]; - + + $retval = array(); + $counter = 0; + foreach ($data as $item) { - // Approve Anrechnung - if(getData($this->anrechnunglib->requestRecommendation($item['anrechnung_id']))) + // Check if Anrechnungs-LV has lector + if (!$this->anrechnunglib->LVhasLector($item['anrechnung_id'])) { - $json[]= array( + // Count up LV with no lector + $counter++; + + // Break, if LV has no lector + break; + } + + // Request Recommendation + if($this->anrechnunglib->requestRecommendation($item['anrechnung_id'])) + { + $retval[]= array( 'anrechnung_id' => $item['anrechnung_id'], 'status_kurzbz' => self::ANRECHNUNGSTATUS_PROGRESSED_BY_LEKTOR, 'status_bezeichnung' => $inProgressLektor, @@ -256,26 +269,29 @@ class approveAnrechnungDetail extends Auth_Controller ); } } - + + /** + * Send mails to lectors + * NOTE: mails are sent at the end to ensure sending only ONE mail to each LV-Leitung or lector + * even if they are required for more recommendations + * */ + if (!isEmptyArray($retval)) + { + self::_sendSanchoMailToLectors($retval); + + // Output json to ajax + return $this->outputJsonSuccess($retval); + } + // Output json to ajax - if (isset($json) && !isEmptyArray($json)) + if (isEmptyArray($retval) && $counter > 0) { - /** - * Send mails to lectors - * NOTE: mails are sent at the end to ensure sending only ONE mail to each LV-Leitung or lector - * even if they are required for more recommendations - * */ - if (!$this->_sendSanchoMailToLectors($json)) - { - show_error('Failed sending emails'); - } - - return $this->outputJsonSuccess($json); - } - else - { - return $this->outputJsonError('Es wurden keine Empfehlungen angefordert'); + return $this->outputJsonError( + "Empfehlung wurde nicht angefordert,\nDer LV sind keine LektorInnen zugeteilt." + ); } + + return $this->outputJsonError('Es wurden keine Empfehlungen angefordert'); } /** @@ -575,8 +591,8 @@ class approveAnrechnungDetail extends Auth_Controller } /** - * Get lectors (prio for LV-Leitung, if not present to all lectors of LV. - * Anyway this function will receive a unique array to avoid sending more mails to one and the same lector. + * Get unique array of LV lectors. + * Only get LV Leitung if present, otherwise all lectors of LV. * @param $anrechnung_arr * @return array */ @@ -620,7 +636,7 @@ class approveAnrechnungDetail extends Auth_Controller unset($lector->lvleiter); } - // Now make the lector array aka mail receivers unique + // Make the lector array unique $lector_arr = array_unique($lector_arr, SORT_REGULAR); return $lector_arr; diff --git a/application/controllers/lehre/anrechnung/ApproveAnrechnungUebersicht.php b/application/controllers/lehre/anrechnung/ApproveAnrechnungUebersicht.php index 21da93df8..1321c2c19 100644 --- a/application/controllers/lehre/anrechnung/ApproveAnrechnungUebersicht.php +++ b/application/controllers/lehre/anrechnung/ApproveAnrechnungUebersicht.php @@ -206,12 +206,25 @@ class approveAnrechnungUebersicht extends Auth_Controller ? $inProgressLektor->bezeichnung_mehrsprachig[0] : $inProgressLektor->bezeichnung_mehrsprachig[1]; + $retval = array(); + $counter = 0; + foreach ($data as $item) { - // Approve Anrechnung - if(getData($this->anrechnunglib->requestRecommendation($item['anrechnung_id']))) + // Check if Anrechnungs-LV has lector + if (!$this->anrechnunglib->LVhasLector($item['anrechnung_id'])) { - $json[]= array( + // Count up LV with no lector + $counter++; + + // Continue loop, if LV has no lector + continue; + } + + // Request Recommendation + if($this->anrechnunglib->requestRecommendation($item['anrechnung_id'])) + { + $retval[]= array( 'anrechnung_id' => $item['anrechnung_id'], 'status_kurzbz' => self::ANRECHNUNGSTATUS_PROGRESSED_BY_LEKTOR, 'status_bezeichnung' => $inProgressLektor, @@ -220,25 +233,23 @@ class approveAnrechnungUebersicht extends Auth_Controller } } - // Output json to ajax - if (isset($json) && !isEmptyArray($json)) + /** + * Send mails to lectors + * NOTE: mails are sent at the end to ensure sending only ONE mail to each LV-Leitung or lector + * even if they are required for more recommendations + * */ + if (!isEmptyArray($retval)) { - /** - * Send mails to lectors - * NOTE: mails are sent at the end to ensure sending only ONE mail to each LV-Leitung or lector - * even if they are required for more recommendations - * */ - if (!$this->_sendSanchoMailToLectors($json)) - { - show_error('Failed sending emails'); - } - - return $this->outputJsonSuccess($json); + self::_sendSanchoMailToLectors($retval); } - else + + // Output json to ajax + if (isEmptyArray($retval) && $counter == 0) { return $this->outputJsonError('Es wurden keine Empfehlungen angefordert'); } + + return $this->outputJsonSuccess($retval); } /** diff --git a/application/libraries/AnrechnungLib.php b/application/libraries/AnrechnungLib.php index d873d7828..295426b86 100644 --- a/application/libraries/AnrechnungLib.php +++ b/application/libraries/AnrechnungLib.php @@ -464,7 +464,7 @@ class AnrechnungLib || $status_kurzbz == self::ANRECHNUNGSTATUS_REJECTED || $status_kurzbz == self::ANRECHNUNGSTATUS_PROGRESSED_BY_LEKTOR) { - return success(false); // dont ask for recommendation + return false; // dont ask for recommendation } // Start DB transaction @@ -494,7 +494,7 @@ class AnrechnungLib return error($result->msg, EXIT_ERROR); } - return success(true); // recommended + return true; // recommended } /** @@ -639,6 +639,24 @@ class AnrechnungLib // Return filename return 'Anrechnungsantrag'. $orgform_kurzbz .'_LV-'. $lehrveranstaltung_id. '_'. $fullname; } + + public function LVhasLector($anrechnung_id) + { + $result = $this->ci->AnrechnungModel->load($anrechnung_id); + if (!hasData($result)) + { + showError('Anrechnung existiert nicht'); + } + + // Get lectors of lehrveranstaltung + $result = $this->ci->LehrveranstaltungModel->getLecturersByLv( + $result->retval[0]->studiensemester_kurzbz, + $result->retval[0]->lehrveranstaltung_id + ); + + // Continue, if LV has no lector (there is no one to ask for recommendation) + return hasData($result) ? true : false; + } // Return an object with Anrechnungdata private function _setAnrechnungDataObject($anrechnung) diff --git a/application/views/lehre/anrechnung/approveAnrechnungUebersicht.php b/application/views/lehre/anrechnung/approveAnrechnungUebersicht.php index 7ec175384..1c88fc643 100644 --- a/application/views/lehre/anrechnung/approveAnrechnungUebersicht.php +++ b/application/views/lehre/anrechnung/approveAnrechnungUebersicht.php @@ -43,6 +43,7 @@ $this->load->view( 'bitteMindEinenAntragWaehlen', 'bitteBegruendungAngeben', 'empfehlungWurdeAngefordert', + 'empfehlungWurdeAngefordertAusnahmeWoKeineLektoren', 'anrechnungenWurdenGenehmigt', 'anrechnungenWurdenAbgelehnt' ), diff --git a/public/js/lehre/anrechnung/approveAnrechnungUebersicht.js b/public/js/lehre/anrechnung/approveAnrechnungUebersicht.js index 6e4474026..7f777178d 100644 --- a/public/js/lehre/anrechnung/approveAnrechnungUebersicht.js +++ b/public/js/lehre/anrechnung/approveAnrechnungUebersicht.js @@ -426,12 +426,23 @@ $(function(){ if (!data.error && data.retval != null) { - // Update status 'genehmigt' - $('#tableWidgetTabulator').tabulator('updateData', data.retval); - - // Print success message - FHC_DialogLib.alertSuccess(FHC_PhrasesLib.t("ui", "empfehlungWurdeAngefordert")); + // Print info message, if not all selected recommendations were requested + if (data.retval.length < selected_data.length){ + FHC_DialogLib.alertInfo( + FHC_PhrasesLib.t( + "ui", "empfehlungWurdeAngefordertAusnahmeWoKeineLektoren", + [selected_data.length, data.retval.length, selected_data.length - data.retval.length]) + ); + } + else + { + // Print success message + FHC_DialogLib.alertSuccess(FHC_PhrasesLib.t("ui", "empfehlungWurdeAngefordert")); + } } + + //Update status 'genehmigt' + $('#tableWidgetTabulator').tabulator('updateData', data.retval); }, errorCallback: function (jqXHR, textStatus, errorThrown) { diff --git a/system/phrasesupdate.php b/system/phrasesupdate.php index 89c31cfaa..589e4ac7e 100644 --- a/system/phrasesupdate.php +++ b/system/phrasesupdate.php @@ -10210,6 +10210,26 @@ array( ) ) ), + array( + 'app' => 'core', + 'category' => 'ui', + 'phrase' => 'empfehlungWurdeAngefordertAusnahmeWoKeineLektoren', + 'insertvon' => 'system', + 'phrases' => array( + array( + 'sprache' => 'German', + 'text' => "Empfehlungsanfragen: {0}
Abgeschickt: {1}
Nicht abgeschickt: {2}
Grund: Keine Lektoren zu LV zugeteilt.", + 'description' => '', + 'insertvon' => 'system' + ), + array( + 'sprache' => 'English', + 'text' => "Requests for recommendation: {0}
Sent: {1}
Not sent: {2}
Reason: No lectors assigned to the course yet.", + 'description' => '', + 'insertvon' => 'system' + ) + ) + ), array( 'app' => 'core', 'category' => 'ui',