diff --git a/application/controllers/jobs/MailJob.php b/application/controllers/jobs/MailJob.php index 721db0068..f459d4d3e 100644 --- a/application/controllers/jobs/MailJob.php +++ b/application/controllers/jobs/MailJob.php @@ -1,20 +1,8 @@ messagelib->sendAllNotices($numberToSent, $numberPerTimeRange, $emailTimeRange, $emailFromSystem); + $this->logInfo('Send all message email notices started'); + + // Send them all! + $sendAllEmailNotices = $this->messagelib->sendAllEmailNotices($since, $numberToSent, $numberPerTimeRange, $emailTimeRange, $emailFromSystem); + + if (isError($sendAllEmailNotices)) + { + $optionalParameters = new stdClass(); + $optionalParameters->$since = $since; + $optionalParameters->$numberToSent = $numberToSent; + $optionalParameters->$numberPerTimeRange = $numberPerTimeRange; + $optionalParameters->$emailTimeRange = $emailTimeRange; + $optionalParameters->$emailFromSystem = $emailFromSystem; + + $this->logError($sendAllEmailNotices->retval, $optionalParameters); + } + elseif (!hasData($sendAllEmailNotices)) + { + $this->logInfo('There were no unsent messages'); + } + + $this->logInfo('Send all message email notices ended'); } } diff --git a/application/controllers/jobs/Priorisation.php b/application/controllers/jobs/Priorisation.php new file mode 100644 index 000000000..7e63eb9b1 --- /dev/null +++ b/application/controllers/jobs/Priorisation.php @@ -0,0 +1,787 @@ +load->model('crm/Prestudent_model', 'PrestudentModel'); + //$this->load->model('organisation/Studiengang_model', 'StudiengangModel'); + //$this->load->model('organisation/Studienplan_model', 'StudienplanModel'); + + // Load helpers + //$this->load->helper('hlp_sancho_helper'); + } + + /** + * runReihungstestJob + */ + public function runReihungstestJob() + { + // Get study plans that have no assigned placement tests yet + $result = $this->ReihungstestModel->checkMissingReihungstest(); + + $missing_rt_arr = array(); + if (hasData($result)) + { + $missing_rt_arr = $result->retval; + } + elseif (isError($result)) + { + show_error(getError($result)); + } + + // Get free places + $result = $this->ReihungstestModel->getFreePlaces(); + + $free_places_arr = array(); + if (hasData($result)) + { + $free_places_arr = $result->retval; + } + elseif (isError($result)) + { + show_error(getError($result)); + } + + // Prepare data for mail template 'ReihungstestJob' + $content_data_arr = $this->_getContentData($missing_rt_arr, $free_places_arr); + + // Send email in Sancho design + if (!empty($missing_rt_arr) || !empty($free_places_arr)) + { + sendSanchoMail( + 'ReihungstestJob', + $content_data_arr, + MAIL_INFOCENTER, + 'Support für die Reihungstest-Verwaltung'); + } + } + + /* + * Sends an email to all assistants of a placement test when an anmeldeschluss has been reached + * + * @param integer $degreeProgram. Kennzahl of Degree Program to check + * @param string $bcc. Optional. BCC-Mailadress to send the Mails to + * @param string $from. Optional. Sender-Mailadress shown to recipient + */ + public function runZentraleReihungstestAnmeldefristAssistenzJob($degreeProgram, $bcc = null, $from = null) + { + // Encode Params + if ($bcc != '') + { + // $bcc can be given as null-string, so check that too + if ($bcc == 'null') + { + $bcc = ''; + } + else + { + $bcc = urldecode($bcc); + } + } + if ($from != '') + { + $from = urldecode($from); + } + + // Get placement tests where registration date was yesterday + $result = $this->ReihungstestModel->checkReachedRegistrationDate($degreeProgram); + + $reachedRegistration_rt_arr = array(); + + if (hasData($result)) + { + $reachedRegistration_rt_arr = $result->retval; + } + elseif (isError($result)) + { + show_error(getError($result)); + } + + $applicants_arr = array(); + + foreach ($reachedRegistration_rt_arr as $reihungstest) + { + $applicants = $this->ReihungstestModel->getApplicantsOfPlacementTestForCronjob($reihungstest->reihungstest_id); + + if (hasData($applicants)) + { + $applicants_arr = $applicants->retval; + } + elseif (isError($applicants)) + { + show_error(getError($applicants)); + } + + // Get all Bachelor-Degree-Programs with Mailadress + $bachelorStudiengeange = $this->StudiengangModel->loadStudiengaengeFromTyp('b'); + $bachelorStudiengeange_arr = array(); + + if (hasData($bachelorStudiengeange)) + { + $bachelorStudiengeange_arr = $bachelorStudiengeange->retval; + } + elseif (isError($bachelorStudiengeange)) + { + show_error(getError($bachelorStudiengeange)); + } + + // If a person ist an applicant of this degree-program send mail with application data + // Otherwise inform assistant, that no applicant is registered in this test + foreach ($bachelorStudiengeange_arr as $bachelorStudiengang) + { + $studiengang_kuerzel = strtoupper($bachelorStudiengang->typ.$bachelorStudiengang->kurzbz); + $applicantCounter = 0; + $mailcontent_data_arr = array(); + foreach ($applicants_arr as $applicant) + { + if ($bachelorStudiengang->studiengang_kz == $applicant->studiengang_kz) + { + $applicantCounter ++; + } + } + if ($applicantCounter == 0) + { + $mailcontent = '

Der Anmeldeschluss für den zentralen Reihungstest am ' . date_format(date_create($reihungstest->datum), 'd.m.Y') . ' um ' . $reihungstest->uhrzeit . ' Uhr wurde gestern erreicht.

'; + $mailcontent .= '

Für den Studiengang '.$studiengang_kuerzel.' nehmen keine InteressentInnen an diesem Reihungstest teil

'; + } + else + { + $mailcontent = '

Der Anmeldeschluss für den zentralen Reihungstest am ' . date_format(date_create($reihungstest->datum), 'd.m.Y') . ' um ' . $reihungstest->uhrzeit . ' Uhr wurde gestern erreicht.

'; + $mailcontent .= ' +

' . $applicantCounter . ' InteressentIn(nen) des Studiengangs ' . $studiengang_kuerzel . ' nehmen daran teil:

+

+ + Liste der Anmeldungen + +

'; + } + $mailcontent_data_arr['table'] = $mailcontent; + + // Send email in Sancho design + if (!isEmptyString($mailcontent)) + { + sendSanchoMail( + 'Sancho_ReihungstestteilnehmerJob', + $mailcontent_data_arr, + $bachelorStudiengang->email, + 'Anmeldeschluss Reihungstest ' . date_format(date_create($reihungstest->datum), 'd.m.Y') . ' ' . $reihungstest->uhrzeit . ' Uhr', + 'sancho_header_min_bw.jpg', + 'sancho_footer_min_bw.jpg', + $from, + '', + $bcc); + } + } + } + } + + /* + * Checks, if an applicant was assigned to a test after Anmeldefrist and sends an email to all responsible assistants + * + * @param integer $degreeProgram. Kennzahl of Degree Program to check + * @param string $bcc. Optional. BCC-Mailadress to send the Mails to + * @param string $from. Optional. Sender-Mailadress shown to recipient + */ + public function runZentraleReihungstestNachtraeglichHinzugefuegtJob($degreeProgram, $bcc = null, $from = null) + { + // Encode Params + if ($bcc != '') + { + // $bcc can be given as null-string, so check that too + if ($bcc == 'null') + { + $bcc = ''; + } + else + { + $bcc = urldecode($bcc); + } + } + if ($from != '') + { + $from = urldecode($from); + } + + // Get applicants that have been added to a test after Anmeldefrist + $result = $this->ReihungstestModel->getApplicantAssignedAfterDate($degreeProgram); + + $applicants_after_anmeldefrist_arr = array(); + + if (hasData($result)) + { + $applicants_after_anmeldefrist_arr = $result->retval; + } + elseif (isError($result)) + { + show_error(getError($result)); + } + + $studiengang = ''; + $mailReceipients = ''; // String with all mailadresses + $mailcontent_data_arr = array(); + $headerstyle = 'style="background: #DCE4EF; border: 1px solid #FFF; padding: 4px; text-align: left;"'; + $rowstyle = 'style="background-color: #EEEEEE; padding: 4px;"'; + $mailcontent = ''; + $applicants_list = ''; + + if (count($applicants_after_anmeldefrist_arr) > 0) + { + foreach ($applicants_after_anmeldefrist_arr as $applicant) + { + if ($studiengang != $applicant->studiengang_kz) + { + if ($studiengang != '' && $studiengang != $applicant->studiengang_kz) + { + $bachelorStudiengang = $this->StudiengangModel->load($studiengang); + $mailcontent .= $applicants_list; + $mailcontent .= ''; + $mailcontent .= '

+ + Liste der Anmeldungen + +

'; + $mailcontent_data_arr['table'] = $mailcontent; + sendSanchoMail( + 'Sancho_ReihungstestteilnehmerJob', + $mailcontent_data_arr, + $bachelorStudiengang->retval[0]->email, + 'InteressentIn nach Reihungstest-Anmeldeschluss hinzugefügt', + 'sancho_header_min_bw.jpg', + 'sancho_footer_min_bw.jpg', + $from, + '', + $bcc); + $applicants_list = ''; + $mailcontent_data_arr = array(); + } + + $mailcontent = '

Folgende InteressentInnen wurden nach der Anmeldefrist zu einem Reihungstest hinzugefügt.
Details siehe Link

'; + $mailcontent .= ' + + + + + + + + + + + '; + } + + $studiengang = $applicant->studiengang_kz; + $mailReceipients .= $applicant->email . ';'; + $applicants_list .= ' + + + + + + + + + '; + }; + $bachelorStudiengang = $this->StudiengangModel->load($studiengang); + $mailcontent .= $applicants_list; + $mailcontent .= '
Datum des TestsUhrzeit des TestsOrgFormSemesterNachnameVorname
' . date_format(date_create($applicant->datum), 'd.m.Y') . '' . $applicant->uhrzeit . '' . $applicant->orgform_kurzbz . '' . $applicant->ausbildungssemester . '' . $applicant->nachname . '' . $applicant->vorname . '
'; + $mailcontent .= '

