diff --git a/application/config/abgabe.php b/application/config/abgabe.php index da77da22e..c6a3c4d85 100644 --- a/application/config/abgabe.php +++ b/application/config/abgabe.php @@ -7,7 +7,7 @@ $config['turnitin_link'] = 'https://technikum-wien.turnitin.com/sso/sp/redwood/s $config['old_abgabe_beurteilung_link'] = 'https://moodle.technikum-wien.at/mod/page/view.php?id=1005052'; -$config['PAABGABE_EMAIL_JOB_INTERVAL'] = '1 day'; +$config['PAABGABE_EMAIL_JOB_INTERVAL'] = '2 day'; // used as APP_ROOT.URL_STUDENTS -> cis4 $config['URL_STUDENTS'] = 'cis.php/Cis/Abgabetool/Student'; // used as APP_ROOT.URL_MITARBEITER -> old cis diff --git a/application/controllers/api/frontend/v1/Abgabe.php b/application/controllers/api/frontend/v1/Abgabe.php index 0b85e2370..36b2280b5 100644 --- a/application/controllers/api/frontend/v1/Abgabe.php +++ b/application/controllers/api/frontend/v1/Abgabe.php @@ -1169,7 +1169,7 @@ class Abgabe extends FHCAPI_Controller } // for each projektarbeit fetch their betreuer and save them in their own dictionary to avoid too many mails - $betreuer = []; + $betreuerMap = []; forEach($projektarbeiten as $projektarbeit_id => $abgaben) { $betreuerResult = $this->_ci->ProjektbetreuerModel->getAllBetreuerOfProjektarbeit($projektarbeit_id); @@ -1177,22 +1177,110 @@ class Abgabe extends FHCAPI_Controller // $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] = []; + if (!isset($betreuerMap[$betreuerRow->person_id])) { + $betreuerMap[$betreuerRow->person_id] = []; } + // Add the current row to the array associated with its 'projektarbeit_id'. - $projektarbeiten[$projektarbeitId][] = $newOrChangedAbgabe; + $betreuerMap[$betreuerRow->person_id][] = [$projektarbeit_id, $betreuerRow]; + + } + } + + $count = 0; + // now iterate over the betreuerMap and build 1 email about all projektarbeiten and their new/changed termine + + // $tupel = [$projektarbeit_id, $betreuerRow], each betreuer has 0..n [projektarbeit_id, changedAbgaben] tupel + forEach($betreuerMap as $betreuer_person_id => $tupelArr) { + + $abgabenString = '

'; + +// $betreuerRow = $tupel[1]; + $result = $this->_ci->ProjektarbeitModel->getProjektbetreuerAnrede($betreuer_person_id); + $data = getData($result)[0]; + + $anrede = $data->anrede; + $anredeFillString = $data->anrede == "Herr" ? "r" : ""; + $fullFormattedNameString = $data->first; + + forEach($tupelArr as $tupel) { + $projektarbeit_id = $tupel[0]; + $betreuerRow = $tupel[1]; + + + + $changedAbgaben = $projektarbeiten[$projektarbeit_id]; + + // filter for abgaben which where not inserted by the current betreuer iteration if there is no updateamum + // or not changed by the betreuer if there is updateamum + $relevantAbgaben = array_filter($changedAbgaben, function($abgabetermin) use ($betreuerRow) { + // new termin not created by that betreuer + if($abgabetermin->updatevon == null && $abgabetermin->insertvon != $betreuerRow->uid) { + return $abgabetermin; + } else if($abgabetermin->updatevon != null && $abgabetermin->updatevon != $betreuerRow->uid) { + return $abgabetermin; + } + }); + + if(count($relevantAbgaben) == 0) { + break; // skip that projektarbeit if only changes originate from the betreuer in question + } + + $projektarbeit_titel = $relevantAbgaben[0]->titel ?? 'Kein Titel vergeben'; +// $abgabenString = '

'; + $abgabenString .= 'Projektarbeit: '.$projektarbeit_titel.' ('.$betreuerRow->betreuerart_kurzbz.') ID:'.$projektarbeit_id.'
'; + $abgabeString .= 'Stg: '.$stgtyp.$stgkz.'
'; + foreach ($relevantAbgaben as $abgabe) { + $datetime = new DateTime($abgabe->datum); + $dateEmailFormatted = $datetime->format('d.m.Y'); + + $datetimeAbgabe = new DateTime($abgabe->abgabedatum); + $abgabedatumFormatted = $datetimeAbgabe->format('d.m.Y'); + + $abgabenString .= ' Zieldatum: '.$dateEmailFormatted . ' ' . $abgabe->bezeichnung . '
'; + if($abgabe->kurzbz != '') { + $abgabenString .= $abgabe->kurzbz . '
'; + } + } + + $abgabenString .= '

