From 2706a76b46919059d45c77b7ede25c0bba58c29c Mon Sep 17 00:00:00 2001 From: ma0068 Date: Wed, 28 Sep 2022 09:30:23 +0200 Subject: [PATCH] SponsionsJob: Umbau auf eine Abfrage --- application/controllers/jobs/SponsionJob.php | 39 ++++++++----------- application/models/crm/Prestudent_model.php | 37 +++++++++++------- .../education/Abschlusspruefung_model.php | 21 +--------- 3 files changed, 42 insertions(+), 55 deletions(-) diff --git a/application/controllers/jobs/SponsionJob.php b/application/controllers/jobs/SponsionJob.php index 5af16d60b..ef5f6c880 100644 --- a/application/controllers/jobs/SponsionJob.php +++ b/application/controllers/jobs/SponsionJob.php @@ -3,7 +3,7 @@ * FH-Complete * * - * Cronjobs to be run for inserting the date of Sponsion as Date ZGV of absolvents + * Cronjobs to be run for inserting the date of Sponsion as Date ZGV */ // ------------------------------------------------------------------------ @@ -25,33 +25,28 @@ class SponsionJob extends JOB_Controller public function insertDate() { - $allAbsolventsWithDateSponsion = $this->AbschlusspruefungModel->getAbsolventsWithSponsionDate()->retval; - $count = 0; $countBewerbungen = 0; + //Bewerbungen vom aktuellen Semester + nächstes Semester berücksichtigen + $date_actual = new DateTime('first day of this month midnight'); // date obj of actual date + $month = $date_actual->format('m'); // string month of actual timesheet + $year = $date_actual->format('Y'); // string year of actual timesheet + $nextYear = $year+1; + print_r("-----------------------------------------------------------------\n"); - print_r("Cronjob START\n"); - print_r("Sponsionsdatum als ZGV-Datum eintragen:\n"); + $semester1 = "WS" . $year; + $semester2 = ($month>= 6) ? "SS" . $nextYear : "SS" . $year; - foreach ($allAbsolventsWithDateSponsion as $absolvent) - { - $this->AbschlusspruefungModel->insertDatumSponsionAsZgvmadatum($absolvent->prestudent_id, $absolvent->sponsion); + $allInteressenten = $this->PrestudentModel->getAllInteressentenWithMasterSponsion($semester1, $semester2)->retval; - //get all prestudents of person_id with Status Interessent - $allBewerbungen = $this->PrestudentModel->getPrestudentsOfPersonId($absolvent->person_id, 'Interessent')->retval; - foreach ($allBewerbungen as $bewerbung) - { - $this->AbschlusspruefungModel->insertDatumSponsionAsZgvmadatum($bewerbung->prestudent_id, $absolvent->sponsion); - print_r (" Bewerbung: personId: " . $absolvent->person_id . " prestudentId: " . $bewerbung->prestudent_id. " DateSponsion: " . $absolvent->sponsion."\n"); - $countBewerbungen++; - } - $count++; - } + foreach($allInteressenten as $interessent) + { + $this->AbschlusspruefungModel->insertDatumSponsionAsZgvmadatum($interessent->prestudent_id, $interessent->sponsion); + $countBewerbungen++; + } - print_r("\nAnzahl Absolventen: " . $count); - print_r("\nAnzahl Inserts Bewerbungen: " . $countBewerbungen); - print_r("\nCronjob END\n"); - print_r("-----------------------------------------------------------------\n"); + print_r("Anzahl Inserts Bewerbungen: " . $countBewerbungen); + print_r("\n-----------------------------------------------------------------\n"); return true; } diff --git a/application/models/crm/Prestudent_model.php b/application/models/crm/Prestudent_model.php index 14009c4fb..f5dfceb21 100644 --- a/application/models/crm/Prestudent_model.php +++ b/application/models/crm/Prestudent_model.php @@ -667,25 +667,36 @@ class Prestudent_model extends DB_Model return $this->execQuery($query, array($prestudent_id)); } + /** - * get all prestudents of a Person_id with certain status - * @param $personId - * @param $prestudentStatus - * @return array all prestudents of the person (with certain status) + * get all Interessenten without ZGVmasdatum and with Sponsionsdate + * @param $semesterkurzbz1 und $semesterkurzbz2 + * @return array all prestudents with sponsionsdate */ - public function getPrestudentsOfPersonId($personId, $prestudentStatus) + public function getAllInteressentenWithMasterSponsion($semesterkurzbz1, $semesterkurzbz2=null) { return $this->execQuery( - 'SELECT prestudent_id - FROM public.tbl_prestudent - JOIN public.tbl_prestudentstatus USING (prestudent_id) - WHERE person_id = ? - AND get_rolle_prestudent(prestudent_id, null) = ?', + 'SELECT ps.prestudent_id, person_id, ap.sponsion + FROM + public.tbl_prestudent ps + JOIN public.tbl_prestudentstatus USING(prestudent_id) + JOIN public.tbl_person p USING (person_id) + JOIN public.tbl_prestudent ps2 USING (person_id) + JOIN public.tbl_student st ON (st.prestudent_id = ps2.prestudent_id) + JOIN lehre.tbl_abschlusspruefung ap USING (student_uid) + JOIN public.tbl_studiengang sg ON (sg.studiengang_kz = ps2.studiengang_kz) + WHERE + get_rolle_prestudent(ps.prestudent_id, null) = \'Interessent\' + AND ps.zgvmadatum is NULL + AND get_rolle_prestudent(ps2.prestudent_id, null) = \'Absolvent\' + AND sg.typ != \'l\' + AND tbl_prestudentstatus.studiensemester_kurzbz in (?,?)', array( - $personId, - $prestudentStatus + $semesterkurzbz1, + $semesterkurzbz2 ) - ); + ); } + } diff --git a/application/models/education/Abschlusspruefung_model.php b/application/models/education/Abschlusspruefung_model.php index 3de2aac03..8ad6a3343 100644 --- a/application/models/education/Abschlusspruefung_model.php +++ b/application/models/education/Abschlusspruefung_model.php @@ -114,27 +114,8 @@ class Abschlusspruefung_model extends DB_Model return success($abschlusspruefungdata); } -/** -* get all Absolvents with a Date Sponsion without filled master zgv field -*/ - public function getAbsolventsWithSponsionDate() - { - $qry = "SELECT ps.prestudent_id, ap.sponsion, p.person_id - FROM lehre.tbl_abschlusspruefung ap - JOIN public.tbl_student st USING (student_uid) - JOIN public.tbl_prestudent ps USING (prestudent_id) - JOIN public.tbl_prestudentstatus pstatus USING (prestudent_id) - JOIN public.tbl_person p USING (person_id) - JOIN public.tbl_studiengang sg ON (sg.studiengang_kz = ps.studiengang_kz) - WHERE ap.sponsion < now() - AND ps.zgvmadatum is NULL - AND pstatus.status_kurzbz in ('Absolvent') - AND sg.typ != 'l' - ORDER BY ap.Sponsion DESC"; - return $this->execQuery($qry); - } - /** +/** * update ZGV Master */ public function insertDatumSponsionAsZgvmadatum($prestudentId, $datumSponsion)