+ + Liste der Anmeldungen + +

'; + $mailcontent_data_arr['table'] = $mailcontent; + sendSanchoMail( + 'Sancho_ReihungstestteilnehmerJob', + $mailcontent_data_arr, + $bachelorStudiengang->retval[0]->email, + 'InteressentIn nach Reihungstest-Anmeldeschluss hinzugefügt', + 'sancho_header_min_bw.jpg', + 'sancho_footer_min_bw.jpg', + $from, + '', + $bcc); + } + } + + /* + * Sends an email to all applicants of a placement test to remind them 3 working days before + * + * @param integer $degreeProgram. Kennzahl of Degree Program to check + * @param string $bcc. Optional. BCC-Mailadress to send the Mails to + * @param string $from. Optional. Sender-Mailadress shown to recipient + */ + public function remindApplicantsOfPlacementTest($degreeProgram, $bcc = null, $from = null) + { + // Encode Params + if ($bcc != '') + { + // $bcc can be given as null-string, so check that too + if ($bcc == 'null') + { + $bcc = ''; + } + else + { + $bcc = urldecode($bcc); + } + } + if ($from != '') + { + $from = urldecode($from); + } + + // Get placement tests with testdate within the next 2 weeks + $resultNextTestDates = $this->ReihungstestModel->getNextPlacementtests($degreeProgram, 14); + if (hasData($resultNextTestDates)) + { + $nextTestDates = $resultNextTestDates->retval; + $enddate = ''; + // Loop through the dates + foreach ($nextTestDates as $testDates) + { + $workingdays = 0; + $testsOndate = array(); + + // Deduct days till 3 working days are reached + for ($i = 1; ; $i++) + { + if (isDateWorkingDay($testDates->datum, $i) === true) + { + $workingdays++; + } + if ($workingdays == 3) + { + $enddate = date("Y-m-d", strtotime("$testDates->datum -" . $i . " days")); + break; + } + else + { + continue; + } + } + + // If $enddate is today -> load all tests of $testDates->datum + if (date("Y-m-d", strtotime($enddate)) == date('Y-m-d')) + { + $resultTestsOnDate = $this->ReihungstestModel->getTestsOnDate($testDates->datum, $degreeProgram); + + if (hasData($resultTestsOnDate)) + { + $testsOndate = $resultTestsOnDate->retval; + } + elseif (isError($resultTestsOnDate)) + { + show_error(getError($resultTestsOnDate)); + } + } + + if (!isEmptyArray($testsOndate)) + { + foreach ($testsOndate as $reihungstest) + { + // Loads applicants of a test + $applicants = $this->ReihungstestModel->getApplicantsOfPlacementTest($reihungstest->reihungstest_id); + + if (hasData($applicants)) + { + $applicants_arr = $applicants->retval; + } + elseif (isError($applicants)) + { + show_error(getError($applicants)); + } + + foreach ($applicants_arr as $applicant) + { + $mailcontent_data_arr = array(); + $mailcontent_data_arr['anrede'] = $applicant->anrede; + $mailcontent_data_arr['nachname'] = $applicant->nachname; + $mailcontent_data_arr['vorname'] = $applicant->vorname; + $mailcontent_data_arr['rt_datum'] = date_format(date_create($reihungstest->datum), 'd.m.Y'); + $mailcontent_data_arr['rt_uhrzeit'] = date_format(date_create($reihungstest->uhrzeit), 'H:i'); + $mailcontent_data_arr['rt_raum'] = $applicant->planbezeichnung; + if ($applicant->lageplan == '') + { + $mailcontent_data_arr['wegbeschreibung'] = 'Für diesen Raum liegt noch keine Wegbeschreibung vor.