'; + + } + // done with building the change list, now send it + $betreuerRow = $tupelArr[0][1]; + + + $path = $this->_ci->config->item('URL_MITARBEITER'); + $url = APP_ROOT.$path; + + $body_fields = array( + 'anrede' => $anrede, + 'anredeFillString' => $anredeFillString, + 'fullFormattedNameString' => $fullFormattedNameString, + 'abgabenString' => $abgabenString, + 'linkAbgabetool' => $url + ); + +// if(count($tupelArr) <= 2) break; // testing code + + // send email with bundled info + sendSanchoMail( + 'PAAChangesBetSM', + $body_fields, + $betreuerRow->private_email, + $this->p->t('abgabetool', 'changedAbgabeterminev2') + ); + + $count++; } + $this->addMeta('$projektarbeiten', $projektarbeiten); + $this->addMeta('$betreuerMap', $betreuerMap); // $result = $this->_ci->PaabgabeModel->findNewOrChangedTermineByOtherUsersSince($interval); diff --git a/application/controllers/jobs/AbgabetoolJob.php b/application/controllers/jobs/AbgabetoolJob.php index c3e879963..adedb0f78 100644 --- a/application/controllers/jobs/AbgabetoolJob.php +++ b/application/controllers/jobs/AbgabetoolJob.php @@ -101,7 +101,6 @@ class AbgabetoolJob extends JOB_Controller $result = $this->_ci->ProjektarbeitModel->getProjektbetreuerAnrede($person_id); $data = getData($result)[0]; - // $abgabe is the array of paabgabe objects $anrede = $data->anrede; $anredeFillString = $data->anrede == "Herr" ? "r" : ""; $fullFormattedNameString = $data->first; diff --git a/application/models/education/Paabgabe_model.php b/application/models/education/Paabgabe_model.php index 9edfc68ac..09542be12 100644 --- a/application/models/education/Paabgabe_model.php +++ b/application/models/education/Paabgabe_model.php @@ -64,16 +64,20 @@ class Paabgabe_model extends DB_Model public function findAbgabenNewOrUpdatedSince($interval) { - $query = "SELECT projektarbeit_id, paabgabe_id, paabgabetyp_kurzbz, fixtermin, datum, kurzbz, campus.tbl_paabgabetyp.bezeichnung, campus.tbl_paabgabe.abgabedatum, - campus.tbl_paabgabe.insertvon, campus.tbl_paabgabe.insertamum, campus.tbl_paabgabe.updatevon, campus.tbl_paabgabe.updateamum, - campus.tbl_paabgabe.note, upload_allowed, beurteilungsnotiz, student_uid, tbl_projektarbeit.note, lehre.tbl_projektarbeit.titel - FROM campus.tbl_paabgabe - JOIN campus.tbl_paabgabetyp USING (paabgabetyp_kurzbz) - JOIN lehre.tbl_projektarbeit USING (projektarbeit_id) - - WHERE campus.tbl_paabgabe.insertamum >= NOW() - INTERVAL ? - OR campus.tbl_paabgabe.updateamum >= NOW() - INTERVAL ? - "; + $query = "SELECT projektarbeit_id, paabgabe_id, paabgabetyp_kurzbz, fixtermin, datum, campus.tbl_paabgabe.kurzbz, campus.tbl_paabgabetyp.bezeichnung, campus.tbl_paabgabe.abgabedatum, + campus.tbl_paabgabe.insertvon, campus.tbl_paabgabe.insertamum, campus.tbl_paabgabe.updatevon, campus.tbl_paabgabe.updateamum, + campus.tbl_paabgabe.note, upload_allowed, beurteilungsnotiz, student_uid, tbl_projektarbeit.note, lehre.tbl_projektarbeit.titel, + UPPER(tbl_studiengang.typ) as stgtyp, UPPER(tbl_studiengang.kurzbz) as stgkz + FROM campus.tbl_paabgabe + JOIN campus.tbl_paabgabetyp USING (paabgabetyp_kurzbz) + JOIN lehre.tbl_projektarbeit USING (projektarbeit_id) + JOIN lehre.tbl_lehreinheit using(lehreinheit_id) + JOIN lehre.tbl_lehrveranstaltung using(lehrveranstaltung_id) + JOIN public.tbl_studiengang on(lehre.tbl_lehrveranstaltung.studiengang_kz=public.tbl_studiengang.studiengang_kz) + + + WHERE campus.tbl_paabgabe.insertamum >= NOW() - INTERVAL ? + OR campus.tbl_paabgabe.updateamum >= NOW() - INTERVAL ?"; return $this->execQuery($query, [$interval, $interval]); }