From 0c5af137dbf84ad79181b2303e1939ef528bcea7 Mon Sep 17 00:00:00 2001 From: Johann Hoffmann Date: Wed, 3 Dec 2025 16:49:49 +0100 Subject: [PATCH] WIP notifyBetreuerAboutNewOrChangedAbgabenForBetreuedProjektarbeiten Email Job; allowed abgabetypen & allowed noten as per config now via db primary key; new ProjektbetreuerModel method "getAllBetreuerOfProjektarbeit" to do just that; --- application/config/abgabe.php | 6 +- .../controllers/api/frontend/v1/Abgabe.php | 76 ++++++++++++++++++- .../controllers/jobs/AbgabetoolJob.php | 36 +++++++++ .../models/education/Projektarbeit_model.php | 12 +-- .../education/Projektbetreuer_model.php | 37 +++++++++ .../Cis/Abgabetool/AbgabeMitarbeiterDetail.js | 2 +- .../Cis/Abgabetool/AbgabeStudentDetail.js | 2 +- .../Cis/Abgabetool/AbgabetoolAssistenz.js | 2 +- .../Cis/Abgabetool/AbgabetoolMitarbeiter.js | 4 +- .../Cis/Abgabetool/AbgabetoolStudent.js | 2 +- 10 files changed, 159 insertions(+), 20 deletions(-) diff --git a/application/config/abgabe.php b/application/config/abgabe.php index b897e92e0..da77da22e 100644 --- a/application/config/abgabe.php +++ b/application/config/abgabe.php @@ -14,8 +14,10 @@ $config['URL_STUDENTS'] = 'cis.php/Cis/Abgabetool/Student'; $config['URL_MITARBEITER'] = 'index.ci.php/Cis/Abgabetool/Mitarbeiter'; // lehre.tbl_paabgabetyp bezeichnung -$config['ALLOWED_ABGABETYPEN_BETREUER'] = ['Zwischenabgabe', 'Quality Gate 1', 'Quality Gate 2']; -$config['ALLOWED_NOTEN_ABGABETOOL'] = ['Bestanden', 'Nicht bestanden']; +//$config['ALLOWED_ABGABETYPEN_BETREUER'] = ['Zwischenabgabe', 'Quality Gate 1', 'Quality Gate 2']; +$config['ALLOWED_ABGABETYPEN_BETREUER'] = ['zwischen', 'qualgate1', 'qualgate2']; // tbl_paabgabetyp pk +//$config['ALLOWED_NOTEN_ABGABETOOL'] = ['Bestanden', 'Nicht bestanden']; +$config['ALLOWED_NOTEN_ABGABETOOL'] = ['10', '14']; // tbl_note pk $config['beurteilung_link_fallback'] = 'addons/fhtw/content/projektbeurteilung/projektbeurteilungDocumentExport.php?projektarbeit_id=?&betreuerart_kurzbz=?&person_id=?'; diff --git a/application/controllers/api/frontend/v1/Abgabe.php b/application/controllers/api/frontend/v1/Abgabe.php index 8b6afef11..0b85e2370 100644 --- a/application/controllers/api/frontend/v1/Abgabe.php +++ b/application/controllers/api/frontend/v1/Abgabe.php @@ -44,7 +44,8 @@ class Abgabe extends FHCAPI_Controller 'getProjektarbeitenForStudiengang' =>array('basis/abgabe_assistenz:rw'), 'getStudiengaenge' => array('basis/abgabe_assistenz:rw'), 'getStudentProjektarbeitAbgabeFile' => array('basis/abgabe_student:rw', 'basis/abgabe_lektor:rw', 'basis/abgabe_assistenz:rw'), - 'postStudentProjektarbeitZusatzdaten' => array('basis/abgabe_lektor:rw', 'basis/abgabe_assistenz:rw') + 'postStudentProjektarbeitZusatzdaten' => array('basis/abgabe_lektor:rw', 'basis/abgabe_assistenz:rw'), + 'notifyBetreuerAboutChangedAbgaben' => self::PERM_LOGGED ]); $this->load->library('PhrasesLib'); @@ -1125,4 +1126,77 @@ class Abgabe extends FHCAPI_Controller } } + public function notifyBetreuerAboutChangedAbgaben() { + // $this->_ci->logInfo('Start job FHC-Core->notifyBetreuerAboutChangedAbgaben'); + + $this->_ci =& get_instance(); + $this->_ci->load->model('education/Projektarbeit_model', 'ProjektarbeitModel'); + $this->_ci->load->model('education/Projektbetreuer_model', 'ProjektbetreuerModel'); + $this->_ci->load->model('education/Paabgabe_model', 'PaabgabeModel'); + $this->_ci->load->model('crm/Student_model', 'StudentModel'); + + $interval = $this->_ci->config->item('PAABGABE_EMAIL_JOB_INTERVAL'); + + // get all new or changed termine in interval + $result = $this->_ci->PaabgabeModel->findAbgabenNewOrUpdatedSince($interval); + $retval = getData($result); + + if(count($retval) == 0) { + // $this->_ci->logInfo("Keine Emails an Betreuer über neue oder veränderte Termine versandt"); + return; + } + + $this->addMeta('retval', $retval); + + // group changed/new abgaben for projektarbeiten + $projektarbeiten = []; + foreach($retval as $newOrChangedAbgabe) { + + // Check if the current item has a 'projektarbeit_id' field. + // Replace 'projektarbeit_id' with the actual key name if it's different. + if (isset($newOrChangedAbgabe->projektarbeit_id)) { + $projektarbeitId = $newOrChangedAbgabe->projektarbeit_id; + + // If the 'projektarbeit_id' is not yet a key in $projektarbeiten, + // initialize it as an empty array. + if (!isset($projektarbeiten[$projektarbeitId])) { + $projektarbeiten[$projektarbeitId] = []; + } + + // Add the current row to the array associated with its 'projektarbeit_id'. + $projektarbeiten[$projektarbeitId][] = $newOrChangedAbgabe; + } + } + + // for each projektarbeit fetch their betreuer and save them in their own dictionary to avoid too many mails + $betreuer = []; + forEach($projektarbeiten as $projektarbeit_id => $abgaben) { + $betreuerResult = $this->_ci->ProjektbetreuerModel->getAllBetreuerOfProjektarbeit($projektarbeit_id); + +// $projektarbeiten[$projektarbeit_id]['betreuer'] = $betreuerResult; +// $projektarbeit->betreuer = $betreuerResult; + forEach($betreuerResult->retval as $betreuerRow) { + + } + if (isset($betreuerResult->projektarbeit_id)) { + $projektarbeitId = $newOrChangedAbgabe->projektarbeit_id; + + // If the 'projektarbeit_id' is not yet a key in $projektarbeiten, + // initialize it as an empty array. + if (!isset($projektarbeiten[$projektarbeitId])) { + $projektarbeiten[$projektarbeitId] = []; + } + + // Add the current row to the array associated with its 'projektarbeit_id'. + $projektarbeiten[$projektarbeitId][] = $newOrChangedAbgabe; + } + + } + $this->addMeta('$projektarbeiten', $projektarbeiten); +// $result = $this->_ci->PaabgabeModel->findNewOrChangedTermineByOtherUsersSince($interval); + + + // $this->_ci->logInfo('End job FHC-Core->notifyBetreuerAboutChangedAbgaben'); + } + } \ No newline at end of file diff --git a/application/controllers/jobs/AbgabetoolJob.php b/application/controllers/jobs/AbgabetoolJob.php index 84fe8f1a1..c3e879963 100644 --- a/application/controllers/jobs/AbgabetoolJob.php +++ b/application/controllers/jobs/AbgabetoolJob.php @@ -27,7 +27,43 @@ class AbgabetoolJob extends JOB_Controller } public function notifyBetreuerAboutChangedAbgaben() { + $this->_ci->logInfo('Start job FHC-Core->notifyBetreuerAboutChangedAbgaben'); + + $interval = $this->_ci->config->item('PAABGABE_EMAIL_JOB_INTERVAL'); + + // get all new or changed termine in interval + $result = $this->_ci->PaabgabeModel->findAbgabenNewOrUpdatedSince($interval); + $retval = getData($result); + + if(count($retval) == 0) { + $this->_ci->logInfo("Keine Emails an Betreuer über neue oder veränderte Termine versandt"); + return; + } + // group changed/new abgaben for projektarbeiten, then look up their betreuer and send them email + $projektarbeiten = []; + foreach($retval as $newOrChangedAbgabe) { + + // Check if the current item has a 'projektarbeit_id' field. + // Replace 'projektarbeit_id' with the actual key name if it's different. + if (isset($newOrChangedAbgabe['projektarbeit_id'])) { + $projektarbeitId = $newOrChangedAbgabe['projektarbeit_id']; + + // If the 'projektarbeit_id' is not yet a key in $projektarbeiten, + // initialize it as an empty array. + if (!isset($projektarbeiten[$projektarbeitId])) { + $projektarbeiten[$projektarbeitId] = []; + } + + // Add the current row to the array associated with its 'projektarbeit_id'. + $projektarbeiten[$projektarbeitId][] = $newOrChangedAbgabe; + } + + } + $result = $this->_ci->PaabgabeModel->findNewOrChangedTermineByOtherUsersSince($interval); + + + $this->_ci->logInfo('End job FHC-Core->notifyBetreuerAboutChangedAbgaben'); } public function notifyBetreuerMail() { diff --git a/application/models/education/Projektarbeit_model.php b/application/models/education/Projektarbeit_model.php index e1b800673..c595d7585 100644 --- a/application/models/education/Projektarbeit_model.php +++ b/application/models/education/Projektarbeit_model.php @@ -306,17 +306,7 @@ class Projektarbeit_model extends DB_Model return $this->execReadOnlyQuery($qry, array($projektarbeit_id)); } - - /** - * Prüft ob Projektarbeit aktuell ist (also zurzeit online bewertet wird). - * @param $projektarbeit_id - * @return boolean - */ - public function projektarbeitIsCurrent($projektarbeit_id) { - $version = $this->getVersion($projektarbeit_id); - // paarbeit sollte nur ab einem Studiensemester online bewertet werden - return $version === null ? null : $version->isCurrent; - } + public function getProjektarbeitenForStudiengang($studiengang_kz, $benotet) { $new_qry = "SELECT DISTINCT ON(tmp.projektarbeit_id) *, campus.get_betreuer_details(tmp.zweitbetreuer_person_id) as zweitbetreuer_full_name, campus.get_betreuer_details(tmp.betreuer_person_id) as erstbetreuer_full_name diff --git a/application/models/education/Projektbetreuer_model.php b/application/models/education/Projektbetreuer_model.php index 02368ae21..47e0239d6 100644 --- a/application/models/education/Projektbetreuer_model.php +++ b/application/models/education/Projektbetreuer_model.php @@ -232,4 +232,41 @@ class Projektbetreuer_model extends DB_Model return $this->execQuery($qry, array($projektarbeit_id, $betreuer_person_id)); } + + /** + * Gets all Betreuer of a Projektarbeit. + * Returns one row for each person. + * @param int $projektarbeit_id + * @return array success with number of Betreuer or error + */ + public function getAllBetreuerOfProjektarbeit($projektarbeit_id) + { + $qry = "SELECT DISTINCT ON (pers.person_id) pers.person_id, betreuerart_kurzbz, vorname, nachname, + trim(COALESCE(titelpre,'')||' '||COALESCE(vorname,'')||' '||COALESCE(nachname,'')||' '||COALESCE(titelpost,'')) as voller_name, + anrede, titelpre, titelpost, gebdatum, geschlecht, pa.projekttyp_kurzbz, + ben.uid, ben.alias, ma.personalnummer, mitarbeiter_uid, student_uid, + ( + SELECT kontakt + FROM public.tbl_kontakt + WHERE kontakttyp = 'email' + AND person_id = pers.person_id + ORDER BY + CASE WHEN zustellung THEN 0 ELSE 1 END, + insertamum DESC NULLS LAST + LIMIT 1 + ) AS private_email + FROM lehre.tbl_projektarbeit pa + JOIN lehre.tbl_projektbetreuer USING (projektarbeit_id) + JOIN public.tbl_person pers USING (person_id) + LEFT JOIN public.tbl_benutzer ben USING (person_id) + LEFT JOIN public.tbl_mitarbeiter ma ON ben.uid = ma.mitarbeiter_uid + WHERE (ben.aktiv OR ben.aktiv IS NULL) + AND projektarbeit_id = ? + ORDER BY pers.person_id, CASE WHEN ma.mitarbeiter_uid IS NULL THEN 1 ELSE 0 END, /*Mitarbeiter account first*/ + CASE WHEN ben.uid IS NULL THEN 1 ELSE 0 END, /*user with account first*/ + ben.insertamum"; + + return $this->execQuery($qry, array($projektarbeit_id)); + } + } diff --git a/public/js/components/Cis/Abgabetool/AbgabeMitarbeiterDetail.js b/public/js/components/Cis/Abgabetool/AbgabeMitarbeiterDetail.js index 2f85b78c5..289102f87 100644 --- a/public/js/components/Cis/Abgabetool/AbgabeMitarbeiterDetail.js +++ b/public/js/components/Cis/Abgabetool/AbgabeMitarbeiterDetail.js @@ -487,7 +487,7 @@ export const AbgabeMitarbeiterDetail = { if(this.assistenzMode) { return this.abgabeTypeOptions } else { - return this.abgabeTypeOptions.filter(opt => this.abgabetypenBetreuer.includes(opt.bezeichnung)) + return this.abgabeTypeOptions.filter(opt => this.abgabetypenBetreuer.includes(opt.paabgabetyp_kurzbz)) } }, getMessagePtStyle() { diff --git a/public/js/components/Cis/Abgabetool/AbgabeStudentDetail.js b/public/js/components/Cis/Abgabetool/AbgabeStudentDetail.js index 7fb2ffc3d..dd6c86f78 100644 --- a/public/js/components/Cis/Abgabetool/AbgabeStudentDetail.js +++ b/public/js/components/Cis/Abgabetool/AbgabeStudentDetail.js @@ -55,7 +55,6 @@ export const AbgabeStudentDetail = { return false } - // TODO: define these if(endupload) { if(await this.$fhcAlert.confirm({ message: this.$p.t('abgabetool/confirmEnduploadSpeichern'), @@ -341,6 +340,7 @@ export const AbgabeStudentDetail = { +
{{ termin?.bezeichnung }} diff --git a/public/js/components/Cis/Abgabetool/AbgabetoolAssistenz.js b/public/js/components/Cis/Abgabetool/AbgabetoolAssistenz.js index 60e317863..0da8c2f5e 100644 --- a/public/js/components/Cis/Abgabetool/AbgabetoolAssistenz.js +++ b/public/js/components/Cis/Abgabetool/AbgabetoolAssistenz.js @@ -785,7 +785,7 @@ export const AbgabetoolAssistenz = { this.notenOptions = res.data[0] this.allowedNotenOptions = this.notenOptions.filter( - opt => res.data[1].includes(opt.bezeichnung) + opt => res.data[1].includes(opt.note) ) } diff --git a/public/js/components/Cis/Abgabetool/AbgabetoolMitarbeiter.js b/public/js/components/Cis/Abgabetool/AbgabetoolMitarbeiter.js index a4fa5a211..387a6606e 100644 --- a/public/js/components/Cis/Abgabetool/AbgabetoolMitarbeiter.js +++ b/public/js/components/Cis/Abgabetool/AbgabetoolMitarbeiter.js @@ -352,7 +352,7 @@ export const AbgabetoolMitarbeiter = { }, computed: { getAllowedAbgabeTypeOptions() { - return this.abgabeTypeOptions.filter(opt => this.abgabetypenBetreuer.includes(opt.bezeichnung)) + return this.abgabeTypeOptions.filter(opt => this.abgabetypenBetreuer.includes(opt.paabgabetyp_kurzbz)) } }, created() { @@ -375,7 +375,7 @@ export const AbgabetoolMitarbeiter = { this.notenOptions = res.data[0] this.allowedNotenOptions = this.notenOptions.filter( - opt => res.data[1].includes(opt.bezeichnung) + opt => res.data[1].includes(opt.note) ) } diff --git a/public/js/components/Cis/Abgabetool/AbgabetoolStudent.js b/public/js/components/Cis/Abgabetool/AbgabetoolStudent.js index 774f089c8..e8ed7eef4 100644 --- a/public/js/components/Cis/Abgabetool/AbgabetoolStudent.js +++ b/public/js/components/Cis/Abgabetool/AbgabetoolStudent.js @@ -308,7 +308,7 @@ export const AbgabetoolStudent = { this.notenOptions = res.data[0] this.allowedNotenOptions = this.notenOptions.filter( - opt => res.data[1].includes(opt.bezeichnung) + opt => res.data[1].includes(opt.note) ) } }).finally(() => {