No directions were found for this room'; + } + else + { + $mailcontent_data_arr['wegbeschreibung'] = $applicant->lageplan; + } + + sendSanchoMail( + 'Sancho_RemindApplicantsOfTest', + $mailcontent_data_arr, + $applicant->email, + 'Ihre Anmeldung zum Reihungstest - Reminder / Your registration for the placement test - Reminder', + DEFAULT_SANCHO_HEADER_IMG, + DEFAULT_SANCHO_FOOTER_IMG, + $from, + '', + $bcc); + } + } + } + } + } + } + + /** + * This job sends eMail(s) to the relevant stg assistance(s) informing about: + * All applicants, who have sent new applications AFTER they had absolved a + * placement test in the actual studiensemester + * AND who have been confirmed yesterday. + */ + public function mailNewApplicants() + { + // Get yesterdays confirmed applicants for Bachelor-studies + $this->load->model('crm/Prestudentstatus_model', 'PrestudentstatusModel'); + $this->PrestudentstatusModel->addSelect(' + tbl_person.person_id, + tbl_prestudentstatus.prestudent_id, + tbl_prestudent.studiengang_kz, + tbl_prestudentstatus.studiensemester_kurzbz, + tbl_prestudentstatus.bestaetigtam, + tbl_prestudentstatus.bewerbung_abgeschicktamum + '); + $this->PrestudentstatusModel->addJoin('public.tbl_prestudent', 'prestudent_id'); + $this->PrestudentstatusModel->addJoin('public.tbl_studiengang', 'studiengang_kz'); + $this->PrestudentstatusModel->addJoin('public.tbl_studiengangstyp', 'typ'); + $this->PrestudentstatusModel->addJoin('public.tbl_person', 'person_id'); + + $yesterdays_applicants_arr = $this->PrestudentstatusModel->loadWhere(' + status_kurzbz = \'Interessent\' AND + typ = \'b\' AND + bestaetigtam = current_date - 1 + '); + + // Retrieve the person_ids of yesterdays confirmed applicants + $person_id_arr = array(); + if (hasData($yesterdays_applicants_arr)) + { + foreach ($yesterdays_applicants_arr->retval as $yesterdays_applicant) + { + if (isset($yesterdays_applicant->person_id)) { + $person_id_arr[] = $yesterdays_applicant->person_id; + } + } + } + elseif (isError($yesterdays_applicants_arr)) + { + show_error(getError($yesterdays_applicants_arr)); + } + + // Get all other prestudenten of the given persons. + if (!isEmptyArray($person_id_arr)) + { + $this->load->model('crm/Prestudent_model', 'PrestudentModel'); + $this->PrestudentModel->addDistinct(); + $this->PrestudentModel->addSelect(' + person_id, + tbl_reihungstest.studiensemester_kurzbz, + tbl_reihungstest.reihungstest_id, + (SELECT(tbl_reihungstest.datum::text || \' \' || tbl_reihungstest.uhrzeit::text)::timestamp) AS reihungstest_timestamp + '); + $this->PrestudentModel->addJoin('public.tbl_studiengang', 'studiengang_kz'); + $this->PrestudentModel->addJoin('public.tbl_studiengangstyp', 'typ'); + $this->PrestudentModel->addJoin('public.tbl_prestudentstatus', 'prestudent_id'); + $this->PrestudentModel->addJoin('public.tbl_person', 'person_id'); + $this->PrestudentModel->addJoin('public.tbl_rt_person', 'person_id'); + $this->PrestudentModel->addJoin('public.tbl_reihungstest', 'tbl_reihungstest.reihungstest_id = tbl_rt_person.rt_id'); + + // Store them, if they have already absolved a placement test in the same study term they have applied for. + $placement_absolvents_arr = $this->PrestudentModel->loadWhere(' + person_id IN (' . implode(', ', $person_id_arr) . ') AND + typ = \'b\' AND + teilgenommen = \'t\' AND + tbl_reihungstest.studiensemester_kurzbz IN ( + SELECT + studiensemester_kurzbz + FROM + public.tbl_studiensemester + WHERE + ende >= now() + ) + '); + } + + // Store data to be send in the email-link + $result_arr = array(); + foreach($yesterdays_applicants_arr->retval as $yesterdays_applicant) + { + foreach ($placement_absolvents_arr->retval as $placement_absolvent) + { + if ($yesterdays_applicant->person_id == $placement_absolvent->person_id && + $yesterdays_applicant->studiensemester_kurzbz == $placement_absolvent->studiensemester_kurzbz && + $yesterdays_applicant->bewerbung_abgeschicktamum >= $placement_absolvent->reihungstest_timestamp) + { + $obj = new stdClass(); + $obj->prestudent_id = $yesterdays_applicant->prestudent_id; // prestudent_id of the yesterdays applicant + $obj->studiengang_kz = $yesterdays_applicant->studiengang_kz; // study program of interest of the yesterdays applicant + $obj->reihungstest_id = $placement_absolvent->reihungstest_id; // reihungstest_id of absolved reihungstest of that person + + $result_arr[]= $obj; + } + } + } + + // Sort by STG. This is important to send the mails clustered by STG to the different STG assistances. + usort($result_arr, function ($a, $b) + { + if ($a->studiengang_kz == $b->studiengang_kz) { + return 0; + } + return ($a->studiengang_kz < $b->studiengang_kz) ? -1 : 1; + }); + + $to = ''; // mail recipient (stg assistance) + $content_arr = array(); // url paths to the new applicants + $base_link = base_url('vilesci/stammdaten/auswertung_fhtw.php'); + + $i = 0; // loop counter + $len = count($result_arr); + + // Loop trough list of new applicants + foreach($result_arr as $result) + { + $studiengang = $this->StudiengangModel->load($result->studiengang_kz); + $mail_stg_assistance = $studiengang->retval[0]->email; + + // If first loop + if ($i == 0) + { + $to = $mail_stg_assistance; // set recipient initially + } + + // If new study is encountered but is not the first loop + if ($to != $mail_stg_assistance && $i != 0) + { + // Prepare content for mail template + $content_data_arr = $this->_getContentDataNewApplicant($content_arr); + + // Send mail + sendSanchoMail( + 'BewerberNachReihungstest', + $content_data_arr, + $to, + 'Neue Bewerbungen nach absolviertem Reihungstest', + 'sancho_header_min_bw.jpg', + 'sancho_footer_min_bw.jpg' + ); + + // Reset content for new study applicants & reset recipient (new stg assistance) + $content_arr = array($base_link. '?reihungstest='. $result->reihungstest_id. '&prestudent_id='. $result->prestudent_id); + $to = $mail_stg_assistance; + } + // If same study + else + { + // just add content + $content_arr[]= $base_link. '?reihungstest='. $result->reihungstest_id. '&prestudent_id='. $result->prestudent_id; // add to content + } + + // If last loop + if (($i == $len - 1)) + { + // Prepare content for mail template + $content_data_arr = $this->_getContentDataNewApplicant($content_arr); + + // Send mail + sendSanchoMail( + 'BewerberNachReihungstest', + $content_data_arr, + $to, + 'Neue Bewerbungen nach absolviertem Reihungstest', + 'sancho_header_min_bw.jpg', + 'sancho_footer_min_bw.jpg' + ); + } + $i++; // iterate counter + } + } + + // ------------------------------------------------------------------------ + // Private methods + /** + * Returns associative array with data as needed in the reihungstest job template. + * @param array $missing_rt_arr Array with studienpläne, which have no assigned placement tests. + * @param array $free_places_arr Array with info and amount of free placement test places. + * @return array + */ + private function _getContentData($missing_rt_arr, $free_places_arr) + { + $style_tbl1 = ' cellpadding="0" cellspacing="10" width="100%" style="font-family: courier, verdana, sans-serif; font-size: 0.95em; border: 1px solid #000000;" '; + $style_tbl2 = ' cellpadding="0" cellspacing="20" width="100%" style="font-family: courier, verdana, sans-serif; font-size: 0.95em; border: 1px solid #000000;" '; + + // Prepare HTML table with study plans that have no placement tests yet + if (!empty($missing_rt_arr)) { + $studienplan_list + = ' + + '; + + foreach ($missing_rt_arr as $rt) { + $studienplan_list .= ' + ' . $rt->bezeichnung . ' + '; + } + + $studienplan_list .= ' + + '; + } else { + $studienplan_list = ' + + Alles okay! Alle Studienpläne haben zumindest einen Reihungstest. + + '; + } + + // Prepare HTML table with information and amount of free places + if (!empty($free_places_arr)) { + $freie_plaetze_list = ' + + + Fakultät + Reihungstesttermine + Freie Plätze + + '; + + foreach ($free_places_arr as $free_place) { + $datum = new DateTime($free_place->datum); + $style_alarm = ($free_place->freie_plaetze <= 5) ? ' style=" color: red; font-weight: bold" ' : ''; // mark if <=5 free places + + $freie_plaetze_list .= ' + + ' . $free_place->fakultaet . ' + ' . $datum->format('d.m.Y') . ' + ' . $free_place->freie_plaetze . ' + + '; + } + + $freie_plaetze_list .= ' + + '; + } else { + $freie_plaetze_list = ' + + Es gibt heute keine Ergebnisse zu freien Reihungstestplätze. + + '; + } + + // Set associative array with the prepared HTML tables and URL be used by the template's variables + $content_data_arr['studienplan_list'] = $studienplan_list; + $content_data_arr['freie_plaetze_list'] = $freie_plaetze_list; + $content_data_arr['link'] = site_url('/organisation/Reihungstest'); + + return $content_data_arr; + } + + /** + * Returns associative array with data as needed in the BewerberNachReihungstest-template. + * @param array $content_arr Array with links to the testtool evaluation page of the new applicants. + * @return array + */ + private function _getContentDataNewApplicant($content_arr) + { + $content = ''; + $counter = 1; + foreach ($content_arr as $row) + { + $content .= '
Link zu: Bewerber '. $counter. ''; + $counter++; + } + + $content_data_arr['link'] = $content; + return $content_data_arr; + } + + + /** + * Checks the upcoming placement tests if there are correct studyplans assigned + * If there are invalid studyplans assigned (outdated because there exists a new version), + * it tries to find a better one and assigns it additionaly + */ + public function correctStudienplan() + { + // get all placement tests with incorrect studyplan + $qry = " + SELECT + tbl_reihungstest.reihungstest_id, + tbl_studienplan.studienplan_id, + tbl_reihungstest.studiensemester_kurzbz, + tbl_studienordnung.studiengang_kz + FROM + public.tbl_reihungstest + JOIN public.tbl_rt_studienplan ON(tbl_rt_studienplan.reihungstest_id=tbl_reihungstest.reihungstest_id) + JOIN lehre.tbl_studienplan USING(studienplan_id) + JOIN lehre.tbl_studienordnung USING(studienordnung_id) + WHERE + NOT EXISTS( + SELECT 1 FROM lehre.tbl_studienplan_semester + WHERE studienplan_id=tbl_rt_studienplan.studienplan_id + AND tbl_studienplan_semester.studiensemester_kurzbz=tbl_reihungstest.studiensemester_kurzbz + ) + AND tbl_reihungstest.datum >= now() + AND NOT EXISTS( + SELECT + 1 + FROM + public.tbl_rt_studienplan rtstp + JOIN lehre.tbl_studienplan stp USING(studienplan_id) + JOIN lehre.tbl_studienordnung sto USING(studienordnung_id) + JOIN lehre.tbl_studienplan_semester stpsem USING(studienplan_id) + WHERE + sto.studiengang_kz=tbl_studienordnung.studiengang_kz + AND rtstp.reihungstest_id=tbl_reihungstest.reihungstest_id + AND stpsem.studiensemester_kurzbz=tbl_reihungstest.studiensemester_kurzbz + ) + "; + + $db = new DB_Model(); + $result_rt = $db->execReadOnlyQuery($qry); + + if (hasdata($result_rt)) { + foreach ($result_rt->retval as $row_rt) { + // find an active studyplan for the same degree program with is valid in this semester + $result_stpl = $this->StudienplanModel->getStudienplaeneBySemester( + $row_rt->studiengang_kz, + $row_rt->studiensemester_kurzbz + ); + + if (hasData($result_stpl)) { + foreach ($result_stpl->retval as $row_stpl) { + // Add new Studyplan to RtStudienplan if missing + $rt_studienplan = $this->RtStudienplanModel->loadWhere(array( + "reihungstest_id" => $row_rt->reihungstest_id, + "studienplan_id" => $row_stpl->studienplan_id + )); + + if (!hasData($rt_studienplan)) { + echo "\nAdding StudienplanId: $row_stpl->studienplan_id"; + echo " to ReihungstestId: $row_rt->reihungstest_id"; + + $this->RtStudienplanModel->insert(array( + "reihungstest_id" => $row_rt->reihungstest_id, + "studienplan_id" => $row_stpl->studienplan_id + )); + } + } + } + } + } + } +} diff --git a/application/controllers/jobs/ReihungstestJob.php b/application/controllers/jobs/ReihungstestJob.php index 84a5fe614..c548d2495 100644 --- a/application/controllers/jobs/ReihungstestJob.php +++ b/application/controllers/jobs/ReihungstestJob.php @@ -3,30 +3,32 @@ if (!defined('BASEPATH')) exit('No direct script access allowed'); class ReihungstestJob extends CLI_Controller { - /** - * Constructor - */ - public function __construct() - { - parent::__construct(); + /** + * Constructor + */ + public function __construct() + { + parent::__construct(); - // Load models - $this->load->model('crm/Reihungstest_model', 'ReihungstestModel'); - $this->load->model('crm/RtStudienplan_model', 'RtStudienplanModel'); - $this->load->model('organisation/Studiengang_model', 'StudiengangModel'); - $this->load->model('organisation/Studienplan_model', 'StudienplanModel'); + // Load models + $this->load->model('crm/Reihungstest_model', 'ReihungstestModel'); + $this->load->model('crm/RtStudienplan_model', 'RtStudienplanModel'); + $this->load->model('crm/Konto_model', 'KontoModel'); + $this->load->model('crm/Prestudentstatus_model', 'PrestudentstatusModel'); + $this->load->model('organisation/Studiengang_model', 'StudiengangModel'); + $this->load->model('organisation/Studienplan_model', 'StudienplanModel'); - // Load helpers - $this->load->helper('hlp_sancho_helper'); - } + // Load helpers + $this->load->helper('hlp_sancho_helper'); + } - /** - * runReihungstestJob - */ - public function runReihungstestJob() - { - // Get study plans that have no assigned placement tests yet - $result = $this->ReihungstestModel->checkMissingReihungstest(); + /** + * runReihungstestJob + */ + public function runReihungstestJob() + { + // Get study plans that have no assigned placement tests yet + $result = $this->ReihungstestModel->checkMissingReihungstest(); $missing_rt_arr = array(); if (hasData($result)) @@ -38,8 +40,8 @@ class ReihungstestJob extends CLI_Controller show_error(getError($result)); } - // Get free places - $result = $this->ReihungstestModel->getFreePlaces(); + // Get free places + $result = $this->ReihungstestModel->getFreePlaces(); $free_places_arr = array(); if (hasData($result)) @@ -51,8 +53,8 @@ class ReihungstestJob extends CLI_Controller show_error(getError($result)); } - // Prepare data for mail template 'ReihungstestJob' - $content_data_arr = $this->_getContentData($missing_rt_arr, $free_places_arr); + // Prepare data for mail template 'ReihungstestJob' + $content_data_arr = $this->_getContentData($missing_rt_arr, $free_places_arr); // Send email in Sancho design if (!empty($missing_rt_arr) || !empty($free_places_arr)) @@ -95,7 +97,7 @@ class ReihungstestJob extends CLI_Controller // Get placement tests where registration date was yesterday $result = $this->ReihungstestModel->checkReachedRegistrationDate($degreeProgram); - $reachedRegistration_rt_arr = array(); + $reachedRegistration_rt_arr = array(); if (hasData($result)) { @@ -106,11 +108,11 @@ class ReihungstestJob extends CLI_Controller show_error(getError($result)); } - $applicants_arr = array(); + $applicants_arr = array(); - foreach ($reachedRegistration_rt_arr as $reihungstest) - { - $applicants = $this->ReihungstestModel->getApplicantsOfPlacementTestForCronjob($reihungstest->reihungstest_id); + foreach ($reachedRegistration_rt_arr as $reihungstest) + { + $applicants = $this->ReihungstestModel->getApplicantsOfPlacementTestForCronjob($reihungstest->reihungstest_id); if (hasData($applicants)) { @@ -214,24 +216,24 @@ class ReihungstestJob extends CLI_Controller // Get applicants that have been added to a test after Anmeldefrist $result = $this->ReihungstestModel->getApplicantAssignedAfterDate($degreeProgram); - $applicants_after_anmeldefrist_arr = array(); + $applicants_after_anmeldefrist_arr = array(); - if (hasData($result)) - { - $applicants_after_anmeldefrist_arr = $result->retval; - } - elseif (isError($result)) - { - show_error(getError($result)); - } + if (hasData($result)) + { + $applicants_after_anmeldefrist_arr = $result->retval; + } + elseif (isError($result)) + { + show_error(getError($result)); + } - $studiengang = ''; - $mailReceipients = ''; // String with all mailadresses - $mailcontent_data_arr = array(); - $headerstyle = 'style="background: #DCE4EF; border: 1px solid #FFF; padding: 4px; text-align: left;"'; - $rowstyle = 'style="background-color: #EEEEEE; padding: 4px;"'; - $mailcontent = ''; - $applicants_list = ''; + $studiengang = ''; + $mailReceipients = ''; // String with all mailadresses + $mailcontent_data_arr = array(); + $headerstyle = 'style="background: #DCE4EF; border: 1px solid #FFF; padding: 4px; text-align: left;"'; + $rowstyle = 'style="background-color: #EEEEEE; padding: 4px;"'; + $mailcontent = ''; + $applicants_list = ''; if (count($applicants_after_anmeldefrist_arr) > 0) { @@ -277,11 +279,11 @@ class ReihungstestJob extends CLI_Controller '; - } + } - $studiengang = $applicant->studiengang_kz; - $mailReceipients .= $applicant->email . ';'; - $applicants_list .= ' + $studiengang = $applicant->studiengang_kz; + $mailReceipients .= $applicant->email . ';'; + $applicants_list .= ' ' . date_format(date_create($applicant->datum), 'd.m.Y') . ' ' . $applicant->uhrzeit . ' @@ -315,7 +317,7 @@ class ReihungstestJob extends CLI_Controller } /* - * Sends an email to all applicants of a placement test to remind them 3 working days before + * Sends an email to all applicants of a placement test to remind them 2 working days before * * @param integer $degreeProgram. Kennzahl of Degree Program to check * @param string $bcc. Optional. BCC-Mailadress to send the Mails to @@ -341,66 +343,66 @@ class ReihungstestJob extends CLI_Controller $from = urldecode($from); } - // Get placement tests with testdate within the next 2 weeks - $resultNextTestDates = $this->ReihungstestModel->getNextPlacementtests($degreeProgram, 14); - if (hasData($resultNextTestDates)) - { - $nextTestDates = $resultNextTestDates->retval; - $enddate = ''; - // Loop through the dates - foreach ($nextTestDates as $testDates) - { - $workingdays = 0; - $testsOndate = array(); + // Get placement tests with testdate within the next 2 weeks + $resultNextTestDates = $this->ReihungstestModel->getNextPlacementtests($degreeProgram, 14); + if (hasData($resultNextTestDates)) + { + $nextTestDates = $resultNextTestDates->retval; + $enddate = ''; + // Loop through the dates + foreach ($nextTestDates as $testDates) + { + $workingdays = 0; + $testsOndate = array(); - // Deduct days till 3 working days are reached - for ($i = 1; ; $i++) - { - if (isDateWorkingDay($testDates->datum, $i) === true) - { - $workingdays++; - } - if ($workingdays == 3) - { - $enddate = date("Y-m-d", strtotime("$testDates->datum -" . $i . " days")); - break; - } - else - { - continue; - } - } + // Deduct days till 2 working days are reached + for ($i = 1; ; $i++) + { + if (isDateWorkingDay($testDates->datum, $i) === true) + { + $workingdays++; + } + if ($workingdays == 2) + { + $enddate = date("Y-m-d", strtotime("$testDates->datum -" . $i . " days")); + break; + } + else + { + continue; + } + } - // If $enddate is today -> load all tests of $testDates->datum - if (date("Y-m-d", strtotime($enddate)) == date('Y-m-d')) - { - $resultTestsOnDate = $this->ReihungstestModel->getTestsOnDate($testDates->datum, $degreeProgram); + // If $enddate is today -> load all tests of $testDates->datum + if (date("Y-m-d", strtotime($enddate)) == date('Y-m-d')) + { + $resultTestsOnDate = $this->ReihungstestModel->getTestsOnDate($testDates->datum, $degreeProgram); - if (hasData($resultTestsOnDate)) - { - $testsOndate = $resultTestsOnDate->retval; - } - elseif (isError($resultTestsOnDate)) - { - show_error(getError($resultTestsOnDate)); - } - } + if (hasData($resultTestsOnDate)) + { + $testsOndate = $resultTestsOnDate->retval; + } + elseif (isError($resultTestsOnDate)) + { + show_error(getError($resultTestsOnDate)); + } + } - if (!isEmptyArray($testsOndate)) - { - foreach ($testsOndate as $reihungstest) - { - // Loads applicants of a test - $applicants = $this->ReihungstestModel->getApplicantsOfPlacementTest($reihungstest->reihungstest_id); + if (!isEmptyArray($testsOndate)) + { + foreach ($testsOndate as $reihungstest) + { + // Loads applicants of a test + $applicants = $this->ReihungstestModel->getApplicantsOfPlacementTest($reihungstest->reihungstest_id); - if (hasData($applicants)) - { - $applicants_arr = $applicants->retval; - } - elseif (isError($applicants)) - { - show_error(getError($applicants)); - } + if (hasData($applicants)) + { + $applicants_arr = $applicants->retval; + } + elseif (isError($applicants)) + { + show_error(getError($applicants)); + } foreach ($applicants_arr as $applicant) { @@ -420,237 +422,237 @@ class ReihungstestJob extends CLI_Controller $mailcontent_data_arr['wegbeschreibung'] = $applicant->lageplan; } - sendSanchoMail( - 'Sancho_RemindApplicantsOfTest', - $mailcontent_data_arr, - $applicant->email, - 'Ihre Anmeldung zum Reihungstest - Reminder / Your registration for the placement test - Reminder', - DEFAULT_SANCHO_HEADER_IMG, - DEFAULT_SANCHO_FOOTER_IMG, - $from, - '', - $bcc); - } - } - } - } - } - } + sendSanchoMail( + 'Sancho_RemindApplicantsOfTest', + $mailcontent_data_arr, + $applicant->email, + 'Ihre Anmeldung zum Reihungstest - Reminder / Your registration for the placement test - Reminder', + DEFAULT_SANCHO_HEADER_IMG, + DEFAULT_SANCHO_FOOTER_IMG, + $from, + '', + $bcc); + } + } + } + } + } + } - /** - * This job sends eMail(s) to the relevant stg assistance(s) informing about: - * All applicants, who have sent new applications AFTER they had absolved a - * placement test in the actual studiensemester - * AND who have been confirmed yesterday. - */ - public function mailNewApplicants() - { - // Get yesterdays confirmed applicants for Bachelor-studies - $this->load->model('crm/Prestudentstatus_model', 'PrestudentstatusModel'); - $this->PrestudentstatusModel->addSelect(' - tbl_person.person_id, - tbl_prestudentstatus.prestudent_id, - tbl_prestudent.studiengang_kz, - tbl_prestudentstatus.studiensemester_kurzbz, - tbl_prestudentstatus.bestaetigtam, - tbl_prestudentstatus.bewerbung_abgeschicktamum - '); - $this->PrestudentstatusModel->addJoin('public.tbl_prestudent', 'prestudent_id'); - $this->PrestudentstatusModel->addJoin('public.tbl_studiengang', 'studiengang_kz'); - $this->PrestudentstatusModel->addJoin('public.tbl_studiengangstyp', 'typ'); - $this->PrestudentstatusModel->addJoin('public.tbl_person', 'person_id'); + /** + * This job sends eMail(s) to the relevant stg assistance(s) informing about: + * All applicants, who have sent new applications AFTER they had absolved a + * placement test in the actual studiensemester + * AND who have been confirmed yesterday. + */ + public function mailNewApplicants() + { + // Get yesterdays confirmed applicants for Bachelor-studies + $this->load->model('crm/Prestudentstatus_model', 'PrestudentstatusModel'); + $this->PrestudentstatusModel->addSelect(' + tbl_person.person_id, + tbl_prestudentstatus.prestudent_id, + tbl_prestudent.studiengang_kz, + tbl_prestudentstatus.studiensemester_kurzbz, + tbl_prestudentstatus.bestaetigtam, + tbl_prestudentstatus.bewerbung_abgeschicktamum + '); + $this->PrestudentstatusModel->addJoin('public.tbl_prestudent', 'prestudent_id'); + $this->PrestudentstatusModel->addJoin('public.tbl_studiengang', 'studiengang_kz'); + $this->PrestudentstatusModel->addJoin('public.tbl_studiengangstyp', 'typ'); + $this->PrestudentstatusModel->addJoin('public.tbl_person', 'person_id'); - $yesterdays_applicants_arr = $this->PrestudentstatusModel->loadWhere(' - status_kurzbz = \'Interessent\' AND - typ = \'b\' AND - bestaetigtam = current_date - 1 - '); + $yesterdays_applicants_arr = $this->PrestudentstatusModel->loadWhere(' + status_kurzbz = \'Interessent\' AND + typ = \'b\' AND + bestaetigtam = current_date - 1 + '); - // Retrieve the person_ids of yesterdays confirmed applicants - $person_id_arr = array(); - if (hasData($yesterdays_applicants_arr)) - { - foreach ($yesterdays_applicants_arr->retval as $yesterdays_applicant) - { - if (isset($yesterdays_applicant->person_id)) { - $person_id_arr[] = $yesterdays_applicant->person_id; - } - } - } - elseif (isError($yesterdays_applicants_arr)) - { - show_error(getError($yesterdays_applicants_arr)); - } + // Retrieve the person_ids of yesterdays confirmed applicants + $person_id_arr = array(); + if (hasData($yesterdays_applicants_arr)) + { + foreach ($yesterdays_applicants_arr->retval as $yesterdays_applicant) + { + if (isset($yesterdays_applicant->person_id)) { + $person_id_arr[] = $yesterdays_applicant->person_id; + } + } + } + elseif (isError($yesterdays_applicants_arr)) + { + show_error(getError($yesterdays_applicants_arr)); + } - // Get all other prestudenten of the given persons. - if (!isEmptyArray($person_id_arr)) - { - $this->load->model('crm/Prestudent_model', 'PrestudentModel'); - $this->PrestudentModel->addDistinct(); - $this->PrestudentModel->addSelect(' - person_id, - tbl_reihungstest.studiensemester_kurzbz, - tbl_reihungstest.reihungstest_id, - (SELECT(tbl_reihungstest.datum::text || \' \' || tbl_reihungstest.uhrzeit::text)::timestamp) AS reihungstest_timestamp - '); - $this->PrestudentModel->addJoin('public.tbl_studiengang', 'studiengang_kz'); - $this->PrestudentModel->addJoin('public.tbl_studiengangstyp', 'typ'); - $this->PrestudentModel->addJoin('public.tbl_prestudentstatus', 'prestudent_id'); - $this->PrestudentModel->addJoin('public.tbl_person', 'person_id'); - $this->PrestudentModel->addJoin('public.tbl_rt_person', 'person_id'); - $this->PrestudentModel->addJoin('public.tbl_reihungstest', 'tbl_reihungstest.reihungstest_id = tbl_rt_person.rt_id'); + // Get all other prestudenten of the given persons. + if (!isEmptyArray($person_id_arr)) + { + $this->load->model('crm/Prestudent_model', 'PrestudentModel'); + $this->PrestudentModel->addDistinct(); + $this->PrestudentModel->addSelect(' + person_id, + tbl_reihungstest.studiensemester_kurzbz, + tbl_reihungstest.reihungstest_id, + (SELECT(tbl_reihungstest.datum::text || \' \' || tbl_reihungstest.uhrzeit::text)::timestamp) AS reihungstest_timestamp + '); + $this->PrestudentModel->addJoin('public.tbl_studiengang', 'studiengang_kz'); + $this->PrestudentModel->addJoin('public.tbl_studiengangstyp', 'typ'); + $this->PrestudentModel->addJoin('public.tbl_prestudentstatus', 'prestudent_id'); + $this->PrestudentModel->addJoin('public.tbl_person', 'person_id'); + $this->PrestudentModel->addJoin('public.tbl_rt_person', 'person_id'); + $this->PrestudentModel->addJoin('public.tbl_reihungstest', 'tbl_reihungstest.reihungstest_id = tbl_rt_person.rt_id'); - // Store them, if they have already absolved a placement test in the same study term they have applied for. - $placement_absolvents_arr = $this->PrestudentModel->loadWhere(' - person_id IN (' . implode(', ', $person_id_arr) . ') AND - typ = \'b\' AND - teilgenommen = \'t\' AND - tbl_reihungstest.studiensemester_kurzbz IN ( - SELECT - studiensemester_kurzbz - FROM - public.tbl_studiensemester - WHERE - ende >= now() - ) - '); - } + // Store them, if they have already absolved a placement test in the same study term they have applied for. + $placement_absolvents_arr = $this->PrestudentModel->loadWhere(' + person_id IN (' . implode(', ', $person_id_arr) . ') AND + typ = \'b\' AND + teilgenommen = \'t\' AND + tbl_reihungstest.studiensemester_kurzbz IN ( + SELECT + studiensemester_kurzbz + FROM + public.tbl_studiensemester + WHERE + ende >= now() + ) + '); + } - // Store data to be send in the email-link - $result_arr = array(); - foreach($yesterdays_applicants_arr->retval as $yesterdays_applicant) - { - foreach ($placement_absolvents_arr->retval as $placement_absolvent) - { - if ($yesterdays_applicant->person_id == $placement_absolvent->person_id && - $yesterdays_applicant->studiensemester_kurzbz == $placement_absolvent->studiensemester_kurzbz && - $yesterdays_applicant->bewerbung_abgeschicktamum >= $placement_absolvent->reihungstest_timestamp) - { - $obj = new stdClass(); - $obj->prestudent_id = $yesterdays_applicant->prestudent_id; // prestudent_id of the yesterdays applicant - $obj->studiengang_kz = $yesterdays_applicant->studiengang_kz; // study program of interest of the yesterdays applicant - $obj->reihungstest_id = $placement_absolvent->reihungstest_id; // reihungstest_id of absolved reihungstest of that person + // Store data to be send in the email-link + $result_arr = array(); + foreach($yesterdays_applicants_arr->retval as $yesterdays_applicant) + { + foreach ($placement_absolvents_arr->retval as $placement_absolvent) + { + if ($yesterdays_applicant->person_id == $placement_absolvent->person_id && + $yesterdays_applicant->studiensemester_kurzbz == $placement_absolvent->studiensemester_kurzbz && + $yesterdays_applicant->bewerbung_abgeschicktamum >= $placement_absolvent->reihungstest_timestamp) + { + $obj = new stdClass(); + $obj->prestudent_id = $yesterdays_applicant->prestudent_id; // prestudent_id of the yesterdays applicant + $obj->studiengang_kz = $yesterdays_applicant->studiengang_kz; // study program of interest of the yesterdays applicant + $obj->reihungstest_id = $placement_absolvent->reihungstest_id; // reihungstest_id of absolved reihungstest of that person - $result_arr[]= $obj; - } - } - } + $result_arr[]= $obj; + } + } + } - // Sort by STG. This is important to send the mails clustered by STG to the different STG assistances. - usort($result_arr, function ($a, $b) - { - if ($a->studiengang_kz == $b->studiengang_kz) { - return 0; - } - return ($a->studiengang_kz < $b->studiengang_kz) ? -1 : 1; - }); + // Sort by STG. This is important to send the mails clustered by STG to the different STG assistances. + usort($result_arr, function ($a, $b) + { + if ($a->studiengang_kz == $b->studiengang_kz) { + return 0; + } + return ($a->studiengang_kz < $b->studiengang_kz) ? -1 : 1; + }); - $to = ''; // mail recipient (stg assistance) - $content_arr = array(); // url paths to the new applicants - $base_link = base_url('vilesci/stammdaten/auswertung_fhtw.php'); + $to = ''; // mail recipient (stg assistance) + $content_arr = array(); // url paths to the new applicants + $base_link = base_url('vilesci/stammdaten/auswertung_fhtw.php'); - $i = 0; // loop counter - $len = count($result_arr); + $i = 0; // loop counter + $len = count($result_arr); - // Loop trough list of new applicants - foreach($result_arr as $result) - { - $studiengang = $this->StudiengangModel->load($result->studiengang_kz); - $mail_stg_assistance = $studiengang->retval[0]->email; + // Loop trough list of new applicants + foreach($result_arr as $result) + { + $studiengang = $this->StudiengangModel->load($result->studiengang_kz); + $mail_stg_assistance = $studiengang->retval[0]->email; - // If first loop - if ($i == 0) - { - $to = $mail_stg_assistance; // set recipient initially - } + // If first loop + if ($i == 0) + { + $to = $mail_stg_assistance; // set recipient initially + } - // If new study is encountered but is not the first loop - if ($to != $mail_stg_assistance && $i != 0) - { - // Prepare content for mail template - $content_data_arr = $this->_getContentDataNewApplicant($content_arr); + // If new study is encountered but is not the first loop + if ($to != $mail_stg_assistance && $i != 0) + { + // Prepare content for mail template + $content_data_arr = $this->_getContentDataNewApplicant($content_arr); - // Send mail - sendSanchoMail( - 'BewerberNachReihungstest', - $content_data_arr, - $to, - 'Neue Bewerbungen nach absolviertem Reihungstest', - 'sancho_header_min_bw.jpg', - 'sancho_footer_min_bw.jpg' - ); + // Send mail + sendSanchoMail( + 'BewerberNachReihungstest', + $content_data_arr, + $to, + 'Neue Bewerbungen nach absolviertem Reihungstest', + 'sancho_header_min_bw.jpg', + 'sancho_footer_min_bw.jpg' + ); - // Reset content for new study applicants & reset recipient (new stg assistance) - $content_arr = array($base_link. '?reihungstest='. $result->reihungstest_id. '&prestudent_id='. $result->prestudent_id); - $to = $mail_stg_assistance; - } - // If same study - else - { - // just add content - $content_arr[]= $base_link. '?reihungstest='. $result->reihungstest_id. '&prestudent_id='. $result->prestudent_id; // add to content - } + // Reset content for new study applicants & reset recipient (new stg assistance) + $content_arr = array($base_link. '?reihungstest='. $result->reihungstest_id. '&prestudent_id='. $result->prestudent_id); + $to = $mail_stg_assistance; + } + // If same study + else + { + // just add content + $content_arr[]= $base_link. '?reihungstest='. $result->reihungstest_id. '&prestudent_id='. $result->prestudent_id; // add to content + } - // If last loop - if (($i == $len - 1)) - { - // Prepare content for mail template - $content_data_arr = $this->_getContentDataNewApplicant($content_arr); + // If last loop + if (($i == $len - 1)) + { + // Prepare content for mail template + $content_data_arr = $this->_getContentDataNewApplicant($content_arr); - // Send mail - sendSanchoMail( - 'BewerberNachReihungstest', - $content_data_arr, - $to, - 'Neue Bewerbungen nach absolviertem Reihungstest', - 'sancho_header_min_bw.jpg', - 'sancho_footer_min_bw.jpg' - ); - } - $i++; // iterate counter - } - } + // Send mail + sendSanchoMail( + 'BewerberNachReihungstest', + $content_data_arr, + $to, + 'Neue Bewerbungen nach absolviertem Reihungstest', + 'sancho_header_min_bw.jpg', + 'sancho_footer_min_bw.jpg' + ); + } + $i++; // iterate counter + } + } - // ------------------------------------------------------------------------ - // Private methods - /** - * Returns associative array with data as needed in the reihungstest job template. - * @param array $missing_rt_arr Array with studienpläne, which have no assigned placement tests. - * @param array $free_places_arr Array with info and amount of free placement test places. - * @return array - */ - private function _getContentData($missing_rt_arr, $free_places_arr) - { - $style_tbl1 = ' cellpadding="0" cellspacing="10" width="100%" style="font-family: courier, verdana, sans-serif; font-size: 0.95em; border: 1px solid #000000;" '; - $style_tbl2 = ' cellpadding="0" cellspacing="20" width="100%" style="font-family: courier, verdana, sans-serif; font-size: 0.95em; border: 1px solid #000000;" '; + // ------------------------------------------------------------------------ + // Private methods + /** + * Returns associative array with data as needed in the reihungstest job template. + * @param array $missing_rt_arr Array with studienpläne, which have no assigned placement tests. + * @param array $free_places_arr Array with info and amount of free placement test places. + * @return array + */ + private function _getContentData($missing_rt_arr, $free_places_arr) + { + $style_tbl1 = ' cellpadding="0" cellspacing="10" width="100%" style="font-family: courier, verdana, sans-serif; font-size: 0.95em; border: 1px solid #000000;" '; + $style_tbl2 = ' cellpadding="0" cellspacing="20" width="100%" style="font-family: courier, verdana, sans-serif; font-size: 0.95em; border: 1px solid #000000;" '; - // Prepare HTML table with study plans that have no placement tests yet - if (!empty($missing_rt_arr)) { - $studienplan_list - = ' + // Prepare HTML table with study plans that have no placement tests yet + if (!empty($missing_rt_arr)) { + $studienplan_list + = ' '; - foreach ($missing_rt_arr as $rt) { - $studienplan_list .= ' + foreach ($missing_rt_arr as $rt) { + $studienplan_list .= ' ' . $rt->bezeichnung . ' '; - } + } - $studienplan_list .= ' + $studienplan_list .= ' '; - } else { - $studienplan_list = ' + } else { + $studienplan_list = ' Alles okay! Alle Studienpläne haben zumindest einen Reihungstest. '; - } + } - // Prepare HTML table with information and amount of free places - if (!empty($free_places_arr)) { - $freie_plaetze_list = ' + // Prepare HTML table with information and amount of free places + if (!empty($free_places_arr)) { + $freie_plaetze_list = ' Fakultät @@ -659,67 +661,67 @@ class ReihungstestJob extends CLI_Controller '; - foreach ($free_places_arr as $free_place) { - $datum = new DateTime($free_place->datum); - $style_alarm = ($free_place->freie_plaetze <= 5) ? ' style=" color: red; font-weight: bold" ' : ''; // mark if <=5 free places + foreach ($free_places_arr as $free_place) { + $datum = new DateTime($free_place->datum); + $style_alarm = ($free_place->freie_plaetze <= 5) ? ' style=" color: red; font-weight: bold" ' : ''; // mark if <=5 free places - $freie_plaetze_list .= ' + $freie_plaetze_list .= ' ' . $free_place->fakultaet . ' ' . $datum->format('d.m.Y') . ' ' . $free_place->freie_plaetze . ' '; - } + } - $freie_plaetze_list .= ' + $freie_plaetze_list .= ' '; - } else { - $freie_plaetze_list = ' + } else { + $freie_plaetze_list = ' Es gibt heute keine Ergebnisse zu freien Reihungstestplätze. '; - } + } - // Set associative array with the prepared HTML tables and URL be used by the template's variables - $content_data_arr['studienplan_list'] = $studienplan_list; - $content_data_arr['freie_plaetze_list'] = $freie_plaetze_list; - $content_data_arr['link'] = site_url('/organisation/Reihungstest'); + // Set associative array with the prepared HTML tables and URL be used by the template's variables + $content_data_arr['studienplan_list'] = $studienplan_list; + $content_data_arr['freie_plaetze_list'] = $freie_plaetze_list; + $content_data_arr['link'] = site_url('/organisation/Reihungstest'); - return $content_data_arr; - } + return $content_data_arr; + } - /** - * Returns associative array with data as needed in the BewerberNachReihungstest-template. - * @param array $content_arr Array with links to the testtool evaluation page of the new applicants. - * @return array - */ - private function _getContentDataNewApplicant($content_arr) - { - $content = ''; - $counter = 1; - foreach ($content_arr as $row) - { - $content .= '
Link zu: Bewerber '. $counter. ''; - $counter++; - } + /** + * Returns associative array with data as needed in the BewerberNachReihungstest-template. + * @param array $content_arr Array with links to the testtool evaluation page of the new applicants. + * @return array + */ + private function _getContentDataNewApplicant($content_arr) + { + $content = ''; + $counter = 1; + foreach ($content_arr as $row) + { + $content .= '
Link zu: Bewerber '. $counter. ''; + $counter++; + } - $content_data_arr['link'] = $content; - return $content_data_arr; - } + $content_data_arr['link'] = $content; + return $content_data_arr; + } - /** - * Checks the upcoming placement tests if there are correct studyplans assigned - * If there are invalid studyplans assigned (outdated because there exists a new version), - * it tries to find a better one and assigns it additionaly - */ - public function correctStudienplan() - { - // get all placement tests with incorrect studyplan - $qry = " + /** + * Checks the upcoming placement tests if there are correct studyplans assigned + * If there are invalid studyplans assigned (outdated because there exists a new version), + * it tries to find a better one and assigns it additionaly + */ + public function correctStudienplan() + { + // get all placement tests with incorrect studyplan + $qry = " SELECT tbl_reihungstest.reihungstest_id, tbl_studienplan.studienplan_id, @@ -752,37 +754,285 @@ class ReihungstestJob extends CLI_Controller ) "; - $db = new DB_Model(); - $result_rt = $db->execReadOnlyQuery($qry); + $db = new DB_Model(); + $result_rt = $db->execReadOnlyQuery($qry); - if (hasdata($result_rt)) { - foreach ($result_rt->retval as $row_rt) { - // find an active studyplan for the same degree program with is valid in this semester - $result_stpl = $this->StudienplanModel->getStudienplaeneBySemester( - $row_rt->studiengang_kz, - $row_rt->studiensemester_kurzbz - ); + if (hasdata($result_rt)) { + foreach ($result_rt->retval as $row_rt) { + // find an active studyplan for the same degree program with is valid in this semester + $result_stpl = $this->StudienplanModel->getStudienplaeneBySemester( + $row_rt->studiengang_kz, + $row_rt->studiensemester_kurzbz + ); - if (hasData($result_stpl)) { - foreach ($result_stpl->retval as $row_stpl) { - // Add new Studyplan to RtStudienplan if missing - $rt_studienplan = $this->RtStudienplanModel->loadWhere(array( - "reihungstest_id" => $row_rt->reihungstest_id, - "studienplan_id" => $row_stpl->studienplan_id - )); + if (hasData($result_stpl)) { + foreach ($result_stpl->retval as $row_stpl) { + // Add new Studyplan to RtStudienplan if missing + $rt_studienplan = $this->RtStudienplanModel->loadWhere(array( + "reihungstest_id" => $row_rt->reihungstest_id, + "studienplan_id" => $row_stpl->studienplan_id + )); - if (!hasData($rt_studienplan)) { - echo "\nAdding StudienplanId: $row_stpl->studienplan_id"; - echo " to ReihungstestId: $row_rt->reihungstest_id"; + if (!hasData($rt_studienplan)) { + echo "\nAdding StudienplanId: $row_stpl->studienplan_id"; + echo " to ReihungstestId: $row_rt->reihungstest_id"; - $this->RtStudienplanModel->insert(array( - "reihungstest_id" => $row_rt->reihungstest_id, - "studienplan_id" => $row_stpl->studienplan_id - )); - } - } - } - } - } - } + $this->RtStudienplanModel->insert(array( + "reihungstest_id" => $row_rt->reihungstest_id, + "studienplan_id" => $row_stpl->studienplan_id + )); + } + } + } + } + } + } + + /* + * Cronjob for priorisation process of FHTW + * + * Wenn ein Student in einer höheren Prio aufgenommen wird, werden die anderen Bewerbungen auf "Abgewiesen" gesetzt, + * solang diese noch im Status "Bewerber" sind. + * Andernfalls wird eine Mail an die niedrigeren Prios verschickt, dass eine höhere Prio aufgenommen hat + * Die Kaution wird automatisch gebucht + * + * @param string $bcc. Optional. BCC-Mailadress to send the Mails to + * @param string $from. Optional. Sender-Mailadress shown to recipient + */ + public function prioritizationJob($bcc = null, $from = null) + { + $qry = " + SELECT DISTINCT + get_rolle_prestudent (tbl_prestudent.prestudent_id, 'WS2020') AS laststatus, /* Studiensemester dynamisch ermitteln oder als Parameter */ + tbl_prestudentstatus.studiensemester_kurzbz, + tbl_prestudent.* + FROM PUBLIC.tbl_person + JOIN PUBLIC.tbl_prestudent USING (person_id) + JOIN PUBLIC.tbl_prestudentstatus USING (prestudent_id) + JOIN lehre.tbl_studienplan USING (studienplan_id) + JOIN lehre.tbl_studienordnung USING (studienordnung_id) + JOIN PUBLIC.tbl_studiengang ON (tbl_studienordnung.studiengang_kz = tbl_studiengang.studiengang_kz) + WHERE tbl_prestudentstatus.datum >= (SELECT CURRENT_DATE -1) + AND get_rolle_prestudent (tbl_prestudent.prestudent_id, 'WS2020') IN ('Aufgenommener','Bewerber','Wartender') + AND studiensemester_kurzbz = 'WS2020' /* Studiensemester dynamisch ermitteln oder als Parameter */ + AND tbl_studiengang.typ = 'b' + ORDER BY studiengang_kz, laststatus + "; + + // Encode Params + if ($bcc != '') + { + // $bcc can be given as null-string, so check that too + if ($bcc == 'null') + { + $bcc = ''; + } + else + { + $bcc = urldecode($bcc); + } + } + if ($from != '') + { + $from = urldecode($from); + } + + $db = new DB_Model(); + $result_prestudents = $db->execReadOnlyQuery($qry); + $mailArray = array(); + + if (hasdata($result_prestudents)) + { + foreach ($result_prestudents->retval as $row_ps) + { + // Wenn der letzte Status "Aufgenommener" ist, alle niedrigeren Prios auf "Abgewiesen" setzen + // falls diese Bewerber oder Warteliste sind + // Danach Kaution einbuchen + if ($row_ps->laststatus == 'Aufgenommener') + { + // Alle niedrigeren Prios laden + $qryNiedrPrios = " + SELECT DISTINCT + get_rolle_prestudent (tbl_prestudent.prestudent_id, '".$row_ps->studiensemester_kurzbz."') AS laststatus, + tbl_studienplan.orgform_kurzbz, + tbl_person.nachname, + tbl_person.vorname, + tbl_prestudent.* + FROM PUBLIC.tbl_person + JOIN PUBLIC.tbl_prestudent USING (person_id) + JOIN PUBLIC.tbl_prestudentstatus USING (prestudent_id) + JOIN lehre.tbl_studienplan USING (studienplan_id) + JOIN PUBLIC.tbl_studiengang ON (tbl_prestudent.studiengang_kz = tbl_studiengang.studiengang_kz) + WHERE tbl_prestudent.person_id = ".$row_ps->person_id." + AND tbl_prestudent.prestudent_id != ".$row_ps->prestudent_id." + AND get_rolle_prestudent (tbl_prestudent.prestudent_id, '".$row_ps->studiensemester_kurzbz."') IN ('Aufgenommener','Bewerber','Wartender') + AND studiensemester_kurzbz = '".$row_ps->studiensemester_kurzbz."' + AND tbl_studiengang.typ = 'b' + AND priorisierung > ".$row_ps->priorisierung." + ORDER BY studiengang_kz, laststatus + "; + + $resultNiedrPrios = $db->execReadOnlyQuery($qryNiedrPrios); + + if (hasdata($resultNiedrPrios)) + { + foreach ($resultNiedrPrios->retval as $rowNiedrPrios) + { + if ($rowNiedrPrios->laststatus == 'Bewerber') + { + // Abgewiesenen-Status mit Statusgrund "Aufnahme anderer Studiengang" (ID 5) setzen + $lastStatus = $this->PrestudentstatusModel->getLastStatus($rowNiedrPrios->prestudent_id); + + $result = $this->PrestudentstatusModel->insert( + array( + 'prestudent_id' => $rowNiedrPrios->prestudent_id, + 'studiensemester_kurzbz' => $lastStatus->retval[0]->studiensemester_kurzbz, + 'ausbildungssemester' => $lastStatus->retval[0]->ausbildungssemester, + 'datum' => date('Y-m-d'), + 'orgform_kurzbz' => $lastStatus->retval[0]->orgform_kurzbz, + 'studienplan_id' => $lastStatus->retval[0]->studienplan_id, + 'status_kurzbz' => 'Abgewiesener', + 'statusgrund_id' => 5, + 'insertvon' => 'prioritizationJob', + 'insertamum' => date('Y-m-d H:i:s') + ) + ); + if (isSuccess($result)) + { + /*$mailArray[$rowNiedrPrios->studiengang_kz][$rowNiedrPrios->orgform_kurzbz]['AbgewiesenGesetzt'][] + = $rowNiedrPrios->nachname.' '.$rowNiedrPrios->vorname.' ('.$rowNiedrPrios->prestudent_id.')';*/ + } + } + elseif ($rowNiedrPrios->laststatus == 'Wartender') + { + // Abgewiesenen-Status mit Statusgrund "Aufnahme anderer Studiengang" (ID 5) setzen + // Mail zur Info an Assistenz schicken + $lastStatus = $this->PrestudentstatusModel->getLastStatus($rowNiedrPrios->prestudent_id); + + $result = $this->PrestudentstatusModel->insert( + array( + 'prestudent_id' => $rowNiedrPrios->prestudent_id, + 'studiensemester_kurzbz' => $lastStatus->retval[0]->studiensemester_kurzbz, + 'ausbildungssemester' => $lastStatus->retval[0]->ausbildungssemester, + 'datum' => date('Y-m-d'), + 'orgform_kurzbz' => $lastStatus->retval[0]->orgform_kurzbz, + 'studienplan_id' => $lastStatus->retval[0]->studienplan_id, + 'status_kurzbz' => 'Abgewiesener', + 'statusgrund_id' => 5, + 'insertvon' => 'prioritizationJob', + 'insertamum' => date('Y-m-d H:i:s') + ) + ); + if (isSuccess($result)) + { + $mailArray[$rowNiedrPrios->studiengang_kz][$rowNiedrPrios->orgform_kurzbz]['AbgewiesenGesetzt'][] + = $rowNiedrPrios->nachname.' '.$rowNiedrPrios->vorname.' ('.$rowNiedrPrios->prestudent_id.')'; + } + } + elseif ($rowNiedrPrios->laststatus == 'Aufgenommener') + { + // Mail zur Info an Assistenz schicken, dass in höherer Prio aufgenommen wurde + $mailArray[$rowNiedrPrios->studiengang_kz][$rowNiedrPrios->orgform_kurzbz]['AufnahmeHoeherePrio'][] + = $rowNiedrPrios->nachname.' '.$rowNiedrPrios->vorname.' ('.$rowNiedrPrios->prestudent_id.')'; + } + } + } + + + // Kaution einbuchen für $row_ps->prestudent_id + // Vorher prüfen, ob schon eine Kaution gebucht ist + // Todo: Betrag automatisch aus tbl_buchungstyp laden + + $qryKautionExists = " + SELECT count(*) as anzahl + FROM public.tbl_konto + WHERE person_id = ".$row_ps->person_id." + AND studiensemester_kurzbz = '".$row_ps->studiensemester_kurzbz."' + AND buchungstyp_kurzbz = 'Kaution'"; + + $resultKautionExists = $db->execReadOnlyQuery($qryKautionExists); + if (hasdata($resultKautionExists)) + { + if ($resultKautionExists->retval[0]->anzahl == '0') + { + // Todo: Zahlungsreferenz generieren (StudiengangsOE+Buchungsnummer) + $this->KontoModel->insert(array( + "person_id" => $row_ps->person_id, + "studiengang_kz" => $row_ps->studiengang_kz, + "studiensemester_kurzbz" => $row_ps->studiensemester_kurzbz, + "betrag" => -150, + "buchungsdatum" => date('Y-m-d'), + "buchungstext" => 'Kaution', + "buchungstyp_kurzbz" => 'Kaution', + "insertvon" => 'prioritizationJob', + "insertamum" => date('Y-m-d H:i:s') + )); + } + } + } + } + } + echo '
', var_dump($mailArray), '
'; + // Mails senden + if (!isEmptyArray($mailArray)) + { + foreach ($mailArray AS $stg=>$orgform) + { + $studiengang = $this->StudiengangModel->load($stg); + + $mailcontent = '

+ Folgende BewerberInnen wurden in einem höher priorisierten Studiengang aufgenommen und haben deshalb einen Status "Abgewiesen" erhalten:

'; + + foreach ($orgform AS $art=>$value) + { + // Orgform nur dazu schreiben, wenn es mehr als Eine gibt + if (count($orgform) > 1) + { + $mailcontent .= '

Orgform '.$art.'

'; + } + if (isset($value['AbgewiesenGesetzt']) && !isEmptyArray($value['AbgewiesenGesetzt'])) + { + $mailcontent .= ' + + '; + sort($value['AbgewiesenGesetzt']); + foreach ($value['AbgewiesenGesetzt'] AS $key=>$bewerber) + { + $mailcontent .= ''; + } + $mailcontent .= '
Zuvor Warteliste
'.$bewerber.'


'; + } + if (isset($value['AufnahmeHoeherePrio']) && !isEmptyArray($value['AufnahmeHoeherePrio'])) + { + $mailcontent .= ' + + '; + sort($value['AufnahmeHoeherePrio']); + foreach ($value['AufnahmeHoeherePrio'] AS $key=>$bewerber) + { + $mailcontent .= ''; + } + $mailcontent .= '
Zuvor BewerberIn
'.$bewerber.'
'; + } + } + + $mailcontent_data_arr['table'] = $mailcontent; + + // Send email in Sancho design + if (!isEmptyString($mailcontent)) + { + sendSanchoMail( + 'Sancho_ReihungstestteilnehmerJob', + $mailcontent_data_arr, + $studiengang->retval[0]->email, + 'Status Abgewiesen gesetzt', + 'sancho_header_min_bw.jpg', + 'sancho_footer_min_bw.jpg', + $from, + '', + $bcc); + } + } + } + } } diff --git a/application/libraries/MessageLib.php b/application/libraries/MessageLib.php index 3a8f133cf..b97ef4bae 100644 --- a/application/libraries/MessageLib.php +++ b/application/libraries/MessageLib.php @@ -26,8 +26,6 @@ class MessageLib const EMAIL_KONTAKT_TYPE = 'email'; // Email kontakt type const SENT_INFO_NEWLINE = '\n'; // tbl_msg_recipient->sentInfo separator - const ALT_OE = 'infocenter'; // alternative organisation unit when no one is found for a presetudent - private $_ci; /** @@ -139,27 +137,31 @@ class MessageLib // Public methods called by a job /** - * Gets all NOT sent messages from DB and sends for each of them the notice email - * Does not return anything, it logs info and errors on CI logs and in tbl_msg_recipient table + * Gets all messages for which notice emails are still not sent from DB and sends for each of them the notice email * Wrapper for _sendNoticeEmail. */ - public function sendAllEmailNotices($numberToSent, $numberPerTimeRange, $emailTimeRange, $emailFromSystem) + public function sendAllEmailNotices($since, $numberToSent, $numberPerTimeRange, $emailTimeRange, $emailFromSystem) { // Overrides MailLib configs with the given parameters $this->_ci->maillib->overrideConfigs($numberToSent, $numberPerTimeRange, $emailTimeRange, $emailFromSystem); - // Retrieves a certain amount of NOT sent messages, the amount is given by maillib->email_number_to_sent - $messagesResult = $this->_ci->RecipientModel->getMessages( - self::EMAIL_KONTAKT_TYPE, - null, - $this->_ci->maillib->getEmailNumberToSent() + // Retrieves a certain amount of NOT sent messages + $messagesResult = $this->_ci->RecipientModel->getNotSentMessages( + $this->_ci->maillib->getEmailNumberToSent(), + $since ); - if (isError($messagesResult)) terminateWithError(getData($messagesResult)); // If an error occurred then log it and terminate + if (isError($messagesResult) || !hasData($messagesResult)) return $messagesResult; - $sendNotice = $this->_sendNoticeEmails(getData($messagesResult)); + // Collects all the message ids in an array + $messageIds = array(); + foreach (getData($messagesResult) as $message) + { + $messageIds[] = $message->message_id; + } - if (isError($sendNotice)) terminateWithError(getData($sendNotice)); // If an error occurred then log it and terminate + // Send'em all + return $this->_sendNoticeEmails($messageIds); } //------------------------------------------------------------------------------------------------------------------ @@ -221,7 +223,7 @@ class MessageLib $this->_ci->load->model('person/Benutzerfunktion_model', 'BenutzerfunktionModel'); // Retrieves organisation units for a user from database - $benutzer = $this->_ci->BenutzerfunktionModel->getByPersonId($sender_id); + $benutzer = $this->_ci->BenutzerfunktionModel->getActiveFunctionsByPersonId($sender_id); if (isSuccess($benutzer)) // if everything is ok { $ouArray = array(); @@ -494,7 +496,7 @@ class MessageLib * Stores the type of error in 'sentinfo' column keeping en eventual previous error * sent column is set to null */ - private function _setSentError($message_id, $receiver_id, $sentInfo, $prevSentInfo) + private function _updatedRecipientNoticeEmailInfo($message_id, $receiver_id, $sentInfo, $prevSentInfo) { if (!isEmptyString($prevSentInfo)) { @@ -759,15 +761,15 @@ class MessageLib if (!$sent) { // Set in database why this email is NOT going to be send - $sse = $this->_setSentError( + $sse = $this->_updatedRecipientNoticeEmailInfo( $messageData->message_id, $messageData->receiver_id, - 'An error occurred while sending the notice email', - $messageData->sentinfo + 'An error occurred while sending the notice email', // current info + $messageData->sentinfo // previous info ); // If database error occurred then return it, otherwise return a logic error - return isError($sse) ? $sse : error('An error occurred while sending the notice email'); + return isError($sse) ? $sse : error('An error occurred while updating the recipient notice email info'); } else // success! { @@ -776,6 +778,27 @@ class MessageLib if (isError($sss)) return $sss; // If database error occurred then return it } } + else // Because was not possible to find a valid contact + { + $reason = 'Was not possible to find a valid contact for this user'; // default reason + + // In case that the organisation unit does not receive any email notices + if (!isEmptyString($messageData->receiver_ou)) $reason = 'This organization unit does not receive email notices'; + + // In case that a degree program sent a message to a user without a valid contact or UID + if (!isEmptyString($messageData->sender_ou)) $reason = 'Sent from a degree program to a user that does not have a valid UID or a valid contact'; + + // Set in database why this email is NOT going to be send + $sse = $this->_updatedRecipientNoticeEmailInfo( + $messageData->message_id, + $messageData->receiver_id, + $reason, // current info + $messageData->sentinfo // previous info + ); + + // If database error occurred then return it + if (isError($sse)) return $sse; + } } return success('Notice emails sent successfully'); diff --git a/application/models/CL/Messages_model.php b/application/models/CL/Messages_model.php index de6ec5a10..cbb42543f 100644 --- a/application/models/CL/Messages_model.php +++ b/application/models/CL/Messages_model.php @@ -26,6 +26,8 @@ class Messages_model extends CI_Model const TYPE_PERSONS = 'persons'; const TYPE_PRESTUDENTS = 'prestudents'; + const ALT_OE = 'infocenter'; // alternative organisation unit when no one is found for a presetudent + /** * Constructor */ @@ -106,7 +108,7 @@ class Messages_model extends CI_Model { $ouOptions .= sprintf( "\n".'', - is_numeric($ou->prestudent_id) ? $ou->oe_kurzbz : MessageLib::ALT_OE, + is_numeric($ou->prestudent_id) ? $ou->oe_kurzbz : self::ALT_OE, $ou->bezeichnung . (is_numeric($ou->prestudent_id) ? '' : ' *') ); } @@ -509,7 +511,8 @@ class Messages_model extends CI_Model if (!hasData($message)) return error('No messages were saved in database'); // Write log entry - $personLog = $this->_personLog($sender_id, $receiver_id, getData($message)[0]); + // NOTE: $receiver_id and $sender_id are switched!!! Currently this is a workaround + $personLog = $this->_personLog($receiver_id, $sender_id, getData($message)[0]); if (isError($personLog)) return $personLog; return success('Messages sent successfully'); diff --git a/application/models/person/Benutzerfunktion_model.php b/application/models/person/Benutzerfunktion_model.php index ceb427687..fb9b51c1a 100644 --- a/application/models/person/Benutzerfunktion_model.php +++ b/application/models/person/Benutzerfunktion_model.php @@ -11,16 +11,20 @@ class Benutzerfunktion_model extends DB_Model $this->dbTable = 'public.tbl_benutzerfunktion'; $this->pk = 'benutzerfunktion_id'; } - + /** * Get the Benutzerfunktion using the person_id */ - public function getByPersonId($person_id) + public function getActiveFunctionsByPersonId($person_id) { - // Join with the table - $this->addJoin('public.tbl_benutzer', 'uid'); - - return $this->loadWhere(array('person_id' => $person_id)); + $query = 'SELECT bf.* + FROM public.tbl_benutzerfunktion bf + JOIN public.tbl_benutzer b USING (uid) + WHERE b.person_id = ? + AND (bf.datum_von IS NULL OR bf.datum_von <= now()) + AND (bf.datum_bis IS NULL OR bf.datum_bis >= now())'; + + return $this->execQuery($query, array($person_id)); } /** diff --git a/application/models/system/Recipient_model.php b/application/models/system/Recipient_model.php index cea11a7a7..d74d03243 100644 --- a/application/models/system/Recipient_model.php +++ b/application/models/system/Recipient_model.php @@ -199,66 +199,24 @@ class Recipient_model extends DB_Model } /** - * getMessages + * Gets all messages for which notice emails are still not sent * - * Gets all the messages to be sent - * - * @param kontaktType specifies the type of the kontakt to get - * @param sent specifies the status of the messages to get (NULL never sent, otherwise the shipping date) - * @param limit specifies the number of messages to get - * @param message_id specifies a single message + * @param kontaktType specifies the type of the kontakt to get (email,...) + * @param limit specifies the max number of messages to get + * @param since specifies from which date messages have to be retrieved */ - public function getMessages($kontaktType, $message_id = null, $limit = 1) + public function getNotSentMessages($limit, $since) { - $query = 'SELECT mm.message_id, - ks.kontakt as sender, - kr.kontakt as receiver, - mu.mitarbeiter_uid as employeeContact, - ms.mitarbeiter_uid as senderemployeeContact, - mr.person_id as receiver_id, - mr.token, - mm.subject, - mm.body, - mr.sentinfo, - mr.oe_kurzbz - FROM public.tbl_msg_recipient mr INNER JOIN public.tbl_msg_message mm USING (message_id) - LEFT JOIN ( - SELECT person_id, kontakt FROM public.tbl_kontakt WHERE zustellung = true AND kontakttyp = ? - ) ks ON (ks.person_id = mm.person_id) - LEFT JOIN ( - SELECT person_id, kontakt FROM public.tbl_kontakt WHERE zustellung = true AND kontakttyp = ? - ) kr ON (kr.person_id = mr.person_id) - LEFT JOIN ( - SELECT b.person_id, - m.mitarbeiter_uid - FROM public.tbl_benutzer b INNER JOIN public.tbl_mitarbeiter m ON(b.uid = m.mitarbeiter_uid) - WHERE b.aktiv = TRUE - ) mu ON (mu.person_id = mr.person_id) - LEFT JOIN ( - SELECT b.person_id, - m.mitarbeiter_uid - FROM public.tbl_benutzer b INNER JOIN public.tbl_mitarbeiter m ON(b.uid = m.mitarbeiter_uid) - WHERE b.aktiv = TRUE - ) ms ON (ms.person_id = mm.person_id) - WHERE mr.sent IS NULL'; + $query = 'SELECT mm.message_id + FROM public.tbl_msg_recipient mr + JOIN public.tbl_msg_message mm USING (message_id) + WHERE mr.sent IS NULL + AND mr.sentinfo IS NULL + AND mm.insertamum > ? + ORDER BY mr.insertamum ASC + LIMIT ?'; - $parametersArray = array($kontaktType, $kontaktType); - - if (is_numeric($message_id)) - { - array_push($parametersArray, $message_id); - $query .= ' AND mm.message_id = ?'; - } - - $query .= ' ORDER BY mr.insertamum ASC'; - - if (is_numeric($limit)) - { - $query .= ' LIMIT ?'; - array_push($parametersArray, $limit); - } - - return $this->execQuery($query, $parametersArray); + return $this->execQuery($query, array($since, $limit)); } /** diff --git a/application/views/system/messages/htmlWriteTemplate.php b/application/views/system/messages/htmlWriteTemplate.php index 64a8c8236..575e9ea07 100644 --- a/application/views/system/messages/htmlWriteTemplate.php +++ b/application/views/system/messages/htmlWriteTemplate.php @@ -129,34 +129,29 @@ -
+
-
-
- +
+
+
widgetlib->widget( 'Dropdown_widget', - array('elements' => success($recipientsArray), 'emptyElement' => 'Select...'), + array('elements' => success($recipientsArray), 'emptyElement' => ucfirst($this->p->t('global', 'empfaenger')).'...'), array( - 'title' => ucfirst($this->p->t('global', 'empfaenger')).': ', 'name' => 'recipients[]', 'id' => 'recipients' ) ); ?> - + + + p->t('ui', 'refresh')); ?> + + +
-

diff --git a/application/widgets/Vorlage_widget.php b/application/widgets/Vorlage_widget.php index 9c9abe430..9ec13250f 100644 --- a/application/widgets/Vorlage_widget.php +++ b/application/widgets/Vorlage_widget.php @@ -63,7 +63,7 @@ class Vorlage_widget extends DropdownWidget FROM tbl_vorlagestudiengang vs INNER JOIN tbl_vorlage v USING(vorlage_kurzbz) ) templates'; $alias = 'templates'; - $fields = array("templates.vorlage_kurzbz AS id", "UPPER(templates.oe_kurzbz) || ' - ' || templates.bezeichnung || ' - V' || templates.version AS description"); + $fields = array("templates.vorlage_kurzbz AS id", "templates.bezeichnung AS description"); $where = 'templates.aktiv = TRUE AND templates.subject IS NOT NULL AND templates.text IS NOT NULL