From 53de29f3d29386b0494a88ac90efe5938ca2b5e9 Mon Sep 17 00:00:00 2001 From: Johann Hoffmann Date: Mon, 9 Dec 2024 17:13:23 +0100 Subject: [PATCH] stundeplan_model byLva() query when providing lv_id irrespective of student, group, lector etc just fetch all & show them --- .../api/frontend/v1/Stundenplan.php | 19 +++++-- .../models/ressource/Stundenplan_model.php | 56 ++++++++++++++++++- application/views/Cis/MyLv.php | 1 + application/views/Cis/Stundenplan.php | 1 + public/js/api/stundenplan.js | 4 +- public/js/apps/Cis/Stundenplan.js | 12 ++-- 6 files changed, 79 insertions(+), 14 deletions(-) diff --git a/application/controllers/api/frontend/v1/Stundenplan.php b/application/controllers/api/frontend/v1/Stundenplan.php index c14ea4315..a087f32a0 100644 --- a/application/controllers/api/frontend/v1/Stundenplan.php +++ b/application/controllers/api/frontend/v1/Stundenplan.php @@ -126,24 +126,33 @@ class Stundenplan extends FHCAPI_Controller // storing the get parameter in local variables $start_date = $this->input->get('start_date', TRUE); $end_date = $this->input->get('end_date', TRUE); + $lv_id = $this->input->get('lv_id', TRUE); $student_uid = getAuthUID(); if(is_null($student_uid)) { $this->terminateWithError("No UID"); } + + $semester_range = $this->studienSemesterErmitteln($start_date,$end_date); + $this->sortStudienSemester($semester_range); + $this->applyLoadUeberSemesterHaelfte($semester_range); + + if($lv_id) { // fetch Stundenplan for lva, irrelevant of who is requesting it (for now) + $stundenplan_data = $this->StundenplanModel->getStundenplanLVA($start_date, $end_date, $lv_id); + $stundenplan_data = $this->getDataOrTerminateWithError($stundenplan_data) ?? []; + $this->expand_object_information($stundenplan_data); + $this->terminateWithSuccess($stundenplan_data); + + } + $is_mitarbeiter = getData($this->MitarbeiterModel->isMitarbeiter($student_uid)); if($is_mitarbeiter) { $this->terminateWithError("Not possible to look at the Student Calendar as a Mitarbeiter"); } - $semester_range = $this->studienSemesterErmitteln($start_date,$end_date); - - $this->sortStudienSemester($semester_range); - - $this->applyLoadUeberSemesterHaelfte($semester_range); // getting the gruppen_kurzbz of the student in the different studiensemester $benutzer_gruppen = $this->fetchBenutzerGruppenFromStudiensemester($semester_range); diff --git a/application/models/ressource/Stundenplan_model.php b/application/models/ressource/Stundenplan_model.php index 8cb07a3bb..909892674 100644 --- a/application/models/ressource/Stundenplan_model.php +++ b/application/models/ressource/Stundenplan_model.php @@ -186,9 +186,63 @@ class Stundenplan_model extends DB_Model return $query_result; } + /** + * queries Stundenplan but for a whole lva, irrespective of who is requesting it + * + * @return void + */ + public function getStundenplanLVA($start_date, $end_date, $lv_id) { + return $this->execReadOnlyQuery(" + + SELECT + 'lehreinheit' as type, beginn, ende, datum, + CONCAT(lehrfach,'-',lehrform) as topic, + array_agg(DISTINCT lektor) as lektor, + array_agg(DISTINCT (gruppe,verband,semester,studiengang_kz,gruppen_kuerzel)) as gruppe, + string_agg(DISTINCT ort_kurzbz, '/') as ort_kurzbz, + array_agg(DISTINCT lehreinheit_id) as lehreinheit_id, + + titel, lehrfach, lehrform, lehrfach_bez, organisationseinheit, farbe, lehrveranstaltung_id + + FROM + ( + SELECT unr,datum,beginn, ende, + CASE + WHEN sp.mitarbeiter_kurzbz IS NOT NULL THEN sp.mitarbeiter_kurzbz + ELSE lektor + END as lektor, + CASE + WHEN gruppe_kurzbz IS NOT NULL THEN gruppe_kurzbz + ELSE CONCAT(UPPER(sp.stg_typ),UPPER(sp.stg_kurzbz),'-',COALESCE(CAST(sp.semester AS varchar),'/'),COALESCE(CAST(sp.verband AS varchar),'/')) + END as gruppen_kuerzel, + (SELECT bezeichnung + FROM public.tbl_organisationseinheit + WHERE oe_kurzbz IN( + SELECT oe_kurzbz + FROM lehre.tbl_lehrveranstaltung + WHERE lehrveranstaltung_id = sp.lehrveranstaltung_id + )) as organisationseinheit, + ort_kurzbz, studiengang_kz, titel,lehreinheit_id,lehrfach_id,anmerkung,fix,lehrveranstaltung_id,stg_kurzbzlang,stg_bezeichnung,stg_typ,fachbereich_kurzbz,lehrfach,lehrfach_bez,farbe,lehrform,anmerkung_lehreinheit,gruppe, verband, semester,stg_kurzbz + + FROM ( + SELECT sp.* + FROM lehre.vw_stundenplan sp + WHERE + sp.datum >= ? + AND sp.datum <= ? AND sp.lehrveranstaltung_id = ? + ) sp + JOIN lehre.tbl_stunde ON lehre.tbl_stunde.stunde = sp.stunde + + ) as subquery + + GROUP BY unr, datum, beginn, ende, ort_kurzbz, titel, lehrform, lehrfach, lehrfach_bez, organisationseinheit, farbe, lehrveranstaltung_id + + ORDER BY datum, beginn + ", [$start_date, $end_date, $lv_id]); + } + /** * NO STANDALONE FUNCTION - Generates a SQL query string to fetch 'stundenplan' events for a specific student within the current semester. - * @param string $uid the user id that is used to fetch the stundenplan rows from the lehre.vw_stundenplan table * * @return mixed */ diff --git a/application/views/Cis/MyLv.php b/application/views/Cis/MyLv.php index d8d5026a1..3bac4e294 100644 --- a/application/views/Cis/MyLv.php +++ b/application/views/Cis/MyLv.php @@ -1,6 +1,7 @@ 'MyLv', + 'primevue3' => true, 'customJSModules' => ['public/js/apps/Cis/MyLv/Student.js'], 'customCSSs' => ['public/css/components/MyLv.css'] ); diff --git a/application/views/Cis/Stundenplan.php b/application/views/Cis/Stundenplan.php index bfab73109..965707205 100644 --- a/application/views/Cis/Stundenplan.php +++ b/application/views/Cis/Stundenplan.php @@ -1,6 +1,7 @@ 'Stundenplan', + 'primevue3' => true, 'customJSModules' => ['public/js/apps/Cis/Stundenplan.js'], 'customCSSs' => ['public/css/components/calendar.css'] ); diff --git a/public/js/api/stundenplan.js b/public/js/api/stundenplan.js index 0d9fad810..0b756253c 100644 --- a/public/js/api/stundenplan.js +++ b/public/js/api/stundenplan.js @@ -6,10 +6,10 @@ export default { { ort_kurzbz, start_date, end_date} ); }, - getStundenplan(start_date, end_date) { + getStundenplan(start_date, end_date, lv_id) { return this.$fhcApi.get( '/api/frontend/v1/Stundenplan/getStundenplan', - { start_date, end_date } + { start_date, end_date, lv_id } ); }, getStunden() { diff --git a/public/js/apps/Cis/Stundenplan.js b/public/js/apps/Cis/Stundenplan.js index afe400c82..4fe7c656a 100644 --- a/public/js/apps/Cis/Stundenplan.js +++ b/public/js/apps/Cis/Stundenplan.js @@ -10,7 +10,6 @@ const app = Vue.createApp({ name: 'StundenplanApp', data() { return { - lv_id: null, events: null, calendarDate: new CalendarDate(new Date()), currentlySelectedEvent: null, @@ -22,6 +21,11 @@ const app = Vue.createApp({ FhcCalendar, LvModal, LvMenu, LvInfo }, computed:{ + lv_id() { // computed so we can theoretically change path/lva selection and reload without page refresh + const pathParts = window.location.pathname.split('/').filter(Boolean); + const id = pathParts[pathParts.length - 1]; + return id && !isNaN(Number(id)) ? id : null; // only return id if it is a number string since the path might contain invalid elements + }, weekFirstDay: function () { return this.calendarDateToString(this.calendarDate.cdFirstDayOfWeek); }, @@ -40,9 +44,6 @@ const app = Vue.createApp({ setSelectedEvent: function (event) { this.currentlySelectedEvent = event; }, - getLvID: function () { - this.lv_id = window.location.pathname - }, selectDay: function(day){ this.currentDay = day; }, @@ -76,7 +77,7 @@ const app = Vue.createApp({ }, loadEvents: function(){ Promise.allSettled([ - this.$fhcApi.factory.stundenplan.getStundenplan(this.monthFirstDay, this.monthLastDay), + this.$fhcApi.factory.stundenplan.getStundenplan(this.monthFirstDay, this.monthLastDay, this.lv_id), this.$fhcApi.factory.stundenplan.getStundenplanReservierungen(this.monthFirstDay, this.monthLastDay) ]).then((result) => { let promise_events = []; @@ -110,7 +111,6 @@ const app = Vue.createApp({ created() { this.loadEvents(); - this.getLvID(); }, template:/*html*/`

{{$p.t('lehre/stundenplan')}}