From 186e9e6f0848dc39be2885feba69b0cfb8f690cd Mon Sep 17 00:00:00 2001 From: SimonGschnell Date: Tue, 21 May 2024 15:56:18 +0200 Subject: [PATCH 01/34] WIP room planning in calendar --- application/controllers/CisVue/Cms.php | 4 ++ .../components/Cis/Stundenplan.php | 13 +++- .../models/ressource/Stundenplan_model.php | 12 ++++ .../models/ressource/Stundenplandev_model.php | 2 + .../views/CisVue/Cms/RoomInformation.php | 17 ++++++ public/js/apps/Cis/RoomInformation.js | 61 +++++++++++++++++++ 6 files changed, 108 insertions(+), 1 deletion(-) create mode 100644 application/views/CisVue/Cms/RoomInformation.php create mode 100644 public/js/apps/Cis/RoomInformation.js diff --git a/application/controllers/CisVue/Cms.php b/application/controllers/CisVue/Cms.php index 2c1fa1fc6..f8bd61a7b 100755 --- a/application/controllers/CisVue/Cms.php +++ b/application/controllers/CisVue/Cms.php @@ -115,4 +115,8 @@ class Cms extends FHC_Controller show_error("News number rows: No data found"); } } + + public function getRoomInformation(){ + $this->load->view('CisVue/Cms/RoomInformation'); + } } diff --git a/application/controllers/components/Cis/Stundenplan.php b/application/controllers/components/Cis/Stundenplan.php index 2b35e11ca..2ec001843 100755 --- a/application/controllers/components/Cis/Stundenplan.php +++ b/application/controllers/components/Cis/Stundenplan.php @@ -16,7 +16,8 @@ class Stundenplan extends Auth_Controller parent::__construct([ 'index' => ['student/anrechnung_beantragen:r','user:r'], // TODO(chris): permissions? 'Reservierungen' => ['student/anrechnung_beantragen:r','user:r'], // TODO(chris): permissions? - 'Stunden' => ['student/anrechnung_beantragen:r','user:r'] // TODO(chris): permissions? + 'Stunden' => ['student/anrechnung_beantragen:r','user:r'], // TODO(chris): permissions? + 'RoomInformation'=> ['student/anrechnung_beantragen:r','user:r'], ]); } @@ -65,4 +66,14 @@ class Stundenplan extends Auth_Controller $this->outputJsonSuccess(getData($result)); } + public function RoomInformation() + { + $this->load->model('ressource/Stundenplan_model', 'StundenplanModel'); + + $result = $this->StundenplanModel->getRoomDataOnDay('EDV_A2.06','2024-05-21'); + //echo($this->db->last_query()); + echo json_encode($result); + + } + } diff --git a/application/models/ressource/Stundenplan_model.php b/application/models/ressource/Stundenplan_model.php index 5ec6ea302..4d0a7893b 100755 --- a/application/models/ressource/Stundenplan_model.php +++ b/application/models/ressource/Stundenplan_model.php @@ -12,6 +12,18 @@ class Stundenplan_model extends DB_Model $this->pk = 'stundenplan_id'; } + /** + * @param string $ort_kurzbz + * @param string $date + * + * @return stdClass + */ + public function getRoomDataOnDay($ort_kurzbz,$date){ + $res = $this->loadWhere(['ort_kurzbz'=>$ort_kurzbz,'datum'=>$date]); + $res = hasData($res) ? getData($res): null; + return $res; + } + /** * @param string $uid * diff --git a/application/models/ressource/Stundenplandev_model.php b/application/models/ressource/Stundenplandev_model.php index a498e209b..800540d60 100755 --- a/application/models/ressource/Stundenplandev_model.php +++ b/application/models/ressource/Stundenplandev_model.php @@ -12,6 +12,8 @@ class Stundenplandev_model extends DB_Model $this->pk = 'stundenplandev_id'; } + + public function getMissingDirectGroups($studiensemester_kurzbz = null) { $qry = " diff --git a/application/views/CisVue/Cms/RoomInformation.php b/application/views/CisVue/Cms/RoomInformation.php new file mode 100644 index 000000000..c14b68024 --- /dev/null +++ b/application/views/CisVue/Cms/RoomInformation.php @@ -0,0 +1,17 @@ + 'RoomInformation', + 'customJSModules' => ['public/js/apps/Cis/RoomInformation.js'], + 'customCSSs' => ['public/css/components/calendar.css'] +); + +$this->load->view('templates/CISHTML-Header', $includesArray); +?> + +
+

Room Information

+
+
+
+ +load->view('templates/CISHTML-Footer', $includesArray); ?> diff --git a/public/js/apps/Cis/RoomInformation.js b/public/js/apps/Cis/RoomInformation.js new file mode 100644 index 000000000..63587d2d1 --- /dev/null +++ b/public/js/apps/Cis/RoomInformation.js @@ -0,0 +1,61 @@ +import FhcCalendar from "../../components/Calendar/Calendar.js"; + +const app = Vue.createApp({ + components: { + FhcCalendar + }, + data() { + return { + stunden: [], + events: null + } + }, + created() { + axios.get(FHC_JS_DATA_STORAGE_OBJECT.app_root + FHC_JS_DATA_STORAGE_OBJECT.ci_router + '/components/Cis/Stundenplan/Stunden').then(res => { + + + res.data.retval.forEach(std => { + this.stunden[std.stunde] = std; // TODO(chris): geht besser + }); + console.log("this are the loaded stunden", this.stunden) + }); + + axios.get(FHC_JS_DATA_STORAGE_OBJECT.app_root + FHC_JS_DATA_STORAGE_OBJECT.ci_router + '/components/Cis/Stundenplan').then(res => { + + let events; + if (res.data.retval && res.data.retval.forEach) { + res.data.retval.forEach((el, i) => { + el.id = i; + el.color = '#' + (el.farbe || 'CCCCCC'); + el.start = new Date(el.datum + ' ' + this.stunden[el.stunde].beginn); + el.end = new Date(el.datum + ' ' + this.stunden[el.stunde].ende); + el.title = el.lehrfach; + if (el.lehrform) + el.title += '-' + el.lehrform; + }); + events = res.data.retval; + } + + console.log("this are the loaded events",events) + // TODO(chris): do we need that + + }).catch((e)=>{console.log(e,"this is the exception")}) + + + axios.get(FHC_JS_DATA_STORAGE_OBJECT.app_root + FHC_JS_DATA_STORAGE_OBJECT.ci_router + '/components/Cis/Stundenplan/RoomInformation').then(res => { + console.log(res) + console.log("this string got printed after the get was successfully finished") + }).catch((e)=>{console.log(e,"this is the exception")}) + + + + }, + template: /*html*/` +
+ + +
+ `, +}); +app.config.unwrapInjectedRef = true; +app.mount('#content'); \ No newline at end of file From 729509a45d7ef09ccf71e548a880f0c50e256641 Mon Sep 17 00:00:00 2001 From: SimonGschnell Date: Thu, 23 May 2024 15:40:23 +0200 Subject: [PATCH 02/34] WIP --- .../components/Cis/Stundenplan.php | 3 ++ .../models/ressource/Stundenplan_model.php | 14 +++++++- public/js/apps/Cis/RoomInformation.js | 36 ++++++++++++++----- public/js/components/Calendar/Week/Page.js | 16 +++++++-- 4 files changed, 57 insertions(+), 12 deletions(-) diff --git a/application/controllers/components/Cis/Stundenplan.php b/application/controllers/components/Cis/Stundenplan.php index 2ec001843..3ca8bbc2e 100755 --- a/application/controllers/components/Cis/Stundenplan.php +++ b/application/controllers/components/Cis/Stundenplan.php @@ -70,6 +70,9 @@ class Stundenplan extends Auth_Controller { $this->load->model('ressource/Stundenplan_model', 'StundenplanModel'); + + + $result = $this->StundenplanModel->getRoomDataOnDay('EDV_A2.06','2024-05-21'); //echo($this->db->last_query()); echo json_encode($result); diff --git a/application/models/ressource/Stundenplan_model.php b/application/models/ressource/Stundenplan_model.php index 4d0a7893b..b566b0325 100755 --- a/application/models/ressource/Stundenplan_model.php +++ b/application/models/ressource/Stundenplan_model.php @@ -19,9 +19,21 @@ class Stundenplan_model extends DB_Model * @return stdClass */ public function getRoomDataOnDay($ort_kurzbz,$date){ + + + $this->addSelect(['*',"CONCAT(UPPER(sp.stg_typ),UPPER(sp.stg_kurzbz),'-',COALESCE(CAST(sp.semester AS varchar),'/'),COALESCE(CAST(sp.verband AS varchar),'/')) as eintrag","lektor","CONCAT(lehrfach,'-',lehrform)"]); + /* $this->addSelect(["lehre.tbl_stundenplan.*","CONCAT(UPPER(sg.typ),UPPER(sg.kurzbz),'-',lehre.tbl_stundenplan.semester,lehre.tbl_stundenplan.verband) as simml"]); + $this->addJoin("public.tbl_lehrverband as lv","lv.studiengang_kz=lehre.tbl_stundenplan.studiengang_kz AND lv.gruppe=lehre.tbl_stundenplan.gruppe AND lv.verband=lehre.tbl_stundenplan.verband AND lv.semester=lehre.tbl_stundenplan.semester","LEFT"); + $this->addJoin("public.tbl_studiengang as sg","sg.studiengang_kz=lehre.tbl_stundenplan.studiengang_kz","LEFT"); $res = $this->loadWhere(['ort_kurzbz'=>$ort_kurzbz,'datum'=>$date]); $res = hasData($res) ? getData($res): null; - return $res; + return $res; */ + $this->db->where('ort_kurzbz','EDV_A2.06',true); + $this->db->where('datum','2024-05-21',true); + + $query = $this->db->get_compiled_select('lehre.vw_stundenplan sp'); + + return $this->execQuery($query, [$ort_kurzbz, $date]); } /** diff --git a/public/js/apps/Cis/RoomInformation.js b/public/js/apps/Cis/RoomInformation.js index 63587d2d1..adb571047 100644 --- a/public/js/apps/Cis/RoomInformation.js +++ b/public/js/apps/Cis/RoomInformation.js @@ -7,7 +7,8 @@ const app = Vue.createApp({ data() { return { stunden: [], - events: null + events: null, + testDate: new Date('2024-05-21'), } }, created() { @@ -18,11 +19,33 @@ const app = Vue.createApp({ this.stunden[std.stunde] = std; // TODO(chris): geht besser }); console.log("this are the loaded stunden", this.stunden) + + axios.get(FHC_JS_DATA_STORAGE_OBJECT.app_root + FHC_JS_DATA_STORAGE_OBJECT.ci_router + '/components/Cis/Stundenplan/RoomInformation').then(res => { + let events; + console.log(" this is the res of the api call room information",res); + if (res.data && res.data.forEach) { + res.data.forEach((el, i) => { + + console.log(el,"this is the element that gets changed") + el.id = i; + el.color = '#' + (el.farbe || 'CCCCCC'); + el.start = new Date(el.datum + ' ' + this.stunden[el.stunde].beginn); + el.end = new Date(el.datum + ' ' + this.stunden[el.stunde].ende); + el.title = el.lehrfach; + if (el.lehrform) + el.title += '-' + el.lehrform; + }); + events = res.data; + //console.log("this are the room events",events) + //this.events = events; + } + }).catch((e)=>{console.log(e,"this is the exception")}) }); axios.get(FHC_JS_DATA_STORAGE_OBJECT.app_root + FHC_JS_DATA_STORAGE_OBJECT.ci_router + '/components/Cis/Stundenplan').then(res => { let events; + console.log(" this is the res of the api call stundenplan",res); if (res.data.retval && res.data.retval.forEach) { res.data.retval.forEach((el, i) => { el.id = i; @@ -34,18 +57,15 @@ const app = Vue.createApp({ el.title += '-' + el.lehrform; }); events = res.data.retval; + console.log("this are the events of the stundenplan",events) } - console.log("this are the loaded events",events) // TODO(chris): do we need that - }).catch((e)=>{console.log(e,"this is the exception")}) + }).catch((e)=>{console.log(e,"this is the exception")}) - axios.get(FHC_JS_DATA_STORAGE_OBJECT.app_root + FHC_JS_DATA_STORAGE_OBJECT.ci_router + '/components/Cis/Stundenplan/RoomInformation').then(res => { - console.log(res) - console.log("this string got printed after the get was successfully finished") - }).catch((e)=>{console.log(e,"this is the exception")}) + @@ -53,7 +73,7 @@ const app = Vue.createApp({ template: /*html*/`
- +
`, }); diff --git a/public/js/components/Calendar/Week/Page.js b/public/js/components/Calendar/Week/Page.js index 47d48b7f7..ce86f36bd 100755 --- a/public/js/components/Calendar/Week/Page.js +++ b/public/js/components/Calendar/Week/Page.js @@ -28,7 +28,8 @@ export default { }, computed: { days() { - let tmpDate = new CalendarDate(this.year, 1, 1); // NOTE(chris): somewhere in the middle of the year + + let tmpDate = new CalendarDate(this.year,1,1); // NOTE(chris): somewhere in the middle of the year tmpDate.w = this.week; let startDay = tmpDate.firstDayOfWeek; let result = []; @@ -36,9 +37,11 @@ export default { result.push(new Date(startDay.getFullYear(), startDay.getMonth(), startDay.getDate() + i)); } return result; + }, eventsPerDayAndHour() { const res = {}; + console.log("this are the days",this.days) this.days.forEach(day => { let key = day.toDateString(); @@ -46,6 +49,7 @@ export default { nextDay.setDate(nextDay.getDate()+1); nextDay.setMilliseconds(nextDay.getMilliseconds()-1); let d = {events:[],lanes:1}; + console.log("this are the events",this.events, "and this is the key",key) if (this.events[key]) { this.events[key].forEach(evt => { let event = {orig:evt,lane:1,maxLane:1,start: evt.start < day ? day : evt.start, end: evt.end > nextDay ? nextDay : evt.end,shared:[],setSharedMaxRecursive(doneItems) { @@ -75,6 +79,9 @@ export default { } }, methods: { + printTest:function(param){ + console.log("HERE",param) + }, changeToMonth(day) { if (!this.noMonthView) { this.date.set(day); @@ -91,6 +98,7 @@ export default { }, template: `
+
@@ -104,8 +112,10 @@ export default {
{{hour}}:00
From 39321dcde378b8a3c0aac0e661c17ea73af93006 Mon Sep 17 00:00:00 2001 From: SimonGschnell Date: Fri, 31 May 2024 12:28:06 +0200 Subject: [PATCH 03/34] adds the roomInformation Calendar to the menu and uses different template for the calendar page slot --- .../controllers/components/Cis/Stundenplan.php | 1 + application/models/content/Content_model.php | 9 +++++++++ application/models/ressource/Stundenplan_model.php | 4 ++-- public/js/apps/Cis/RoomInformation.js | 14 ++++++++++---- public/js/components/Calendar/Week/Page.js | 2 +- 5 files changed, 23 insertions(+), 7 deletions(-) diff --git a/application/controllers/components/Cis/Stundenplan.php b/application/controllers/components/Cis/Stundenplan.php index 3ca8bbc2e..e0c163bac 100755 --- a/application/controllers/components/Cis/Stundenplan.php +++ b/application/controllers/components/Cis/Stundenplan.php @@ -74,6 +74,7 @@ class Stundenplan extends Auth_Controller $result = $this->StundenplanModel->getRoomDataOnDay('EDV_A2.06','2024-05-21'); + $result = hasData($result) ? getData($result) : []; //echo($this->db->last_query()); echo json_encode($result); diff --git a/application/models/content/Content_model.php b/application/models/content/Content_model.php index ed447b36a..f42a395f9 100755 --- a/application/models/content/Content_model.php +++ b/application/models/content/Content_model.php @@ -165,6 +165,15 @@ class Content_model extends DB_Model "menu_open": false, "aktiv": true, "childs": [] + }, + { + "content_id": 1000008, + "template_kurzbz": "redirect", + "titel": "room information (to delete)", + "content": "", + "menu_open": false, + "aktiv": true, + "childs": [] } ] diff --git a/application/models/ressource/Stundenplan_model.php b/application/models/ressource/Stundenplan_model.php index b566b0325..f67eab166 100755 --- a/application/models/ressource/Stundenplan_model.php +++ b/application/models/ressource/Stundenplan_model.php @@ -21,7 +21,7 @@ class Stundenplan_model extends DB_Model public function getRoomDataOnDay($ort_kurzbz,$date){ - $this->addSelect(['*',"CONCAT(UPPER(sp.stg_typ),UPPER(sp.stg_kurzbz),'-',COALESCE(CAST(sp.semester AS varchar),'/'),COALESCE(CAST(sp.verband AS varchar),'/')) as eintrag","lektor","CONCAT(lehrfach,'-',lehrform)"]); + $this->addSelect(['*',"CONCAT(UPPER(sp.stg_typ),UPPER(sp.stg_kurzbz),'-',COALESCE(CAST(sp.semester AS varchar),'/'),COALESCE(CAST(sp.verband AS varchar),'/')) as stg","lektor","CONCAT(lehrfach,'-',lehrform) as lv_info" ]); /* $this->addSelect(["lehre.tbl_stundenplan.*","CONCAT(UPPER(sg.typ),UPPER(sg.kurzbz),'-',lehre.tbl_stundenplan.semester,lehre.tbl_stundenplan.verband) as simml"]); $this->addJoin("public.tbl_lehrverband as lv","lv.studiengang_kz=lehre.tbl_stundenplan.studiengang_kz AND lv.gruppe=lehre.tbl_stundenplan.gruppe AND lv.verband=lehre.tbl_stundenplan.verband AND lv.semester=lehre.tbl_stundenplan.semester","LEFT"); $this->addJoin("public.tbl_studiengang as sg","sg.studiengang_kz=lehre.tbl_stundenplan.studiengang_kz","LEFT"); @@ -29,7 +29,7 @@ class Stundenplan_model extends DB_Model $res = hasData($res) ? getData($res): null; return $res; */ $this->db->where('ort_kurzbz','EDV_A2.06',true); - $this->db->where('datum','2024-05-21',true); + $this->db->where('datum >=','2024-05-21',true); $query = $this->db->get_compiled_select('lehre.vw_stundenplan sp'); diff --git a/public/js/apps/Cis/RoomInformation.js b/public/js/apps/Cis/RoomInformation.js index adb571047..cc7aec2bb 100644 --- a/public/js/apps/Cis/RoomInformation.js +++ b/public/js/apps/Cis/RoomInformation.js @@ -37,12 +37,12 @@ const app = Vue.createApp({ }); events = res.data; //console.log("this are the room events",events) - //this.events = events; + this.events = events; } }).catch((e)=>{console.log(e,"this is the exception")}) }); - axios.get(FHC_JS_DATA_STORAGE_OBJECT.app_root + FHC_JS_DATA_STORAGE_OBJECT.ci_router + '/components/Cis/Stundenplan').then(res => { + /* axios.get(FHC_JS_DATA_STORAGE_OBJECT.app_root + FHC_JS_DATA_STORAGE_OBJECT.ci_router + '/components/Cis/Stundenplan').then(res => { let events; console.log(" this is the res of the api call stundenplan",res); @@ -65,7 +65,7 @@ const app = Vue.createApp({ }).catch((e)=>{console.log(e,"this is the exception")}) - + */ @@ -73,7 +73,13 @@ const app = Vue.createApp({ template: /*html*/`
- + +
+ {{event.orig.lv_info}} + {{event.orig.stg}} + {{event.orig.lektor}} +
+
`, }); diff --git a/public/js/components/Calendar/Week/Page.js b/public/js/components/Calendar/Week/Page.js index eef39011a..cd0ec816e 100755 --- a/public/js/components/Calendar/Week/Page.js +++ b/public/js/components/Calendar/Week/Page.js @@ -112,7 +112,7 @@ export default {
{{hour}}:00
From 3df1aaf371786bf2696ab8fdffff48396a4665ea Mon Sep 17 00:00:00 2001 From: SimonGschnell Date: Tue, 4 Jun 2024 08:24:58 +0200 Subject: [PATCH 04/34] uses the new fhcApi factory to make the roomInformation get request from the frontent/v1/stundenplan api and uses the CalendarDate class to get the first day of the week and the last day of the week to make the request for the room information over the whole week --- .../api/frontend/v1/Stundenplan.php | 90 +++++++++++++++++++ .../components/Cis/Stundenplan.php | 3 - .../models/ressource/Stundenplan_model.php | 9 +- public/js/api/fhcapifactory.js | 4 +- public/js/api/studenplan.js | 15 ++++ public/js/apps/Cis/RoomInformation.js | 63 ++++--------- public/js/components/Calendar/Week/Page.js | 1 - 7 files changed, 132 insertions(+), 53 deletions(-) create mode 100644 application/controllers/api/frontend/v1/Stundenplan.php create mode 100644 public/js/api/studenplan.js diff --git a/application/controllers/api/frontend/v1/Stundenplan.php b/application/controllers/api/frontend/v1/Stundenplan.php new file mode 100644 index 000000000..5e35ae3c9 --- /dev/null +++ b/application/controllers/api/frontend/v1/Stundenplan.php @@ -0,0 +1,90 @@ +. + */ + +if (! defined('BASEPATH')) exit('No direct script access allowed'); + +/** + * This controller operates between (interface) the JS (GUI) and the SearchBarLib (back-end) + * Provides data to the ajax get calls about the searchbar component + * This controller works with JSON calls on the HTTP GET and the output is always JSON + */ +class Stundenplan extends FHCAPI_Controller +{ + + /** + * Object initialization + */ + public function __construct() + { + + parent::__construct([ + 'roomInformation' => self::PERM_LOGGED, + 'Stunden' => self::PERM_LOGGED + ]); + + // Load the library ... + // $this->load->library(''); + } + + //------------------------------------------------------------------------------------------------------------------ + // Public methods + + /** + * Gets a JSON body via HTTP POST and provides the parameters + */ + public function roomInformation() + { + // storing the get parameter in local variables + $ort_kurzbz = $this->input->get('ort_kurzbz', TRUE); + $start_date = $this->input->get('start_date', TRUE); + $end_date = $this->input->get('end_date', TRUE); + + $this->addMeta("ort",$ort_kurzbz); + $this->addMeta("start date",$start_date); + $this->addMeta("end date",$end_date); + $this->addMeta("testKey","testValue"); + + $this->load->model('ressource/Stundenplan_model', 'StundenplanModel'); + + $result = $this->StundenplanModel->getRoomDataOnDay($ort_kurzbz,$start_date,$end_date); + if(isError($result)){ + $this->terminateWithError(getError($result), self::ERROR_TYPE_GENERAL); + } + + $result = hasData($result) ? getData($result) : []; + //echo($this->db->last_query()); + $this->terminateWithSuccess($result); + + } + + public function Stunden() + { + $this->load->model('ressource/Stunde_model', 'StundeModel'); + + $result = $this->StundeModel->load(); + + if (isError($result)){ + $this->terminateWithError(getError($result), self::ERROR_TYPE_GENERAL); + } + + $result = hasData($result)? getData($result) : []; + + $this->terminateWithSuccess($result); + } +} + diff --git a/application/controllers/components/Cis/Stundenplan.php b/application/controllers/components/Cis/Stundenplan.php index e0c163bac..76535befa 100755 --- a/application/controllers/components/Cis/Stundenplan.php +++ b/application/controllers/components/Cis/Stundenplan.php @@ -69,9 +69,6 @@ class Stundenplan extends Auth_Controller public function RoomInformation() { $this->load->model('ressource/Stundenplan_model', 'StundenplanModel'); - - - $result = $this->StundenplanModel->getRoomDataOnDay('EDV_A2.06','2024-05-21'); $result = hasData($result) ? getData($result) : []; diff --git a/application/models/ressource/Stundenplan_model.php b/application/models/ressource/Stundenplan_model.php index f67eab166..64550ccbf 100755 --- a/application/models/ressource/Stundenplan_model.php +++ b/application/models/ressource/Stundenplan_model.php @@ -18,7 +18,7 @@ class Stundenplan_model extends DB_Model * * @return stdClass */ - public function getRoomDataOnDay($ort_kurzbz,$date){ + public function getRoomDataOnDay($ort_kurzbz='EDV_A2.06',$start_date='2024-05-21',$end_date='2024-05-21'){ $this->addSelect(['*',"CONCAT(UPPER(sp.stg_typ),UPPER(sp.stg_kurzbz),'-',COALESCE(CAST(sp.semester AS varchar),'/'),COALESCE(CAST(sp.verband AS varchar),'/')) as stg","lektor","CONCAT(lehrfach,'-',lehrform) as lv_info" ]); @@ -28,12 +28,13 @@ class Stundenplan_model extends DB_Model $res = $this->loadWhere(['ort_kurzbz'=>$ort_kurzbz,'datum'=>$date]); $res = hasData($res) ? getData($res): null; return $res; */ - $this->db->where('ort_kurzbz','EDV_A2.06',true); - $this->db->where('datum >=','2024-05-21',true); + $this->db->where('ort_kurzbz',$ort_kurzbz,true); + $this->db->where('datum >=',$start_date,true); + $this->db->where('datum <=',$end_date,true); $query = $this->db->get_compiled_select('lehre.vw_stundenplan sp'); - return $this->execQuery($query, [$ort_kurzbz, $date]); + return $this->execQuery($query, [$ort_kurzbz, $start_date, $end_date]); } /** diff --git a/public/js/api/fhcapifactory.js b/public/js/api/fhcapifactory.js index 41c89ef50..d5d07e000 100644 --- a/public/js/api/fhcapifactory.js +++ b/public/js/api/fhcapifactory.js @@ -20,11 +20,13 @@ import phrasen from "./phrasen.js"; import navigation from "./navigation.js"; import filter from "./filter.js"; import studstatus from "./studstatus.js"; +import stundenplan from "./studenplan.js"; export default { search, phrasen, navigation, filter, - studstatus + studstatus, + stundenplan, }; diff --git a/public/js/api/studenplan.js b/public/js/api/studenplan.js new file mode 100644 index 000000000..2da67a737 --- /dev/null +++ b/public/js/api/studenplan.js @@ -0,0 +1,15 @@ + +export default { + getRoomInfo(ort_kurzbz, start_date, end_date) { + return this.$fhcApi.get( + '/api/frontend/v1/Stundenplan/roomInformation', + { ort_kurzbz, start_date, end_date} + ); + }, + getStunden() { + return this.$fhcApi.get( + '/api/frontend/v1/Stundenplan/Stunden', + {} + ); + }, +}; \ No newline at end of file diff --git a/public/js/apps/Cis/RoomInformation.js b/public/js/apps/Cis/RoomInformation.js index cc7aec2bb..fbe49386d 100644 --- a/public/js/apps/Cis/RoomInformation.js +++ b/public/js/apps/Cis/RoomInformation.js @@ -1,4 +1,6 @@ import FhcCalendar from "../../components/Calendar/Calendar.js"; +import CalendarDate from "../../composables/CalendarDate.js"; +import FhcApi from "../../plugin/FhcApi.js"; const app = Vue.createApp({ components: { @@ -8,25 +10,26 @@ const app = Vue.createApp({ return { stunden: [], events: null, - testDate: new Date('2024-05-21'), - } + calendarWeek: new CalendarDate(new Date()), + } }, + computed:{ + currentDate: function(){ + return new Date(this.calendarWeek.y, this.calendarWeek.m, this.calendarWeek.d); + }, + }, created() { - axios.get(FHC_JS_DATA_STORAGE_OBJECT.app_root + FHC_JS_DATA_STORAGE_OBJECT.ci_router + '/components/Cis/Stundenplan/Stunden').then(res => { - - - res.data.retval.forEach(std => { + + this.$fhcApi.factory.stundenplan.getStunden().then(res =>{ + res.data.forEach(std => { this.stunden[std.stunde] = std; // TODO(chris): geht besser }); - console.log("this are the loaded stunden", this.stunden) - axios.get(FHC_JS_DATA_STORAGE_OBJECT.app_root + FHC_JS_DATA_STORAGE_OBJECT.ci_router + '/components/Cis/Stundenplan/RoomInformation').then(res => { + this.$fhcApi.factory.stundenplan.getRoomInfo('EDV_A6.09', this.calendarWeek.firstDayOfWeek, this.calendarWeek.lastDayOfWeek).then(res =>{ let events; - console.log(" this is the res of the api call room information",res); if (res.data && res.data.forEach) { res.data.forEach((el, i) => { - console.log(el,"this is the element that gets changed") el.id = i; el.color = '#' + (el.farbe || 'CCCCCC'); el.start = new Date(el.datum + ' ' + this.stunden[el.stunde].beginn); @@ -35,45 +38,16 @@ const app = Vue.createApp({ if (el.lehrform) el.title += '-' + el.lehrform; }); - events = res.data; - //console.log("this are the room events",events) - this.events = events; + + this.events = res.data; } - }).catch((e)=>{console.log(e,"this is the exception")}) - }); - - /* axios.get(FHC_JS_DATA_STORAGE_OBJECT.app_root + FHC_JS_DATA_STORAGE_OBJECT.ci_router + '/components/Cis/Stundenplan').then(res => { - - let events; - console.log(" this is the res of the api call stundenplan",res); - if (res.data.retval && res.data.retval.forEach) { - res.data.retval.forEach((el, i) => { - el.id = i; - el.color = '#' + (el.farbe || 'CCCCCC'); - el.start = new Date(el.datum + ' ' + this.stunden[el.stunde].beginn); - el.end = new Date(el.datum + ' ' + this.stunden[el.stunde].ende); - el.title = el.lehrfach; - if (el.lehrform) - el.title += '-' + el.lehrform; - }); - events = res.data.retval; - console.log("this are the events of the stundenplan",events) - } - - // TODO(chris): do we need that - - }).catch((e)=>{console.log(e,"this is the exception")}) - - - */ - - + }) + }); }, template: /*html*/`
- - +
{{event.orig.lv_info}} {{event.orig.stg}} @@ -84,4 +58,5 @@ const app = Vue.createApp({ `, }); app.config.unwrapInjectedRef = true; +app.use(FhcApi); app.mount('#content'); \ No newline at end of file diff --git a/public/js/components/Calendar/Week/Page.js b/public/js/components/Calendar/Week/Page.js index cd0ec816e..c6636ad43 100755 --- a/public/js/components/Calendar/Week/Page.js +++ b/public/js/components/Calendar/Week/Page.js @@ -41,7 +41,6 @@ export default { }, eventsPerDayAndHour() { const res = {}; - console.log("this are the days",this.days) this.days.forEach(day => { let key = day.toDateString(); From 1a5d270936bf6b6c0ec1b07d190bcbfc298d3af1 Mon Sep 17 00:00:00 2001 From: SimonGschnell Date: Tue, 4 Jun 2024 15:00:41 +0200 Subject: [PATCH 05/34] calendarDate preparation --- .../api/frontend/v1/Stundenplan.php | 43 +++++++++++++++++++ .../models/ressource/Stundenplan_model.php | 2 +- public/js/apps/Cis/RoomInformation.js | 17 ++++++++ 3 files changed, 61 insertions(+), 1 deletion(-) diff --git a/application/controllers/api/frontend/v1/Stundenplan.php b/application/controllers/api/frontend/v1/Stundenplan.php index 5e35ae3c9..5970835c9 100644 --- a/application/controllers/api/frontend/v1/Stundenplan.php +++ b/application/controllers/api/frontend/v1/Stundenplan.php @@ -49,11 +49,15 @@ class Stundenplan extends FHCAPI_Controller */ public function roomInformation() { + + // storing the get parameter in local variables $ort_kurzbz = $this->input->get('ort_kurzbz', TRUE); $start_date = $this->input->get('start_date', TRUE); $end_date = $this->input->get('end_date', TRUE); + $this->addMeta("test_start_date",$start_date); + $this->addMeta("ort",$ort_kurzbz); $this->addMeta("start date",$start_date); $this->addMeta("end date",$end_date); @@ -67,11 +71,50 @@ class Stundenplan extends FHCAPI_Controller } $result = hasData($result) ? getData($result) : []; + + // set up the log library and configure the library to log to the db + $this->load->library('LogLib'); + $this->loglib->setConfigs(array( + 'classIndex' => 5, + 'functionIndex' => 5, + 'lineIndex' => 4, + 'dbLogType' => 'API', // required + 'dbExecuteUser' => 'RESTful API' + )); + + /* foreach($result as $event){ + $this->loglib->logInfoDB($event->datum,"NEW DATE"); + } */ + + $testStartDate = new DateTime($start_date); + $this->loglib->logInfoDB($testStartDate->format('Y-m-d'),"php start date"); + $testStartDate->modify('+1 day'); + $this->loglib->logInfoDB($testStartDate->format('Y-m-d'),"php start date plus one day"); + $testStartDate->modify('+1 day'); + $this->loglib->logInfoDB($testStartDate->format('Y-m-d'),"php start date plus one day"); + $testStartDate->modify('+1 day'); + $this->loglib->logInfoDB($testStartDate->format('Y-m-d'),"php start date plus one day"); + $testStartDate->modify('+1 day'); + $this->loglib->logInfoDB($testStartDate->format('Y-m-d'),"php start date plus one day"); + + $this->groupTheCalendar($result); + //php start date + $phpStartDate = new DateTime($start_date); + + //$phpStartDate->modify('+1 day'); + $this->addMeta('result',$phpStartDate); + + error_log("test".print_r($result,true)); + //echo($this->db->last_query()); $this->terminateWithSuccess($result); } + private function groupTheCalendar($data){ + + } + public function Stunden() { $this->load->model('ressource/Stunde_model', 'StundeModel'); diff --git a/application/models/ressource/Stundenplan_model.php b/application/models/ressource/Stundenplan_model.php index 64550ccbf..077201f0f 100755 --- a/application/models/ressource/Stundenplan_model.php +++ b/application/models/ressource/Stundenplan_model.php @@ -18,7 +18,7 @@ class Stundenplan_model extends DB_Model * * @return stdClass */ - public function getRoomDataOnDay($ort_kurzbz='EDV_A2.06',$start_date='2024-05-21',$end_date='2024-05-21'){ + public function getRoomDataOnDay($ort_kurzbz='EDV_A2.06',$start_date,$end_date){ $this->addSelect(['*',"CONCAT(UPPER(sp.stg_typ),UPPER(sp.stg_kurzbz),'-',COALESCE(CAST(sp.semester AS varchar),'/'),COALESCE(CAST(sp.verband AS varchar),'/')) as stg","lektor","CONCAT(lehrfach,'-',lehrform) as lv_info" ]); diff --git a/public/js/apps/Cis/RoomInformation.js b/public/js/apps/Cis/RoomInformation.js index fbe49386d..6aa590b31 100644 --- a/public/js/apps/Cis/RoomInformation.js +++ b/public/js/apps/Cis/RoomInformation.js @@ -17,6 +17,11 @@ const app = Vue.createApp({ currentDate: function(){ return new Date(this.calendarWeek.y, this.calendarWeek.m, this.calendarWeek.d); }, + }, + methods:{ + calendarDate_to_UTC_date: function(calendarDate){ + return [calendarDate.y, calendarDate.m, calendarDate.d].join('-'); + } }, created() { @@ -25,6 +30,18 @@ const app = Vue.createApp({ this.stunden[std.stunde] = std; // TODO(chris): geht besser }); + + console.log(this.calendarDate_to_UTC_date(this.calendarWeek.firstDayOfWeek),"this is the converted calendar date") + + /* console.log(this.convertDateToUtcDate(this.calendarWeek.firstDayOfWeek), "iso string here") + + console.log(this.calendarWeek.cdFirstDayOfWeek.y,"this is the year of the first day of the week"); + console.log(this.calendarWeek.cdFirstDayOfWeek.m,"this is the month of the first day of the week"); + console.log(this.calendarWeek.cdFirstDayOfWeek.d,"this is the day of the first day of the week"); + + console.log(this.calendarWeek.firstDayOfWeek,"this is the first day of the week"); + console.log(this.convertDateToUtcDate(this.calendarWeek.firstDayOfWeek), "this is the UTC date") + */ this.$fhcApi.factory.stundenplan.getRoomInfo('EDV_A6.09', this.calendarWeek.firstDayOfWeek, this.calendarWeek.lastDayOfWeek).then(res =>{ let events; if (res.data && res.data.forEach) { From 25d284389a3fa50dea33fa9080fb417a3d32cf0f Mon Sep 17 00:00:00 2001 From: SimonGschnell Date: Thu, 6 Jun 2024 09:25:46 +0200 Subject: [PATCH 06/34] gruppieren algorithm erweitern --- .../api/frontend/v1/Stundenplan.php | 160 ++++++++++++++---- .../components/Cis/Stundenplan.php | 10 -- public/js/apps/Cis/RoomInformation.js | 23 ++- 3 files changed, 134 insertions(+), 59 deletions(-) diff --git a/application/controllers/api/frontend/v1/Stundenplan.php b/application/controllers/api/frontend/v1/Stundenplan.php index 5970835c9..c55b225c9 100644 --- a/application/controllers/api/frontend/v1/Stundenplan.php +++ b/application/controllers/api/frontend/v1/Stundenplan.php @@ -37,13 +37,31 @@ class Stundenplan extends FHCAPI_Controller 'Stunden' => self::PERM_LOGGED ]); - // Load the library ... - // $this->load->library(''); + $this->load->library('LogLib'); + $this->loglib->setConfigs(array( + 'classIndex' => 5, + 'functionIndex' => 5, + 'lineIndex' => 4, + 'dbLogType' => 'API', // required + 'dbExecuteUser' => 'RESTful API' + )); } //------------------------------------------------------------------------------------------------------------------ // Public methods + public function Stunden() + { + $this->load->model('ressource/Stunde_model', 'StundeModel'); + + $result = $this->StundeModel->load(); + + if (isError($result)) + return $this->terminateWithError(getError($result), self::ERROR_TYPE_GENERAL); + + $this->terminateWithSuccess(getData($result)); + } + /** * Gets a JSON body via HTTP POST and provides the parameters */ @@ -64,39 +82,123 @@ class Stundenplan extends FHCAPI_Controller $this->addMeta("testKey","testValue"); $this->load->model('ressource/Stundenplan_model', 'StundenplanModel'); - + $this->load->model('ressource/Stunde_model', 'StundeModel'); + + $stunden = $this->StundeModel->load(); + if(isError($stunden)){ + $this->terminateWithError(getError($stunden), self::ERROR_TYPE_GENERAL); + } + $stunden = getData($stunden); + + $this->loglib->logInfoDB(print_r($stunden,true),"stunden"); + + $result = $this->StundenplanModel->getRoomDataOnDay($ort_kurzbz,$start_date,$end_date); if(isError($result)){ $this->terminateWithError(getError($result), self::ERROR_TYPE_GENERAL); } $result = hasData($result) ? getData($result) : []; - + $this->loglib->logInfoDB(print_r($result,true),"result"); // set up the log library and configure the library to log to the db - $this->load->library('LogLib'); - $this->loglib->setConfigs(array( - 'classIndex' => 5, - 'functionIndex' => 5, - 'lineIndex' => 4, - 'dbLogType' => 'API', // required - 'dbExecuteUser' => 'RESTful API' - )); + /* foreach($result as $event){ $this->loglib->logInfoDB($event->datum,"NEW DATE"); } */ $testStartDate = new DateTime($start_date); - $this->loglib->logInfoDB($testStartDate->format('Y-m-d'),"php start date"); - $testStartDate->modify('+1 day'); - $this->loglib->logInfoDB($testStartDate->format('Y-m-d'),"php start date plus one day"); - $testStartDate->modify('+1 day'); - $this->loglib->logInfoDB($testStartDate->format('Y-m-d'),"php start date plus one day"); - $testStartDate->modify('+1 day'); - $this->loglib->logInfoDB($testStartDate->format('Y-m-d'),"php start date plus one day"); - $testStartDate->modify('+1 day'); - $this->loglib->logInfoDB($testStartDate->format('Y-m-d'),"php start date plus one day"); + $testEndDate = new DateTime($end_date); + $count =0; + $final_events = array(); + while($testStartDate <= $testEndDate && $count <7){ + $date = $testStartDate->format('Y-m-d'); + //TODO: array filtering for every day and hour could be too time consuming causing slow response + $day_events = array_filter($result,function($entry) use ($date){ + return $entry->datum == $date; + }); + //$this->loglib->logInfoDB(print_r($day_events,true),"day_events"); + foreach($stunden as $stunde){ + $stunden_events = array_filter($day_events, function($entry) use ($stunde){ + return $entry->stunde == $stunde->stunde; + }); + + // aenderung aller events die am gleichen tag und zur gleichen Stunde gehalten werden + foreach($stunden_events as $event_key => $stunden_event){ + $this->loglib->logInfoDB(print_r($stunden_event,true),"this is the stunden evnet"); + + // lektor bestimmen + if($stunden_event->mitarbeiter_kurzbz == null){ + $simml_lektor = $stunden_event->lektor; + }else{ + $simml_lektor = $stunden_event->mitarbeiter_kurzbz; + } + + + + // lehrverband bestimmen + if(strlen($stunden_event->gruppe_kurzbz)>0){ + $lehrverband = $stunden_event->gruppe_kurzbz; + }else{ + $lehrverband=$stunden_event->stg.'-'.$stunden_event->sem; + // checks whether the verband is not null, '' or '0' + if($stunden_event->verband !=null && $stunden_event->verband != '0' && $stunden_event->verband != ''){ + $lehrverband.=$stunden_event->verband; + // if gruppe is not set it will concatenate nothing but it is only appended if the verband is set + $lehrverband.=$stunden_event->gruppe; + } + } + + // lehrfach bestimmen + $lehrfach = $stunden_event->lehrfach; + if(isset($stunden_event->lehrform)){ + $lehrfach .= '-'.$stunden_event->lehrform; + } + + // GRUPIEREN DER GLEICHEN EVENTS + // vergleiche das aktuelle Event mit allen anderen Events die am gleichen Tag und zur gleichen Stunde gehalten werden + foreach($stunden_events as $compare_key => $stunden_event_compare){ + if($compare_key != $event_key){ + + if ( + // the unr's have to be equal to be grouped + $stunden_event->unr==$stunden_event_compare->unr && + // and either the lektor or the ort_kurzbz have to be equal + ($stunden_event->ort_kurzbz==$stunden_event_compare->ort_kurzbz + || $stunden_event->lektor==$stunden_event_compare->lektor) + ) + { + + } + } + } + + + + + } + if (count($stunden_events) == 1){ + $final_events[] = current($stunden_events); + }else if(count($stunden_events) > 1){ + $gruppe = ''; + foreach($stunden_events as $stunden_event){ + $gruppe .= $stunden_event->gruppe . ','; + } + current($stunden_events)->gruppe = $gruppe; + $final_events[] = current($stunden_events); + } + //$this->loglib->logInfoDB(print_r($stunden_events,true),"date: " . $date . " - stunde:" .$stunde->stunde); + } + /* $this->loglib->logInfoDB(print_r($testStartDate,true),"startdate"); + $this->loglib->logInfoDB($count,"count"); + $this->loglib->logInfoDB(print_r($testEndDate,true),"enddate"); + */ + $testStartDate->modify('+1 day'); + $count++; + } + $this->loglib->logInfoDB(print_r($final_events,true),"final_events"); + $this->groupTheCalendar($result); //php start date $phpStartDate = new DateTime($start_date); @@ -107,7 +209,7 @@ class Stundenplan extends FHCAPI_Controller error_log("test".print_r($result,true)); //echo($this->db->last_query()); - $this->terminateWithSuccess($result); + $this->terminateWithSuccess($final_events); } @@ -115,19 +217,5 @@ class Stundenplan extends FHCAPI_Controller } - public function Stunden() - { - $this->load->model('ressource/Stunde_model', 'StundeModel'); - - $result = $this->StundeModel->load(); - - if (isError($result)){ - $this->terminateWithError(getError($result), self::ERROR_TYPE_GENERAL); - } - - $result = hasData($result)? getData($result) : []; - - $this->terminateWithSuccess($result); - } } diff --git a/application/controllers/components/Cis/Stundenplan.php b/application/controllers/components/Cis/Stundenplan.php index 76535befa..6a89458a7 100755 --- a/application/controllers/components/Cis/Stundenplan.php +++ b/application/controllers/components/Cis/Stundenplan.php @@ -66,15 +66,5 @@ class Stundenplan extends Auth_Controller $this->outputJsonSuccess(getData($result)); } - public function RoomInformation() - { - $this->load->model('ressource/Stundenplan_model', 'StundenplanModel'); - - $result = $this->StundenplanModel->getRoomDataOnDay('EDV_A2.06','2024-05-21'); - $result = hasData($result) ? getData($result) : []; - //echo($this->db->last_query()); - echo json_encode($result); - - } } diff --git a/public/js/apps/Cis/RoomInformation.js b/public/js/apps/Cis/RoomInformation.js index 6aa590b31..c3ce80a75 100644 --- a/public/js/apps/Cis/RoomInformation.js +++ b/public/js/apps/Cis/RoomInformation.js @@ -19,8 +19,13 @@ const app = Vue.createApp({ }, }, methods:{ - calendarDate_to_UTC_date: function(calendarDate){ - return [calendarDate.y, calendarDate.m, calendarDate.d].join('-'); + // returns the string YYYY-MM-DD if param is instance of CalendarDate and null otherwise + calendarDateToString: function(calendarDate){ + + return calendarDate instanceof CalendarDate? + [calendarDate.y, calendarDate.m+1, calendarDate.d].join('-'): + null; + } }, created() { @@ -31,18 +36,10 @@ const app = Vue.createApp({ }); - console.log(this.calendarDate_to_UTC_date(this.calendarWeek.firstDayOfWeek),"this is the converted calendar date") + console.log(this.calendarDateToString(this.calendarWeek.cdFirstDayOfWeek),"this is the converted calendar date") - /* console.log(this.convertDateToUtcDate(this.calendarWeek.firstDayOfWeek), "iso string here") - - console.log(this.calendarWeek.cdFirstDayOfWeek.y,"this is the year of the first day of the week"); - console.log(this.calendarWeek.cdFirstDayOfWeek.m,"this is the month of the first day of the week"); - console.log(this.calendarWeek.cdFirstDayOfWeek.d,"this is the day of the first day of the week"); - - console.log(this.calendarWeek.firstDayOfWeek,"this is the first day of the week"); - console.log(this.convertDateToUtcDate(this.calendarWeek.firstDayOfWeek), "this is the UTC date") - */ - this.$fhcApi.factory.stundenplan.getRoomInfo('EDV_A6.09', this.calendarWeek.firstDayOfWeek, this.calendarWeek.lastDayOfWeek).then(res =>{ + + this.$fhcApi.factory.stundenplan.getRoomInfo('EDV_A6.09', this.calendarDateToString(this.calendarWeek.cdFirstDayOfWeek), this.calendarDateToString(this.calendarWeek.cdLastDayOfWeek)).then(res =>{ let events; if (res.data && res.data.forEach) { res.data.forEach((el, i) => { From 70b0b3fae7b988ebd6ae60a0d9c3d90941006ad1 Mon Sep 17 00:00:00 2001 From: SimonGschnell Date: Fri, 7 Jun 2024 15:06:28 +0200 Subject: [PATCH 07/34] MVP algorithm for stundenplan gruppierung (testing) --- .../api/frontend/v1/Stundenplan.php | 95 ++++++++++++++----- application/core/FHCAPI_Controller.php | 13 +++ .../models/ressource/Stundenplan_model.php | 31 +++++- public/js/apps/Cis/RoomInformation.js | 2 +- 4 files changed, 117 insertions(+), 24 deletions(-) diff --git a/application/controllers/api/frontend/v1/Stundenplan.php b/application/controllers/api/frontend/v1/Stundenplan.php index c55b225c9..77e7e9a0f 100644 --- a/application/controllers/api/frontend/v1/Stundenplan.php +++ b/application/controllers/api/frontend/v1/Stundenplan.php @@ -84,16 +84,20 @@ class Stundenplan extends FHCAPI_Controller $this->load->model('ressource/Stundenplan_model', 'StundenplanModel'); $this->load->model('ressource/Stunde_model', 'StundeModel'); + $stunden = $this->StundeModel->load(); if(isError($stunden)){ $this->terminateWithError(getError($stunden), self::ERROR_TYPE_GENERAL); } $stunden = getData($stunden); - $this->loglib->logInfoDB(print_r($stunden,true),"stunden"); - - + $result = $this->StundenplanModel->getRoomDataOnDay($ort_kurzbz,$start_date,$end_date); + + $this->loglib->logErrorDB(print_r($result,true),"this is an entry of a reservierung"); + + return; + if(isError($result)){ $this->terminateWithError(getError($result), self::ERROR_TYPE_GENERAL); } @@ -111,6 +115,7 @@ class Stundenplan extends FHCAPI_Controller $testEndDate = new DateTime($end_date); $count =0; $final_events = array(); + $grouped = array(); while($testStartDate <= $testEndDate && $count <7){ $date = $testStartDate->format('Y-m-d'); //TODO: array filtering for every day and hour could be too time consuming causing slow response @@ -123,24 +128,16 @@ class Stundenplan extends FHCAPI_Controller return $entry->stunde == $stunde->stunde; }); - // aenderung aller events die am gleichen tag und zur gleichen Stunde gehalten werden - foreach($stunden_events as $event_key => $stunden_event){ - $this->loglib->logInfoDB(print_r($stunden_event,true),"this is the stunden evnet"); - - // lektor bestimmen - if($stunden_event->mitarbeiter_kurzbz == null){ - $simml_lektor = $stunden_event->lektor; - }else{ - $simml_lektor = $stunden_event->mitarbeiter_kurzbz; - } - - + $lehrverband_array = array(); + + // for loop that is just used to fill the lehrverband_array + foreach($stunden_events as $key=>$stunden_event){ // lehrverband bestimmen if(strlen($stunden_event->gruppe_kurzbz)>0){ $lehrverband = $stunden_event->gruppe_kurzbz; }else{ - $lehrverband=$stunden_event->stg.'-'.$stunden_event->sem; + $lehrverband=$stunden_event->stg_typ . $stunden_event->stg_kurzbz .'-'.$stunden_event->semester; // checks whether the verband is not null, '' or '0' if($stunden_event->verband !=null && $stunden_event->verband != '0' && $stunden_event->verband != ''){ $lehrverband.=$stunden_event->verband; @@ -148,7 +145,24 @@ class Stundenplan extends FHCAPI_Controller $lehrverband.=$stunden_event->gruppe; } } + $lehrverband_array[$key] = $lehrverband; + } + + + // aenderung aller events die am gleichen tag und zur gleichen Stunde gehalten werden + foreach($stunden_events as $event_key => $stunden_event){ + if(isset($grouped[$event_key])){ + continue; + } + + // lektor bestimmen + if($stunden_event->mitarbeiter_kurzbz == null){ + $simml_lektor = $stunden_event->lektor; + }else{ + $simml_lektor = $stunden_event->mitarbeiter_kurzbz; + } + // lehrfach bestimmen $lehrfach = $stunden_event->lehrfach; if(isset($stunden_event->lehrform)){ @@ -158,26 +172,64 @@ class Stundenplan extends FHCAPI_Controller // GRUPIEREN DER GLEICHEN EVENTS // vergleiche das aktuelle Event mit allen anderen Events die am gleichen Tag und zur gleichen Stunde gehalten werden foreach($stunden_events as $compare_key => $stunden_event_compare){ + if($compare_key != $event_key){ - + + // will be used to skip the loop iteration with this index because it was already grouped + $grouped[$compare_key] = 1; + // this if checks if the events can be grouped if ( // the unr's have to be equal to be grouped $stunden_event->unr==$stunden_event_compare->unr && // and either the lektor or the ort_kurzbz have to be equal ($stunden_event->ort_kurzbz==$stunden_event_compare->ort_kurzbz || $stunden_event->lektor==$stunden_event_compare->lektor) + // reservierungen muessen auch beachtet werden, wenn der eintrag eine reservierung ist dann koennen die eintraege nicht gruppiert werden + //&& !$stunden_event->reservierung && !$stunden_event_compare->reservierung + ) { + + + // Bezeichnung des Events zusammenfuehren + // change the event with the $event_key if the compared_event has different properties but is still groupable + + //Lektoren + if(!mb_strstr($stunden_event->lektor,$stunden_event_compare->lektor)){ + $this->loglib->logErrorDB($stunden_event->datum ."-". $stunden_event->stunde,"entered lektor - first if"); + $stunden_events[$event_key]->lektor = $stunden_event->lektor . ' \ ' . $stunden_event_compare->lektor; + $stunden_events[$event_key]->mitarbeiter_kurzbz = $stunden_event->mitarbeiter_kurzbz . ' \ ' . $stunden_event_compare->mitarbeiter_kurzbz; + } + + //Ort + if(!mb_strstr($stunden_event->ort_kurzbz,$stunden_event_compare->ort_kurzbz)){ + $this->loglib->logErrorDB($stunden_event->datum ."-". $stunden_event->stunde,"entered ort - second if"); + $stunden_events[$event_key]->ort_kurzbz = $stunden_event->ort_kurzbz . ' \ ' . $stunden_event_compare->ort_kurzbz; + } + + //unset the compared and grouped event + unset($stunden_events[$compare_key]); + + + //Lehrverband + if(!mb_strstr($lehrverband_array[$event_key],$lehrverband_array[$compare_key])){ + $this->loglib->logErrorDB($stunden_event->datum ."-". $stunden_event->stunde,"entered gruppe - third if"); + $lehrverband_array[$event_key] .= ' \ ' . $lehrverband_array[$compare_key]; + } + } } } - + + // add the grouped lehrverband entry to the event + $stunden_events[$event_key]->stg = $lehrverband_array[$event_key]; + $final_events[] = $stunden_events[$event_key]; } - if (count($stunden_events) == 1){ + /* if (count($stunden_events) == 1){ $final_events[] = current($stunden_events); }else if(count($stunden_events) > 1){ $gruppe = ''; @@ -186,7 +238,7 @@ class Stundenplan extends FHCAPI_Controller } current($stunden_events)->gruppe = $gruppe; $final_events[] = current($stunden_events); - } + } */ //$this->loglib->logInfoDB(print_r($stunden_events,true),"date: " . $date . " - stunde:" .$stunde->stunde); } /* $this->loglib->logInfoDB(print_r($testStartDate,true),"startdate"); @@ -197,8 +249,7 @@ class Stundenplan extends FHCAPI_Controller $count++; } - $this->loglib->logInfoDB(print_r($final_events,true),"final_events"); - + $this->groupTheCalendar($result); //php start date $phpStartDate = new DateTime($start_date); diff --git a/application/core/FHCAPI_Controller.php b/application/core/FHCAPI_Controller.php index 647032795..d5e3ca0ce 100644 --- a/application/core/FHCAPI_Controller.php +++ b/application/core/FHCAPI_Controller.php @@ -141,6 +141,19 @@ class FHCAPI_Controller extends Auth_Controller $this->returnObj['meta'][$key] = $value; } + /** + * @param string $key + * @return mixed + */ + public function getMeta($key) + { + if (!isset($this->returnObj['meta'])) + return null; + if (!isset($this->returnObj['meta'][$key])) + return null; + return $this->returnObj['meta'][$key]; + } + /** * @param string $status * @return void diff --git a/application/models/ressource/Stundenplan_model.php b/application/models/ressource/Stundenplan_model.php index 077201f0f..0205b1472 100755 --- a/application/models/ressource/Stundenplan_model.php +++ b/application/models/ressource/Stundenplan_model.php @@ -21,7 +21,27 @@ class Stundenplan_model extends DB_Model public function getRoomDataOnDay($ort_kurzbz='EDV_A2.06',$start_date,$end_date){ - $this->addSelect(['*',"CONCAT(UPPER(sp.stg_typ),UPPER(sp.stg_kurzbz),'-',COALESCE(CAST(sp.semester AS varchar),'/'),COALESCE(CAST(sp.verband AS varchar),'/')) as stg","lektor","CONCAT(lehrfach,'-',lehrform) as lv_info" ]); + //$this->addSelect(['*',"CONCAT(UPPER(sp.stg_typ),UPPER(sp.stg_kurzbz),'-',COALESCE(CAST(sp.semester AS varchar),'/'),COALESCE(CAST(sp.verband AS varchar),'/')) as stg","lektor","CONCAT(lehrfach,'-',lehrform) as lv_info" ]); + $result = $this->execReadOnlyQuery(" + + SELECT 'stundenplan_eintrag' as eintrags_type, CONCAT(UPPER(sp.stg_typ),UPPER(sp.stg_kurzbz),'-',COALESCE(CAST(sp.semester AS varchar),'/'),COALESCE(CAST(sp.verband AS varchar),'/')) AS stg, lektor, CONCAT(lehrfach,'-',lehrform) AS lv_info, ort_kurzbz , * FROM lehre.vw_stundenplan sp + WHERE ort_kurzbz = ? AND datum >= ? AND datum <= ? + UNION ALL + SELECT 'reservierungs_eintrag' as eintrags_type, titel, uid, NULL, ort_kurzbz FROM lehre.vw_reservierung res + WHERE ort_kurzbz = ? AND datum >= ? AND datum <= ? + + ", [$ort_kurzbz, $start_date, $end_date,$ort_kurzbz, $start_date, $end_date]); + return $result; + + + /* + "SELECT 'stundenplan_eintrag' as eintrags_type ort_kurzbz studiengang_kz uid stunde datum titel NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL" + "SELECT 'reservierungs_eintrag' as eintrags_type, ort_kurzbz studiengang_kz uid stunde datum titel NULL NULL NULL NULL NULL" + + */ + //to add reservierungen to the query, we have to join the table vw_reservierung to the vw_stundenplan and use the datum/stunde/ort_kurzbz keys + + /* $this->addSelect(["lehre.tbl_stundenplan.*","CONCAT(UPPER(sg.typ),UPPER(sg.kurzbz),'-',lehre.tbl_stundenplan.semester,lehre.tbl_stundenplan.verband) as simml"]); $this->addJoin("public.tbl_lehrverband as lv","lv.studiengang_kz=lehre.tbl_stundenplan.studiengang_kz AND lv.gruppe=lehre.tbl_stundenplan.gruppe AND lv.verband=lehre.tbl_stundenplan.verband AND lv.semester=lehre.tbl_stundenplan.semester","LEFT"); $this->addJoin("public.tbl_studiengang as sg","sg.studiengang_kz=lehre.tbl_stundenplan.studiengang_kz","LEFT"); @@ -34,7 +54,16 @@ class Stundenplan_model extends DB_Model $query = $this->db->get_compiled_select('lehre.vw_stundenplan sp'); + $raum_stundenplan= $this->execQuery($query, [$ort_kurzbz, $start_date, $end_date]); + + // reseting the query and query reservierungen information + $this->resetQuery(); + $this->db->where('ort_kurzbz',$ort_kurzbz,true); + $this->db->where('datum >=',$start_date,true); + $this->db->where('datum <=',$end_date,true); + $query = $this->db->get_compiled_select('lehre.vw_reservierung res'); return $this->execQuery($query, [$ort_kurzbz, $start_date, $end_date]); + } /** diff --git a/public/js/apps/Cis/RoomInformation.js b/public/js/apps/Cis/RoomInformation.js index c3ce80a75..f0edefa73 100644 --- a/public/js/apps/Cis/RoomInformation.js +++ b/public/js/apps/Cis/RoomInformation.js @@ -10,7 +10,7 @@ const app = Vue.createApp({ return { stunden: [], events: null, - calendarWeek: new CalendarDate(new Date()), + calendarWeek: new CalendarDate(new Date("2024-03-06")), } }, computed:{ From 8442690bc75d46196617714e10fa05ca268e3618 Mon Sep 17 00:00:00 2001 From: SimonGschnell Date: Mon, 10 Jun 2024 10:56:12 +0200 Subject: [PATCH 08/34] splits the multiple stg into different rows if there are more than one stg in one lv --- .../api/frontend/v1/Stundenplan.php | 53 +++++++++++++++++-- .../models/ressource/Stundenplan_model.php | 49 ++++------------- public/js/apps/Cis/RoomInformation.js | 2 +- 3 files changed, 61 insertions(+), 43 deletions(-) diff --git a/application/controllers/api/frontend/v1/Stundenplan.php b/application/controllers/api/frontend/v1/Stundenplan.php index 77e7e9a0f..091e6c19d 100644 --- a/application/controllers/api/frontend/v1/Stundenplan.php +++ b/application/controllers/api/frontend/v1/Stundenplan.php @@ -94,9 +94,7 @@ class Stundenplan extends FHCAPI_Controller $result = $this->StundenplanModel->getRoomDataOnDay($ort_kurzbz,$start_date,$end_date); - $this->loglib->logErrorDB(print_r($result,true),"this is an entry of a reservierung"); - - return; + if(isError($result)){ $this->terminateWithError(getError($result), self::ERROR_TYPE_GENERAL); @@ -111,6 +109,53 @@ class Stundenplan extends FHCAPI_Controller $this->loglib->logInfoDB($event->datum,"NEW DATE"); } */ + //TODO: also implement the following algorithm to block the lectures that are together over different stunden + /* $blockcontinue=false; + if (isset($blocked[$this->std_plan[$i][$j][$idx]->unr]) && $blocked[$this->std_plan[$i][$j][$idx]->unr]>0) + { + $blocked[$this->std_plan[$i][$j][$idx]->unr]--; + $blockcontinue=true; + } + + if (!$blockcontinue) + { + // Blockungen ueber mehrere Stunden erkennen + + $blockflag=false; + for ($blockstunden=1;$blockstunden<=$num_rows_stunde;$blockstunden++) + { + if (isset($this->std_plan[$i][$j+$blockstunden][$idx]) && isset($this->std_plan[$i][$j+$blockstunden][$idx]->stundenplan_id) + && ($this->std_plan[$i][$j][$idx]->unr == $this->std_plan[$i][$j+$blockstunden][$idx]->unr) + && $this->std_plan[$i][$j][$idx]!='0' && $k<($num_rows_stunde-$blockstunden) + && !($this->std_plan[$i][$j][$idx]->reservierung && $this->std_plan[$i][$j][$idx]->lektor!=$this->std_plan[$i][$j+$blockstunden][$idx]->lektor)) + { + + if (isset($blocked[$this->std_plan[$i][$j][$idx]->unr])) + $blocked[$this->std_plan[$i][$j][$idx]->unr]++; + else + $blocked[$this->std_plan[$i][$j][$idx]->unr]=1; + $row = $this->db_fetch_object($this->stunde, ($k+$blockstunden)); + $stunden_arr[]=$row->stunde; + $end_time=$row->ende; + $blockflag=true; + } + else + { + if (!$blockflag) + { + $row = $this->db_fetch_object($this->stunde, $k); + $stunden_arr[]=$row->stunde; + $end_time=$row->ende; + break; + } + else + { + break; + } + } + } + } */ + $testStartDate = new DateTime($start_date); $testEndDate = new DateTime($end_date); $count =0; @@ -215,7 +260,7 @@ class Stundenplan extends FHCAPI_Controller //Lehrverband if(!mb_strstr($lehrverband_array[$event_key],$lehrverband_array[$compare_key])){ $this->loglib->logErrorDB($stunden_event->datum ."-". $stunden_event->stunde,"entered gruppe - third if"); - $lehrverband_array[$event_key] .= ' \ ' . $lehrverband_array[$compare_key]; + $lehrverband_array[$event_key] .= ' / ' . $lehrverband_array[$compare_key]; } } diff --git a/application/models/ressource/Stundenplan_model.php b/application/models/ressource/Stundenplan_model.php index 0205b1472..17516afe0 100755 --- a/application/models/ressource/Stundenplan_model.php +++ b/application/models/ressource/Stundenplan_model.php @@ -21,49 +21,22 @@ class Stundenplan_model extends DB_Model public function getRoomDataOnDay($ort_kurzbz='EDV_A2.06',$start_date,$end_date){ - //$this->addSelect(['*',"CONCAT(UPPER(sp.stg_typ),UPPER(sp.stg_kurzbz),'-',COALESCE(CAST(sp.semester AS varchar),'/'),COALESCE(CAST(sp.verband AS varchar),'/')) as stg","lektor","CONCAT(lehrfach,'-',lehrform) as lv_info" ]); - $result = $this->execReadOnlyQuery(" - - SELECT 'stundenplan_eintrag' as eintrags_type, CONCAT(UPPER(sp.stg_typ),UPPER(sp.stg_kurzbz),'-',COALESCE(CAST(sp.semester AS varchar),'/'),COALESCE(CAST(sp.verband AS varchar),'/')) AS stg, lektor, CONCAT(lehrfach,'-',lehrform) AS lv_info, ort_kurzbz , * FROM lehre.vw_stundenplan sp + //TODO alternative query version that unions the reservierungen into the stundenplan with different 'eintrags_type' column + /*" + -- merging all reservierungs information with the stundenplan information but with different types + SELECT 'stundenplan_eintrag' as eintrags_type, ort_kurzbz, studiengang_kz, uid, stunde, datum, titel, semester, verband, gruppe, gruppe_kurzbz, stg_kurzbz, CONCAT(UPPER(sp.stg_typ),UPPER(sp.stg_kurzbz),'-',COALESCE(CAST(sp.semester AS varchar),'/'),COALESCE(CAST(sp.verband AS varchar),'/')) AS stg, CONCAT(lehrfach,'-',lehrform) AS lv_info, * FROM lehre.vw_stundenplan sp WHERE ort_kurzbz = ? AND datum >= ? AND datum <= ? UNION ALL - SELECT 'reservierungs_eintrag' as eintrags_type, titel, uid, NULL, ort_kurzbz FROM lehre.vw_reservierung res + SELECT 'reservierungs_eintrag' as eintrags_type, ort_kurzbz, studiengang_kz, uid, stunde, datum, titel, semester, verband, gruppe, gruppe_kurzbz, stg_kurzbz, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL FROM lehre.vw_reservierung res WHERE ort_kurzbz = ? AND datum >= ? AND datum <= ? - - ", [$ort_kurzbz, $start_date, $end_date,$ort_kurzbz, $start_date, $end_date]); - return $result; + "*/ + $raum_stundenplan= $this->execReadOnlyQuery(" + SELECT 'stundenplan_eintrag' as eintrags_type, ort_kurzbz, studiengang_kz, uid, stunde, datum, titel, semester, verband, gruppe, gruppe_kurzbz, stg_kurzbz, CONCAT(UPPER(sp.stg_typ),UPPER(sp.stg_kurzbz),'-',COALESCE(CAST(sp.semester AS varchar),'/'),COALESCE(CAST(sp.verband AS varchar),'/')) AS stg, CONCAT(lehrfach,'-',lehrform) AS lv_info, * FROM lehre.vw_stundenplan sp + WHERE ort_kurzbz = ? AND datum >= ? AND datum <= ? + ", [$ort_kurzbz, $start_date, $end_date]); - /* - "SELECT 'stundenplan_eintrag' as eintrags_type ort_kurzbz studiengang_kz uid stunde datum titel NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL" - "SELECT 'reservierungs_eintrag' as eintrags_type, ort_kurzbz studiengang_kz uid stunde datum titel NULL NULL NULL NULL NULL" - - */ - //to add reservierungen to the query, we have to join the table vw_reservierung to the vw_stundenplan and use the datum/stunde/ort_kurzbz keys - - - /* $this->addSelect(["lehre.tbl_stundenplan.*","CONCAT(UPPER(sg.typ),UPPER(sg.kurzbz),'-',lehre.tbl_stundenplan.semester,lehre.tbl_stundenplan.verband) as simml"]); - $this->addJoin("public.tbl_lehrverband as lv","lv.studiengang_kz=lehre.tbl_stundenplan.studiengang_kz AND lv.gruppe=lehre.tbl_stundenplan.gruppe AND lv.verband=lehre.tbl_stundenplan.verband AND lv.semester=lehre.tbl_stundenplan.semester","LEFT"); - $this->addJoin("public.tbl_studiengang as sg","sg.studiengang_kz=lehre.tbl_stundenplan.studiengang_kz","LEFT"); - $res = $this->loadWhere(['ort_kurzbz'=>$ort_kurzbz,'datum'=>$date]); - $res = hasData($res) ? getData($res): null; - return $res; */ - $this->db->where('ort_kurzbz',$ort_kurzbz,true); - $this->db->where('datum >=',$start_date,true); - $this->db->where('datum <=',$end_date,true); - - $query = $this->db->get_compiled_select('lehre.vw_stundenplan sp'); - - $raum_stundenplan= $this->execQuery($query, [$ort_kurzbz, $start_date, $end_date]); - - // reseting the query and query reservierungen information - $this->resetQuery(); - $this->db->where('ort_kurzbz',$ort_kurzbz,true); - $this->db->where('datum >=',$start_date,true); - $this->db->where('datum <=',$end_date,true); - $query = $this->db->get_compiled_select('lehre.vw_reservierung res'); - return $this->execQuery($query, [$ort_kurzbz, $start_date, $end_date]); - + return $raum_stundenplan; } /** diff --git a/public/js/apps/Cis/RoomInformation.js b/public/js/apps/Cis/RoomInformation.js index f0edefa73..f4c9c21b7 100644 --- a/public/js/apps/Cis/RoomInformation.js +++ b/public/js/apps/Cis/RoomInformation.js @@ -64,7 +64,7 @@ const app = Vue.createApp({
{{event.orig.lv_info}} - {{event.orig.stg}} + {{item}} {{event.orig.lektor}}
From 392d8f38d290faadbbd45991ce9d8c38abe67693 Mon Sep 17 00:00:00 2001 From: SimonGschnell Date: Mon, 10 Jun 2024 11:39:16 +0200 Subject: [PATCH 09/34] adding the reservierungen to the room plannung --- .../api/frontend/v1/Stundenplan.php | 31 ++++++++++-- .../models/ressource/Reservierung_model.php | 17 +++++++ .../models/ressource/Stundenplan_model.php | 2 +- public/js/api/studenplan.js | 6 +++ public/js/apps/Cis/RoomInformation.js | 49 +++++++++++++++---- 5 files changed, 89 insertions(+), 16 deletions(-) diff --git a/application/controllers/api/frontend/v1/Stundenplan.php b/application/controllers/api/frontend/v1/Stundenplan.php index 091e6c19d..d360c1b90 100644 --- a/application/controllers/api/frontend/v1/Stundenplan.php +++ b/application/controllers/api/frontend/v1/Stundenplan.php @@ -34,7 +34,8 @@ class Stundenplan extends FHCAPI_Controller parent::__construct([ 'roomInformation' => self::PERM_LOGGED, - 'Stunden' => self::PERM_LOGGED + 'Stunden' => self::PERM_LOGGED, + 'Reservierungen' => self::PERM_LOGGED ]); $this->load->library('LogLib'); @@ -68,12 +69,16 @@ class Stundenplan extends FHCAPI_Controller public function roomInformation() { - + //TODO please split this algorithm into multiple smaller function it is not really mantainable like this // storing the get parameter in local variables $ort_kurzbz = $this->input->get('ort_kurzbz', TRUE); $start_date = $this->input->get('start_date', TRUE); $end_date = $this->input->get('end_date', TRUE); + if(!$ort_kurzbz || !$start_date || !$end_date){ + $this->terminateWithError("Missing parameters", self::ERROR_TYPE_GENERAL); + } + $this->addMeta("test_start_date",$start_date); $this->addMeta("ort",$ort_kurzbz); @@ -295,7 +300,6 @@ class Stundenplan extends FHCAPI_Controller } - $this->groupTheCalendar($result); //php start date $phpStartDate = new DateTime($start_date); @@ -309,9 +313,26 @@ class Stundenplan extends FHCAPI_Controller } - private function groupTheCalendar($data){ + public function Reservierungen() + { - } + $ort_kurzbz = $this->input->get('ort_kurzbz', TRUE); + $start_date = $this->input->get('start_date', TRUE); + $end_date = $this->input->get('end_date', TRUE); + + if(!$ort_kurzbz || !$start_date || !$end_date){ + $this->terminateWithError("Missing parameters", self::ERROR_TYPE_GENERAL); + } + + $this->load->model('ressource/Reservierung_model', 'ReservierungModel'); + + $result = $this->ReservierungModel->getRoomReservierungen($ort_kurzbz, $start_date, $end_date); + + if (isError($result)) + return $this->terminateWithError(getError($result), self::ERROR_TYPE_GENERAL); + + $this->terminateWithSuccess(getData($result)); + } } diff --git a/application/models/ressource/Reservierung_model.php b/application/models/ressource/Reservierung_model.php index 7a3d1a4a4..260104305 100755 --- a/application/models/ressource/Reservierung_model.php +++ b/application/models/ressource/Reservierung_model.php @@ -12,6 +12,23 @@ class Reservierung_model extends DB_Model $this->pk = 'reservierung_id'; } + + /** + * @param $uid + * + * @return stdClass + */ + public function getRoomReservierungen($ort_kurzbz, $start_date, $end_date) + { + + $raum_reservierungen= $this->execReadOnlyQuery(" + SELECT * FROM lehre.vw_reservierung res + WHERE ort_kurzbz = ? AND datum >= ? AND datum <= ? + ", [$ort_kurzbz, $start_date, $end_date]); + + return $raum_reservierungen; + } + /** * @param $uid * diff --git a/application/models/ressource/Stundenplan_model.php b/application/models/ressource/Stundenplan_model.php index 17516afe0..299faa049 100755 --- a/application/models/ressource/Stundenplan_model.php +++ b/application/models/ressource/Stundenplan_model.php @@ -32,7 +32,7 @@ class Stundenplan_model extends DB_Model "*/ $raum_stundenplan= $this->execReadOnlyQuery(" - SELECT 'stundenplan_eintrag' as eintrags_type, ort_kurzbz, studiengang_kz, uid, stunde, datum, titel, semester, verband, gruppe, gruppe_kurzbz, stg_kurzbz, CONCAT(UPPER(sp.stg_typ),UPPER(sp.stg_kurzbz),'-',COALESCE(CAST(sp.semester AS varchar),'/'),COALESCE(CAST(sp.verband AS varchar),'/')) AS stg, CONCAT(lehrfach,'-',lehrform) AS lv_info, * FROM lehre.vw_stundenplan sp + SELECT CONCAT(UPPER(sp.stg_typ),UPPER(sp.stg_kurzbz),'-',COALESCE(CAST(sp.semester AS varchar),'/'),COALESCE(CAST(sp.verband AS varchar),'/')) AS stg, CONCAT(lehrfach,'-',lehrform) AS lv_info, * FROM lehre.vw_stundenplan sp WHERE ort_kurzbz = ? AND datum >= ? AND datum <= ? ", [$ort_kurzbz, $start_date, $end_date]); diff --git a/public/js/api/studenplan.js b/public/js/api/studenplan.js index 2da67a737..d691a72cf 100644 --- a/public/js/api/studenplan.js +++ b/public/js/api/studenplan.js @@ -12,4 +12,10 @@ export default { {} ); }, + getReservierungen(ort_kurzbz, start_date, end_date) { + return this.$fhcApi.get( + '/api/frontend/v1/Stundenplan/Reservierungen', + { ort_kurzbz, start_date, end_date} + ); + }, }; \ No newline at end of file diff --git a/public/js/apps/Cis/RoomInformation.js b/public/js/apps/Cis/RoomInformation.js index f4c9c21b7..a7aced683 100644 --- a/public/js/apps/Cis/RoomInformation.js +++ b/public/js/apps/Cis/RoomInformation.js @@ -10,13 +10,19 @@ const app = Vue.createApp({ return { stunden: [], events: null, - calendarWeek: new CalendarDate(new Date("2024-03-06")), + calendarWeek: new CalendarDate(new Date("2024-06-06")), } }, computed:{ currentDate: function(){ return new Date(this.calendarWeek.y, this.calendarWeek.m, this.calendarWeek.d); }, + weekFirstDay: function(){ + return this.calendarDateToString(this.calendarWeek.cdFirstDayOfWeek); + }, + weekLastDay: function(){ + return this.calendarDateToString(this.calendarWeek.cdLastDayOfWeek); + }, }, methods:{ // returns the string YYYY-MM-DD if param is instance of CalendarDate and null otherwise @@ -26,7 +32,8 @@ const app = Vue.createApp({ [calendarDate.y, calendarDate.m+1, calendarDate.d].join('-'): null; - } + }, + }, created() { @@ -36,10 +43,8 @@ const app = Vue.createApp({ }); - console.log(this.calendarDateToString(this.calendarWeek.cdFirstDayOfWeek),"this is the converted calendar date") - - - this.$fhcApi.factory.stundenplan.getRoomInfo('EDV_A6.09', this.calendarDateToString(this.calendarWeek.cdFirstDayOfWeek), this.calendarDateToString(this.calendarWeek.cdLastDayOfWeek)).then(res =>{ + // old testing room EDV_A6.09 + this.$fhcApi.factory.stundenplan.getRoomInfo('SEM_E0.04', this.weekFirstDay, this.weekLastDay).then(res =>{ let events; if (res.data && res.data.forEach) { res.data.forEach((el, i) => { @@ -55,7 +60,27 @@ const app = Vue.createApp({ this.events = res.data; } - }) + }); + + this.$fhcApi.factory.stundenplan.getReservierungen('SEM_E0.04', this.weekFirstDay, this.weekLastDay).then(res => { + if (res.data && res.data.forEach) { + res.data.forEach((el, i) => { + el.reservierung = true; + el.color = '#CCCCCC'; + el.start = new Date(el.datum + ' ' + this.stunden[el.stunde].beginn); + el.end = new Date(el.datum + ' ' + this.stunden[el.stunde].ende); + el.title = el.titel; + if (el.lehrform) + el.title += '-' + el.lehrform; + }); + + } + + let reservierungs_events = res.data; + console.log(reservierungs_events, " this are the reserverungs event") + this.events = [...this.events,...reservierungs_events]; + + }); }); }, @@ -63,9 +88,13 @@ const app = Vue.createApp({
- {{event.orig.lv_info}} - {{item}} - {{event.orig.lektor}} + + + {{event.orig.reservierung? event.orig.title :event.orig.lv_info}} + {{'this is a reservierung'}} + {{item}} + {{event.orig.reservierung? event.orig.uid : event.orig.lektor}} +
From 022ad26dd236863286cf0901750f70068f6e5a40 Mon Sep 17 00:00:00 2001 From: SimonGschnell Date: Mon, 10 Jun 2024 13:01:55 +0200 Subject: [PATCH 10/34] reservierungen query also joins the studiengangs and mitarbeiter information --- application/controllers/api/frontend/v1/Stundenplan.php | 2 ++ application/models/ressource/Reservierung_model.php | 7 +++++-- public/js/apps/Cis/RoomInformation.js | 6 +++--- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/application/controllers/api/frontend/v1/Stundenplan.php b/application/controllers/api/frontend/v1/Stundenplan.php index d360c1b90..4f7e7a053 100644 --- a/application/controllers/api/frontend/v1/Stundenplan.php +++ b/application/controllers/api/frontend/v1/Stundenplan.php @@ -316,6 +316,8 @@ class Stundenplan extends FHCAPI_Controller public function Reservierungen() { + //TODO the reservierungen have to be grouped like the stundenplan + $ort_kurzbz = $this->input->get('ort_kurzbz', TRUE); $start_date = $this->input->get('start_date', TRUE); $end_date = $this->input->get('end_date', TRUE); diff --git a/application/models/ressource/Reservierung_model.php b/application/models/ressource/Reservierung_model.php index 260104305..23d17f974 100755 --- a/application/models/ressource/Reservierung_model.php +++ b/application/models/ressource/Reservierung_model.php @@ -22,8 +22,11 @@ class Reservierung_model extends DB_Model { $raum_reservierungen= $this->execReadOnlyQuery(" - SELECT * FROM lehre.vw_reservierung res - WHERE ort_kurzbz = ? AND datum >= ? AND datum <= ? + SELECT res.*, mit.kurzbz as person_kurzbz , CONCAT(studg.typ,studg.kurzbz,'-') as stg + FROM lehre.vw_reservierung res + JOIN public.tbl_mitarbeiter mit ON mit.mitarbeiter_uid=res.uid + JOIN public.tbl_studiengang studg ON studg.studiengang_kz=res.studiengang_kz + WHERE res.ort_kurzbz = ? AND datum >= ? AND datum <= ? ", [$ort_kurzbz, $start_date, $end_date]); return $raum_reservierungen; diff --git a/public/js/apps/Cis/RoomInformation.js b/public/js/apps/Cis/RoomInformation.js index a7aced683..d485227b2 100644 --- a/public/js/apps/Cis/RoomInformation.js +++ b/public/js/apps/Cis/RoomInformation.js @@ -78,7 +78,7 @@ const app = Vue.createApp({ let reservierungs_events = res.data; console.log(reservierungs_events, " this are the reserverungs event") - this.events = [...this.events,...reservierungs_events]; + this.events = [...(this.events?this.events:[]),...reservierungs_events]; }); }); @@ -91,9 +91,9 @@ const app = Vue.createApp({ {{event.orig.reservierung? event.orig.title :event.orig.lv_info}} - {{'this is a reservierung'}} + {{event.orig.stg}} {{item}} - {{event.orig.reservierung? event.orig.uid : event.orig.lektor}} + {{event.orig.reservierung? event.orig.person_kurzbz : event.orig.lektor}}
From 9c51f25c9e8a885e44da69c9cc8f6e1ffc0462da Mon Sep 17 00:00:00 2001 From: SimonGschnell Date: Tue, 11 Jun 2024 15:03:09 +0200 Subject: [PATCH 11/34] modifies how the slot template from the Calendar Page is passed to the CalendarApp and prints the reservierungen differently (but the reservierungen are not grouped yet) --- .../api/frontend/v1/Stundenplan.php | 3 +- .../models/ressource/Reservierung_model.php | 8 +++- .../models/ressource/Stundenplan_model.php | 16 ++++--- public/js/apps/Cis/RoomInformation.js | 47 ++++++++++++------- public/js/components/Calendar/Calendar.js | 4 +- public/js/components/Calendar/Week.js | 4 +- public/js/components/Calendar/Week/Page.js | 7 +-- 7 files changed, 57 insertions(+), 32 deletions(-) diff --git a/application/controllers/api/frontend/v1/Stundenplan.php b/application/controllers/api/frontend/v1/Stundenplan.php index 4f7e7a053..2bff6016f 100644 --- a/application/controllers/api/frontend/v1/Stundenplan.php +++ b/application/controllers/api/frontend/v1/Stundenplan.php @@ -98,7 +98,8 @@ class Stundenplan extends FHCAPI_Controller $result = $this->StundenplanModel->getRoomDataOnDay($ort_kurzbz,$start_date,$end_date); - + // logging the result of the query + //$this->loglib->logErrorDB(print_r($result,true),"this is the result of the query"); if(isError($result)){ diff --git a/application/models/ressource/Reservierung_model.php b/application/models/ressource/Reservierung_model.php index 23d17f974..e149cf0d7 100755 --- a/application/models/ressource/Reservierung_model.php +++ b/application/models/ressource/Reservierung_model.php @@ -22,7 +22,13 @@ class Reservierung_model extends DB_Model { $raum_reservierungen= $this->execReadOnlyQuery(" - SELECT res.*, mit.kurzbz as person_kurzbz , CONCAT(studg.typ,studg.kurzbz,'-') as stg + SELECT res.*, mit.kurzbz as person_kurzbz , + CASE + WHEN res.verband IS NOT NULL OR res.semester IS NOT NULL THEN + CONCAT(UPPER(studg.typ),UPPER(studg.kurzbz),'-',res.verband,res.semester) + ELSE + CONCAT(UPPER(studg.typ),UPPER(studg.kurzbz)) + END AS stg FROM lehre.vw_reservierung res JOIN public.tbl_mitarbeiter mit ON mit.mitarbeiter_uid=res.uid JOIN public.tbl_studiengang studg ON studg.studiengang_kz=res.studiengang_kz diff --git a/application/models/ressource/Stundenplan_model.php b/application/models/ressource/Stundenplan_model.php index 299faa049..5ce6a9823 100755 --- a/application/models/ressource/Stundenplan_model.php +++ b/application/models/ressource/Stundenplan_model.php @@ -18,23 +18,25 @@ class Stundenplan_model extends DB_Model * * @return stdClass */ - public function getRoomDataOnDay($ort_kurzbz='EDV_A2.06',$start_date,$end_date){ + public function getRoomDataOnDay($ort_kurzbz,$start_date,$end_date){ - //TODO alternative query version that unions the reservierungen into the stundenplan with different 'eintrags_type' column - /*" + + /*$raum_stundenplan= $this->execReadOnlyQuery(" -- merging all reservierungs information with the stundenplan information but with different types - SELECT 'stundenplan_eintrag' as eintrags_type, ort_kurzbz, studiengang_kz, uid, stunde, datum, titel, semester, verband, gruppe, gruppe_kurzbz, stg_kurzbz, CONCAT(UPPER(sp.stg_typ),UPPER(sp.stg_kurzbz),'-',COALESCE(CAST(sp.semester AS varchar),'/'),COALESCE(CAST(sp.verband AS varchar),'/')) AS stg, CONCAT(lehrfach,'-',lehrform) AS lv_info, * FROM lehre.vw_stundenplan sp + SELECT 'stundenplan_eintrag' as eintrags_type, CONCAT(UPPER(sp.stg_typ),UPPER(sp.stg_kurzbz),'-',COALESCE(CAST(sp.semester AS varchar),'/'),COALESCE(CAST(sp.verband AS varchar),'/')) AS stg, CONCAT(lehrfach,'-',lehrform) AS lv_info, ort_kurzbz, studiengang_kz, uid, stunde, datum, titel, semester, verband, gruppe, gruppe_kurzbz, stg_kurzbz, * FROM lehre.vw_stundenplan sp WHERE ort_kurzbz = ? AND datum >= ? AND datum <= ? UNION ALL - SELECT 'reservierungs_eintrag' as eintrags_type, ort_kurzbz, studiengang_kz, uid, stunde, datum, titel, semester, verband, gruppe, gruppe_kurzbz, stg_kurzbz, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL FROM lehre.vw_reservierung res + SELECT 'reservierungs_eintrag' as eintrags_type, NULL, NULL, ort_kurzbz, studiengang_kz, uid, stunde, datum, titel, semester, verband, gruppe, gruppe_kurzbz, stg_kurzbz, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL FROM lehre.vw_reservierung res WHERE ort_kurzbz = ? AND datum >= ? AND datum <= ? - "*/ + ", [$ort_kurzbz, $start_date, $end_date,$ort_kurzbz, $start_date, $end_date]); + */ + $raum_stundenplan= $this->execReadOnlyQuery(" SELECT CONCAT(UPPER(sp.stg_typ),UPPER(sp.stg_kurzbz),'-',COALESCE(CAST(sp.semester AS varchar),'/'),COALESCE(CAST(sp.verband AS varchar),'/')) AS stg, CONCAT(lehrfach,'-',lehrform) AS lv_info, * FROM lehre.vw_stundenplan sp WHERE ort_kurzbz = ? AND datum >= ? AND datum <= ? - ", [$ort_kurzbz, $start_date, $end_date]); + ", [$ort_kurzbz, $start_date, $end_date]); return $raum_stundenplan; } diff --git a/public/js/apps/Cis/RoomInformation.js b/public/js/apps/Cis/RoomInformation.js index d485227b2..e64348dd8 100644 --- a/public/js/apps/Cis/RoomInformation.js +++ b/public/js/apps/Cis/RoomInformation.js @@ -1,7 +1,7 @@ import FhcCalendar from "../../components/Calendar/Calendar.js"; import CalendarDate from "../../composables/CalendarDate.js"; import FhcApi from "../../plugin/FhcApi.js"; - +import Phrasen from "../../plugin/Phrasen.js"; const app = Vue.createApp({ components: { FhcCalendar @@ -10,7 +10,9 @@ const app = Vue.createApp({ return { stunden: [], events: null, - calendarWeek: new CalendarDate(new Date("2024-06-06")), + calendarWeek: new CalendarDate(new Date("2024-05-07")), + reservierungenLoaded:false, + stundenplanLoaded:false, } }, computed:{ @@ -59,14 +61,16 @@ const app = Vue.createApp({ }); this.events = res.data; + this.stundenplanLoaded = true; + console.log(this.events,"this are the events") } }); - this.$fhcApi.factory.stundenplan.getReservierungen('SEM_E0.04', this.weekFirstDay, this.weekLastDay).then(res => { + /* this.$fhcApi.factory.stundenplan.getReservierungen('EDV_F4.26', this.weekFirstDay, this.weekLastDay).then(res => { if (res.data && res.data.forEach) { res.data.forEach((el, i) => { el.reservierung = true; - el.color = '#CCCCCC'; + el.color = '#' + (el.farbe || 'ffffff'); el.start = new Date(el.datum + ' ' + this.stunden[el.stunde].beginn); el.end = new Date(el.datum + ' ' + this.stunden[el.stunde].ende); el.title = el.titel; @@ -77,29 +81,40 @@ const app = Vue.createApp({ } let reservierungs_events = res.data; + + // adding the last reservierung twice for testing purposes + let last_reservierung=Object.assign({}, reservierungs_events[reservierungs_events.length-1]); + last_reservierung.person_kurzbz="drSimml"; + reservierungs_events.push(last_reservierung); + console.log(reservierungs_events, " this are the reserverungs event") this.events = [...(this.events?this.events:[]),...reservierungs_events]; - - }); + this.reservierungenLoaded=true; + console.log(reservierungs_events,"this are the reservierungs events") + }); */ }); }, template: /*html*/`
- -
- - - {{event.orig.reservierung? event.orig.title :event.orig.lv_info}} - {{event.orig.stg}} - {{item}} - {{event.orig.reservierung? event.orig.person_kurzbz : event.orig.lektor}} - -
+ + + +

this is a reservierung

`, }); app.config.unwrapInjectedRef = true; app.use(FhcApi); +app.use(Phrasen); app.mount('#content'); \ No newline at end of file diff --git a/public/js/components/Calendar/Calendar.js b/public/js/components/Calendar/Calendar.js index 4ce70911e..cef013ff5 100755 --- a/public/js/components/Calendar/Calendar.js +++ b/public/js/components/Calendar/Calendar.js @@ -148,9 +148,9 @@ export default { template: `
- + - +
{{event.orig.title}} {{event.orig.ort_kurzbz}} diff --git a/public/js/components/Calendar/Week.js b/public/js/components/Calendar/Week.js index b4ec09e52..a6389fe52 100755 --- a/public/js/components/Calendar/Week.js +++ b/public/js/components/Calendar/Week.js @@ -42,8 +42,8 @@ export default {
- - + +
` diff --git a/public/js/components/Calendar/Week/Page.js b/public/js/components/Calendar/Week/Page.js index c6636ad43..db28e7028 100755 --- a/public/js/components/Calendar/Week/Page.js +++ b/public/js/components/Calendar/Week/Page.js @@ -111,9 +111,10 @@ export default {
{{hour}}:00
- - - +
+ +
+
From d1afd9f09d7707f984c67f1322c2ce7273514308 Mon Sep 17 00:00:00 2001 From: SimonGschnell Date: Wed, 12 Jun 2024 14:42:30 +0200 Subject: [PATCH 12/34] groups the uids of the reservierungen in the raum uebersicht and renders different template if the calender entry is a reservierung or a stundenplan event --- .../api/frontend/v1/Stundenplan.php | 118 ++++++++++++------ public/js/apps/Cis/RoomInformation.js | 78 ++++++------ public/js/components/Calendar/Calendar.js | 8 +- public/js/components/Calendar/Week/Page.js | 4 +- 4 files changed, 122 insertions(+), 86 deletions(-) diff --git a/application/controllers/api/frontend/v1/Stundenplan.php b/application/controllers/api/frontend/v1/Stundenplan.php index 2bff6016f..80e4415b5 100644 --- a/application/controllers/api/frontend/v1/Stundenplan.php +++ b/application/controllers/api/frontend/v1/Stundenplan.php @@ -75,16 +75,10 @@ class Stundenplan extends FHCAPI_Controller $start_date = $this->input->get('start_date', TRUE); $end_date = $this->input->get('end_date', TRUE); + //return early if the get parameter are not present if(!$ort_kurzbz || !$start_date || !$end_date){ $this->terminateWithError("Missing parameters", self::ERROR_TYPE_GENERAL); } - - $this->addMeta("test_start_date",$start_date); - - $this->addMeta("ort",$ort_kurzbz); - $this->addMeta("start date",$start_date); - $this->addMeta("end date",$end_date); - $this->addMeta("testKey","testValue"); $this->load->model('ressource/Stundenplan_model', 'StundenplanModel'); $this->load->model('ressource/Stunde_model', 'StundeModel'); @@ -99,7 +93,7 @@ class Stundenplan extends FHCAPI_Controller $result = $this->StundenplanModel->getRoomDataOnDay($ort_kurzbz,$start_date,$end_date); // logging the result of the query - //$this->loglib->logErrorDB(print_r($result,true),"this is the result of the query"); + $this->loglib->logErrorDB(print_r($result,true),"this is the result of the original stundenplan query"); if(isError($result)){ @@ -107,14 +101,9 @@ class Stundenplan extends FHCAPI_Controller } $result = hasData($result) ? getData($result) : []; - $this->loglib->logInfoDB(print_r($result,true),"result"); - // set up the log library and configure the library to log to the db + $this->loglib->logInfoDB(print_r(count($result),true),"this is the count of the result"); - /* foreach($result as $event){ - $this->loglib->logInfoDB($event->datum,"NEW DATE"); - } */ - //TODO: also implement the following algorithm to block the lectures that are together over different stunden /* $blockcontinue=false; if (isset($blocked[$this->std_plan[$i][$j][$idx]->unr]) && $blocked[$this->std_plan[$i][$j][$idx]->unr]>0) @@ -248,14 +237,12 @@ class Stundenplan extends FHCAPI_Controller //Lektoren if(!mb_strstr($stunden_event->lektor,$stunden_event_compare->lektor)){ - $this->loglib->logErrorDB($stunden_event->datum ."-". $stunden_event->stunde,"entered lektor - first if"); $stunden_events[$event_key]->lektor = $stunden_event->lektor . ' \ ' . $stunden_event_compare->lektor; $stunden_events[$event_key]->mitarbeiter_kurzbz = $stunden_event->mitarbeiter_kurzbz . ' \ ' . $stunden_event_compare->mitarbeiter_kurzbz; } //Ort if(!mb_strstr($stunden_event->ort_kurzbz,$stunden_event_compare->ort_kurzbz)){ - $this->loglib->logErrorDB($stunden_event->datum ."-". $stunden_event->stunde,"entered ort - second if"); $stunden_events[$event_key]->ort_kurzbz = $stunden_event->ort_kurzbz . ' \ ' . $stunden_event_compare->ort_kurzbz; } @@ -265,8 +252,7 @@ class Stundenplan extends FHCAPI_Controller //Lehrverband if(!mb_strstr($lehrverband_array[$event_key],$lehrverband_array[$compare_key])){ - $this->loglib->logErrorDB($stunden_event->datum ."-". $stunden_event->stunde,"entered gruppe - third if"); - $lehrverband_array[$event_key] .= ' / ' . $lehrverband_array[$compare_key]; + $lehrverband_array[$event_key] .= ' / ' . $lehrverband_array[$compare_key]; } } @@ -280,22 +266,9 @@ class Stundenplan extends FHCAPI_Controller } - /* if (count($stunden_events) == 1){ - $final_events[] = current($stunden_events); - }else if(count($stunden_events) > 1){ - $gruppe = ''; - foreach($stunden_events as $stunden_event){ - $gruppe .= $stunden_event->gruppe . ','; - } - current($stunden_events)->gruppe = $gruppe; - $final_events[] = current($stunden_events); - } */ - //$this->loglib->logInfoDB(print_r($stunden_events,true),"date: " . $date . " - stunde:" .$stunde->stunde); + } - /* $this->loglib->logInfoDB(print_r($testStartDate,true),"startdate"); - $this->loglib->logInfoDB($count,"count"); - $this->loglib->logInfoDB(print_r($testEndDate,true),"enddate"); - */ + $testStartDate->modify('+1 day'); $count++; } @@ -305,9 +278,7 @@ class Stundenplan extends FHCAPI_Controller $phpStartDate = new DateTime($start_date); //$phpStartDate->modify('+1 day'); - $this->addMeta('result',$phpStartDate); - - error_log("test".print_r($result,true)); + $this->loglib->logErrorDB(print_r($final_events,true),"this is the result of the stundenplan query"); //echo($this->db->last_query()); $this->terminateWithSuccess($final_events); @@ -328,13 +299,84 @@ class Stundenplan extends FHCAPI_Controller } $this->load->model('ressource/Reservierung_model', 'ReservierungModel'); - + $this->load->model('ressource/Mitarbeiter_model','MitarbeiterModel'); $result = $this->ReservierungModel->getRoomReservierungen($ort_kurzbz, $start_date, $end_date); if (isError($result)) return $this->terminateWithError(getError($result), self::ERROR_TYPE_GENERAL); + $this->load->library('LogLib'); + $this->loglib->logErrorDB(print_r(getData($result),true),"this is the result of the reservierungen query"); + + $result = hasData($result) ? getData($result) : []; - $this->terminateWithSuccess(getData($result)); + // fetching the stunden to do a loop over the days and the stunden + $this->load->model('ressource/Stunde_model', 'StundeModel'); + $stunden = $this->StundeModel->load(); + if(isError($stunden)){ + $this->terminateWithError(getError($stunden), self::ERROR_TYPE_GENERAL); + } + $stunden = getData($stunden); + + $testStartDate = new DateTime($start_date); + $testEndDate = new DateTime($end_date); + $count =0; + $final_events = array(); + $grouped = array(); + + $final_reservierungen = array(); + + // loop over the days + while($testStartDate <= $testEndDate && $count <7){ + + $date = $testStartDate->format('Y-m-d'); + + // filtering all the reservierungen with the date + $day_reservierungen = array_filter($result, function($result_entry) use ($date){ + return $result_entry->datum == $date; + }); + + // loop over the stunden + foreach( $stunden as $stunde){ + // filtering all the day reservierungen to the reservierungen that happen at the same hour of the day + $hour_reservierungen = array_filter($day_reservierungen, function($day_entry) use ($stunde){ + return $day_entry->stunde == $stunde->stunde; + }); + + // if there are no reservierungen within that hour than we skip that iteration of the loop + if(!count($hour_reservierungen)){ + continue; + } + + // looping over the reservierungen that happen at the same day and at the same hour + + $grouped_uid = array(); + foreach($hour_reservierungen as $grouping_reservierung){ + $grouped_uid[]= $grouping_reservierung->uid; + } + + $final_reservierung = $hour_reservierungen[0]; + + + $grouped_uid = array_map(function($uid){ + $res =$this->MitarbeiterModel->generateKurzbz($uid); + $res = hasData($res)? getData($res): $uid; + return $res; + },$grouped_uid); + $this->loglib->logErrorDB(print_r($grouped_uid,true),"this are the grouped uids"); + + $final_reservierung->person_kurzbz = implode(" / ",$grouped_uid); + + $final_reservierungen[] = $final_reservierung; + } + + + $testStartDate->modify('+1 day'); + ++$count; + + } + $this->loglib->logErrorDB(print_r($final_reservierungen,true),"lalala"); + + $this->terminateWithSuccess($final_reservierungen); } } diff --git a/public/js/apps/Cis/RoomInformation.js b/public/js/apps/Cis/RoomInformation.js index e64348dd8..db15979da 100644 --- a/public/js/apps/Cis/RoomInformation.js +++ b/public/js/apps/Cis/RoomInformation.js @@ -10,9 +10,8 @@ const app = Vue.createApp({ return { stunden: [], events: null, - calendarWeek: new CalendarDate(new Date("2024-05-07")), - reservierungenLoaded:false, - stundenplanLoaded:false, + calendarWeek: new CalendarDate(new Date()), + events_loaded:false, } }, computed:{ @@ -46,7 +45,7 @@ const app = Vue.createApp({ // old testing room EDV_A6.09 - this.$fhcApi.factory.stundenplan.getRoomInfo('SEM_E0.04', this.weekFirstDay, this.weekLastDay).then(res =>{ + this.$fhcApi.factory.stundenplan.getRoomInfo('EDV_F4.26', this.weekFirstDay, this.weekLastDay).then(res =>{ let events; if (res.data && res.data.forEach) { res.data.forEach((el, i) => { @@ -61,55 +60,54 @@ const app = Vue.createApp({ }); this.events = res.data; - this.stundenplanLoaded = true; - console.log(this.events,"this are the events") } + + this.$fhcApi.factory.stundenplan.getReservierungen('EDV_F4.26', this.weekFirstDay, this.weekLastDay).then(res => { + if (res.data && res.data.forEach) { + res.data.forEach((el, i) => { + el.reservierung = true; + el.color = '#' + (el.farbe || 'ffffff'); + el.start = new Date(el.datum + ' ' + this.stunden[el.stunde].beginn); + el.end = new Date(el.datum + ' ' + this.stunden[el.stunde].ende); + el.title = el.titel; + if (el.lehrform) + el.title += '-' + el.lehrform; + }); + + } + + let reservierungs_events = res.data; + console.log(reservierungs_events,"this are the reservierungs events that are getting from the db query") + this.events = [...(this.events?this.events:[]),...reservierungs_events]; + this.events_loaded = true; + + }); }); - /* this.$fhcApi.factory.stundenplan.getReservierungen('EDV_F4.26', this.weekFirstDay, this.weekLastDay).then(res => { - if (res.data && res.data.forEach) { - res.data.forEach((el, i) => { - el.reservierung = true; - el.color = '#' + (el.farbe || 'ffffff'); - el.start = new Date(el.datum + ' ' + this.stunden[el.stunde].beginn); - el.end = new Date(el.datum + ' ' + this.stunden[el.stunde].ende); - el.title = el.titel; - if (el.lehrform) - el.title += '-' + el.lehrform; - }); - - } - - let reservierungs_events = res.data; - - // adding the last reservierung twice for testing purposes - let last_reservierung=Object.assign({}, reservierungs_events[reservierungs_events.length-1]); - last_reservierung.person_kurzbz="drSimml"; - reservierungs_events.push(last_reservierung); - - console.log(reservierungs_events, " this are the reserverungs event") - this.events = [...(this.events?this.events:[]),...reservierungs_events]; - this.reservierungenLoaded=true; - console.log(reservierungs_events,"this are the reservierungs events") - }); */ + }); }, template: /*html*/`
- + - -

this is a reservierung

`, diff --git a/public/js/components/Calendar/Calendar.js b/public/js/components/Calendar/Calendar.js index cef013ff5..4fb4c821e 100755 --- a/public/js/components/Calendar/Calendar.js +++ b/public/js/components/Calendar/Calendar.js @@ -150,13 +150,7 @@ export default { - -
- {{event.orig.title}} - {{event.orig.ort_kurzbz}} - {{event.orig.mitarbeiter_kurzbz}} -
-
+
` } diff --git a/public/js/components/Calendar/Week/Page.js b/public/js/components/Calendar/Week/Page.js index db28e7028..efaaff131 100755 --- a/public/js/components/Calendar/Week/Page.js +++ b/public/js/components/Calendar/Week/Page.js @@ -112,7 +112,9 @@ export default {
- + +

this is a placeholder which means that no template was passed to the Calendar Page slot

+
From de4accab83ed1d252f32bda20ab61d9a9e3d3133 Mon Sep 17 00:00:00 2001 From: SimonGschnell Date: Thu, 13 Jun 2024 12:27:09 +0200 Subject: [PATCH 13/34] cleans up the Stundenplan grouping algorithm --- .../api/frontend/v1/Stundenplan.php | 260 +++++++----------- 1 file changed, 99 insertions(+), 161 deletions(-) diff --git a/application/controllers/api/frontend/v1/Stundenplan.php b/application/controllers/api/frontend/v1/Stundenplan.php index 80e4415b5..222d472d6 100644 --- a/application/controllers/api/frontend/v1/Stundenplan.php +++ b/application/controllers/api/frontend/v1/Stundenplan.php @@ -68,8 +68,10 @@ class Stundenplan extends FHCAPI_Controller */ public function roomInformation() { + + $this->load->model('ressource/Stundenplan_model', 'StundenplanModel'); + $this->load->model('ressource/Stunde_model', 'StundeModel'); - //TODO please split this algorithm into multiple smaller function it is not really mantainable like this // storing the get parameter in local variables $ort_kurzbz = $this->input->get('ort_kurzbz', TRUE); $start_date = $this->input->get('start_date', TRUE); @@ -80,21 +82,15 @@ class Stundenplan extends FHCAPI_Controller $this->terminateWithError("Missing parameters", self::ERROR_TYPE_GENERAL); } - $this->load->model('ressource/Stundenplan_model', 'StundenplanModel'); - $this->load->model('ressource/Stunde_model', 'StundeModel'); + // querying the stunden + $stunden = $this->StundeModel->load(); - - $stunden = $this->StundeModel->load(); - if(isError($stunden)){ + if(isError($stunden)) $this->terminateWithError(getError($stunden), self::ERROR_TYPE_GENERAL); - } + $stunden = getData($stunden); - - $result = $this->StundenplanModel->getRoomDataOnDay($ort_kurzbz,$start_date,$end_date); - // logging the result of the query - $this->loglib->logErrorDB(print_r($result,true),"this is the result of the original stundenplan query"); - + $result = $this->StundenplanModel->getRoomDataOnDay($ort_kurzbz,$start_date,$end_date); if(isError($result)){ $this->terminateWithError(getError($result), self::ERROR_TYPE_GENERAL); @@ -103,76 +99,24 @@ class Stundenplan extends FHCAPI_Controller $result = hasData($result) ? getData($result) : []; $this->loglib->logInfoDB(print_r(count($result),true),"this is the count of the result"); - - //TODO: also implement the following algorithm to block the lectures that are together over different stunden - /* $blockcontinue=false; - if (isset($blocked[$this->std_plan[$i][$j][$idx]->unr]) && $blocked[$this->std_plan[$i][$j][$idx]->unr]>0) - { - $blocked[$this->std_plan[$i][$j][$idx]->unr]--; - $blockcontinue=true; - } - - if (!$blockcontinue) - { - // Blockungen ueber mehrere Stunden erkennen - - $blockflag=false; - for ($blockstunden=1;$blockstunden<=$num_rows_stunde;$blockstunden++) - { - if (isset($this->std_plan[$i][$j+$blockstunden][$idx]) && isset($this->std_plan[$i][$j+$blockstunden][$idx]->stundenplan_id) - && ($this->std_plan[$i][$j][$idx]->unr == $this->std_plan[$i][$j+$blockstunden][$idx]->unr) - && $this->std_plan[$i][$j][$idx]!='0' && $k<($num_rows_stunde-$blockstunden) - && !($this->std_plan[$i][$j][$idx]->reservierung && $this->std_plan[$i][$j][$idx]->lektor!=$this->std_plan[$i][$j+$blockstunden][$idx]->lektor)) - { - - if (isset($blocked[$this->std_plan[$i][$j][$idx]->unr])) - $blocked[$this->std_plan[$i][$j][$idx]->unr]++; - else - $blocked[$this->std_plan[$i][$j][$idx]->unr]=1; - $row = $this->db_fetch_object($this->stunde, ($k+$blockstunden)); - $stunden_arr[]=$row->stunde; - $end_time=$row->ende; - $blockflag=true; - } - else - { - if (!$blockflag) - { - $row = $this->db_fetch_object($this->stunde, $k); - $stunden_arr[]=$row->stunde; - $end_time=$row->ende; - break; - } - else - { - break; - } - } - } - } */ - - $testStartDate = new DateTime($start_date); - $testEndDate = new DateTime($end_date); - $count =0; + $final_events = array(); $grouped = array(); - while($testStartDate <= $testEndDate && $count <7){ - $date = $testStartDate->format('Y-m-d'); - //TODO: array filtering for every day and hour could be too time consuming causing slow response - $day_events = array_filter($result,function($entry) use ($date){ - return $entry->datum == $date; - }); - //$this->loglib->logInfoDB(print_r($day_events,true),"day_events"); + $associative_day_events = $this->filterEventsIntoAssociativeDateArray($result, $start_date, $end_date); + foreach($associative_day_events as $date => $day_events ){ + foreach($stunden as $stunde){ + + // filtering all the events at the same hour of the day $stunden_events = array_filter($day_events, function($entry) use ($stunde){ return $entry->stunde == $stunde->stunde; }); $lehrverband_array = array(); - // for loop that is just used to fill the lehrverband_array foreach($stunden_events as $key=>$stunden_event){ + // lehrverband bestimmen if(strlen($stunden_event->gruppe_kurzbz)>0){ $lehrverband = $stunden_event->gruppe_kurzbz; @@ -188,25 +132,22 @@ class Stundenplan extends FHCAPI_Controller $lehrverband_array[$key] = $lehrverband; } - - // aenderung aller events die am gleichen tag und zur gleichen Stunde gehalten werden + // compare nested loop start foreach($stunden_events as $event_key => $stunden_event){ + + // skip the loop iteration if the event was already grouped if(isset($grouped[$event_key])){ continue; } // lektor bestimmen - if($stunden_event->mitarbeiter_kurzbz == null){ - $simml_lektor = $stunden_event->lektor; - }else{ - $simml_lektor = $stunden_event->mitarbeiter_kurzbz; + if($stunden_event->mitarbeiter_kurzbz != null){ + $stunden_events[$event_key]->lektor = $stunden_event->mitarbeiter_kurzbz; } - // lehrfach bestimmen - $lehrfach = $stunden_event->lehrfach; if(isset($stunden_event->lehrform)){ - $lehrfach .= '-'.$stunden_event->lehrform; + $stunden_events[$event_key]->lehrfach .= '-'.$stunden_event->lehrform; } // GRUPIEREN DER GLEICHEN EVENTS @@ -216,24 +157,19 @@ class Stundenplan extends FHCAPI_Controller if($compare_key != $event_key){ // will be used to skip the loop iteration with this index because it was already grouped - $grouped[$compare_key] = 1; - // this if checks if the events can be grouped + $grouped[$compare_key] = TRUE; + + // can the events be grouped? if ( // the unr's have to be equal to be grouped $stunden_event->unr==$stunden_event_compare->unr && // and either the lektor or the ort_kurzbz have to be equal ($stunden_event->ort_kurzbz==$stunden_event_compare->ort_kurzbz || $stunden_event->lektor==$stunden_event_compare->lektor) - // reservierungen muessen auch beachtet werden, wenn der eintrag eine reservierung ist dann koennen die eintraege nicht gruppiert werden - //&& !$stunden_event->reservierung && !$stunden_event_compare->reservierung - ) { - - - // Bezeichnung des Events zusammenfuehren - // change the event with the $event_key if the compared_event has different properties but is still groupable + // group the events properties if they are groupable //Lektoren if(!mb_strstr($stunden_event->lektor,$stunden_event_compare->lektor)){ @@ -246,10 +182,6 @@ class Stundenplan extends FHCAPI_Controller $stunden_events[$event_key]->ort_kurzbz = $stunden_event->ort_kurzbz . ' \ ' . $stunden_event_compare->ort_kurzbz; } - //unset the compared and grouped event - unset($stunden_events[$compare_key]); - - //Lehrverband if(!mb_strstr($lehrverband_array[$event_key],$lehrverband_array[$compare_key])){ $lehrverband_array[$event_key] .= ' / ' . $lehrverband_array[$compare_key]; @@ -262,83 +194,54 @@ class Stundenplan extends FHCAPI_Controller // add the grouped lehrverband entry to the event $stunden_events[$event_key]->stg = $lehrverband_array[$event_key]; $final_events[] = $stunden_events[$event_key]; - - - } - } - - $testStartDate->modify('+1 day'); - $count++; } - - //php start date - $phpStartDate = new DateTime($start_date); - - //$phpStartDate->modify('+1 day'); - $this->loglib->logErrorDB(print_r($final_events,true),"this is the result of the stundenplan query"); - - //echo($this->db->last_query()); $this->terminateWithSuccess($final_events); } public function Reservierungen() { + $this->load->model('ressource/Reservierung_model', 'ReservierungModel'); + $this->load->model('ressource/Stunde_model', 'StundeModel'); + $this->load->model('ressource/Mitarbeiter_model','MitarbeiterModel'); - //TODO the reservierungen have to be grouped like the stundenplan - + // storing the get parameter in local variables $ort_kurzbz = $this->input->get('ort_kurzbz', TRUE); $start_date = $this->input->get('start_date', TRUE); $end_date = $this->input->get('end_date', TRUE); + // return early if the get parameter are not present if(!$ort_kurzbz || !$start_date || !$end_date){ $this->terminateWithError("Missing parameters", self::ERROR_TYPE_GENERAL); } - $this->load->model('ressource/Reservierung_model', 'ReservierungModel'); - $this->load->model('ressource/Mitarbeiter_model','MitarbeiterModel'); + // querying the stunden + $stunden = $this->StundeModel->load(); + + if(isError($stunden)) + $this->terminateWithError(getError($stunden), self::ERROR_TYPE_GENERAL); + + $stunden = getData($stunden); + + // querying the reservierungen $result = $this->ReservierungModel->getRoomReservierungen($ort_kurzbz, $start_date, $end_date); if (isError($result)) return $this->terminateWithError(getError($result), self::ERROR_TYPE_GENERAL); - $this->load->library('LogLib'); - $this->loglib->logErrorDB(print_r(getData($result),true),"this is the result of the reservierungen query"); - + $result = hasData($result) ? getData($result) : []; - - // fetching the stunden to do a loop over the days and the stunden - $this->load->model('ressource/Stunde_model', 'StundeModel'); - $stunden = $this->StundeModel->load(); - if(isError($stunden)){ - $this->terminateWithError(getError($stunden), self::ERROR_TYPE_GENERAL); - } - $stunden = getData($stunden); - - $testStartDate = new DateTime($start_date); - $testEndDate = new DateTime($end_date); - $count =0; - $final_events = array(); - $grouped = array(); - - $final_reservierungen = array(); - + // loop over the days - while($testStartDate <= $testEndDate && $count <7){ - - $date = $testStartDate->format('Y-m-d'); - - // filtering all the reservierungen with the date - $day_reservierungen = array_filter($result, function($result_entry) use ($date){ - return $result_entry->datum == $date; - }); + $day_events = $this->filterEventsIntoAssociativeDateArray($result, $start_date, $end_date); + foreach($day_events as $date => $day_eventArray){ // loop over the stunden foreach( $stunden as $stunde){ // filtering all the day reservierungen to the reservierungen that happen at the same hour of the day - $hour_reservierungen = array_filter($day_reservierungen, function($day_entry) use ($stunde){ + $hour_reservierungen = array_filter($day_eventArray, function($day_entry) use ($stunde){ return $day_entry->stunde == $stunde->stunde; }); @@ -347,37 +250,72 @@ class Stundenplan extends FHCAPI_Controller continue; } - // looping over the reservierungen that happen at the same day and at the same hour - - $grouped_uid = array(); - foreach($hour_reservierungen as $grouping_reservierung){ - $grouped_uid[]= $grouping_reservierung->uid; + $grouped_uids = array(); + foreach($hour_reservierungen as $entry){ + + $mitarbeiter_check = $this->MitarbeiterModel->isMitarbeiter($entry->uid); + + if(isError($mitarbeiter_check)){ + $this->terminateWithError(getError($mitarbeiter_check), self::ERROR_TYPE_GENERAL); + } + + $mitarbeiter_check = getData($mitarbeiter_check); + + // if the uid belongs to a mitarbeiter store the mitarbeiter_kurzbz otherwise store the student uid + if($mitarbeiter_check){ + $mitarbeiterKurzbz = $this->MitarbeiterModel->generateKurzbz($entry->uid); + + if(isError($mitarbeiterKurzbz)){ + $this->terminateWithError(getError($mitarbeiterKurzbz), self::ERROR_TYPE_GENERAL); + } + + $grouped_uids[] = getData($mitarbeiterKurzbz); + + }else{ + $grouped_uids[]= $entry->uid; + } + } + // merging all the information into the first entry $final_reservierung = $hour_reservierungen[0]; - - $grouped_uid = array_map(function($uid){ - $res =$this->MitarbeiterModel->generateKurzbz($uid); - $res = hasData($res)? getData($res): $uid; - return $res; - },$grouped_uid); - $this->loglib->logErrorDB(print_r($grouped_uid,true),"this are the grouped uids"); - - $final_reservierung->person_kurzbz = implode(" / ",$grouped_uid); + $final_reservierung->person_kurzbz = implode(" / ",$grouped_uids); $final_reservierungen[] = $final_reservierung; } - - - $testStartDate->modify('+1 day'); - ++$count; } - $this->loglib->logErrorDB(print_r($final_reservierungen,true),"lalala"); - $this->terminateWithSuccess($final_reservierungen); } + private function filterEventsIntoAssociativeDateArray($events, $start_date, $end_date){ + $php_start_date = new DateTime($start_date); + $php_end_date = new DateTime($end_date); + // count is used to ensure that the loop does not iterate more than 7 times (7 days per week) + $count =0; + + $result = array(); + + // loop over the days + while($php_start_date <= $php_end_date && $count <7){ + + $date = $php_start_date->format('Y-m-d'); + + // filtering all the reservierungen with the date + $day_events = array_filter($events, function($event) use ($date){ + // no filtering is done if the event entries do not have a datum property + return isset($event->datum) ? $event->datum == $date : true; + + }); + + $result[$date] = $day_events; + ++$count; + $php_start_date->modify('+1 day'); + } + + return $result; + } + } From dd7c8480f3913eaeba916c3583594a540eb7eea5 Mon Sep 17 00:00:00 2001 From: SimonGschnell Date: Thu, 13 Jun 2024 12:29:36 +0200 Subject: [PATCH 14/34] removes unwanted methods and properties from CalendarModal --- .../js/components/Calendar/CalendarModal.js | 114 +----------------- 1 file changed, 2 insertions(+), 112 deletions(-) diff --git a/public/js/components/Calendar/CalendarModal.js b/public/js/components/Calendar/CalendarModal.js index 5f6fd9d09..62263c72e 100644 --- a/public/js/components/Calendar/CalendarModal.js +++ b/public/js/components/Calendar/CalendarModal.js @@ -29,123 +29,13 @@ export default { data() { return { data:this.event, - topic: null, - profilUpdate: null, - editData: this.value, - fileID: null, - breadcrumb: null, - loading: false, - + result: false, info: null, }; }, - methods: { - updateFileIDFunction: function (newFileID) { - this.fileID = newFileID; - }, + - async submitProfilChange() { - //? check if data is valid before making a request - if (this.topic && this.profilUpdate) { - //? if profil update contains any attachment - if (this.fileID) { - const fileData = await this.uploadFiles(this.fileID); - - this.fileID = fileData ? fileData : null; - } - - //? inserts new row in public.tbl_cis_profil_update - //* calls the update api call if an update field is present in the data that was passed to the modal - const handleApiResponse = (res) => { - //? toggles the loading to false and closes the loading modal - this.loading = false; - this.setLoading(false); - - if (res.data.error == 0) { - this.result = true; - this.hide(); - Alert.popup( - "Ihre Anfrage wurde erfolgreich gesendet. Bitte warten Sie, während sich das Team um Ihre Anfrage kümmert." - ); - } else { - this.result = false; - this.hide(); - Alert.popup( - "Ein Fehler ist aufgetreten: " + JSON.stringify(res.data.retval) - ); - } - }; - - //* v-show on EditProfil modal binded to this.loading - //? hides the EditProfil modal and shows the loading modal by calling a callback that was passed as prop from the parent component - this.loading = true; - this.setLoading(true); - - this.editData.updateID - ? Vue.$fhcapi.ProfilUpdate.updateProfilRequest( - this.topic, - this.profilUpdate, - this.editData.updateID, - this.fileID ? this.fileID[0] : null - ) - .then((res) => { - handleApiResponse(res); - }) - .catch((err) => { - console.error(err); - }) - : Vue.$fhcapi.ProfilUpdate.insertProfilRequest( - this.topic, - this.profilUpdate, - this.fileID ? this.fileID[0] : null - ) - .then((res) => { - handleApiResponse(res); - }) - .catch((err) => { - console.error(err); - }); - } - }, - - uploadFiles: async function (files) { - if (files[0].type !== "application/x.fhc-dms+json") { - let formData = new FormData(); - formData.append("files[]", files[0]); - const result = this.editData.updateID - ? //? updating old attachment by replacing - //* second parameter of api request insertFile checks if the file has to be replaced or not - await Vue.$fhcapi.ProfilUpdate.insertFile( - formData, - this.editData.updateID - ).then((res) => { - return res.data?.map((file) => file.dms_id); - }) - : //? fresh insert of new attachment - await Vue.$fhcapi.ProfilUpdate.insertFile(formData).then((res) => { - return res.data?.map((file) => file.dms_id); - }); - return result; - } else { - //? attachment hasn't been replaced - return false; - } - }, - }, - computed: { - start_time: function(){ - if(!this.data.start) return 'N/A'; - return this.data.start.getHours() + ":" + this.data.start.getMinutes(); - }, - end_time: function(){ - if(!this.data.end) return 'N/A'; - return this.data.end.getHours() + ":" + this.data.end.getMinutes(); - } - }, - created() { - console.log("this is an test") - }, mounted() { this.modal = this.$refs.modalContainer.modal; }, From a0472c6573a23f9c559c51daca499ee2da6ab725 Mon Sep 17 00:00:00 2001 From: SimonGschnell Date: Fri, 14 Jun 2024 14:44:29 +0200 Subject: [PATCH 15/34] little changes --- .../controllers/api/frontend/v1/Stundenplan.php | 15 ++++++++++++--- public/js/apps/Cis/RoomInformation.js | 2 +- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/application/controllers/api/frontend/v1/Stundenplan.php b/application/controllers/api/frontend/v1/Stundenplan.php index 222d472d6..fe5ac9e23 100644 --- a/application/controllers/api/frontend/v1/Stundenplan.php +++ b/application/controllers/api/frontend/v1/Stundenplan.php @@ -236,6 +236,7 @@ class Stundenplan extends FHCAPI_Controller // loop over the days $day_events = $this->filterEventsIntoAssociativeDateArray($result, $start_date, $end_date); + $final_reservierungen = array(); foreach($day_events as $date => $day_eventArray){ // loop over the stunden @@ -246,13 +247,18 @@ class Stundenplan extends FHCAPI_Controller }); // if there are no reservierungen within that hour than we skip that iteration of the loop - if(!count($hour_reservierungen)){ + if(count($hour_reservierungen) <1){ continue; } + $this->loglib->logInfoDB(print_r($hour_reservierungen,true),"this is the hour reservierungen"); + + // grouping the reservierung information of reservervations of the same hour on the same day $grouped_uids = array(); foreach($hour_reservierungen as $entry){ + // grouping the reservierungs participants + $mitarbeiter_check = $this->MitarbeiterModel->isMitarbeiter($entry->uid); if(isError($mitarbeiter_check)){ @@ -274,11 +280,14 @@ class Stundenplan extends FHCAPI_Controller }else{ $grouped_uids[]= $entry->uid; } + + // grouping the } + // merging all the information into the first entry - $final_reservierung = $hour_reservierungen[0]; + $final_reservierung = current($hour_reservierungen); $final_reservierung->person_kurzbz = implode(" / ",$grouped_uids); @@ -295,7 +304,7 @@ class Stundenplan extends FHCAPI_Controller // count is used to ensure that the loop does not iterate more than 7 times (7 days per week) $count =0; - $result = array(); + $result = array(); // loop over the days while($php_start_date <= $php_end_date && $count <7){ diff --git a/public/js/apps/Cis/RoomInformation.js b/public/js/apps/Cis/RoomInformation.js index db15979da..af92fe147 100644 --- a/public/js/apps/Cis/RoomInformation.js +++ b/public/js/apps/Cis/RoomInformation.js @@ -97,7 +97,7 @@ const app = Vue.createApp({ @@ -69,6 +69,33 @@ export default { this.updateSearchOptions(); }, methods: { + getActionsForRoom: function(res){ + res.roomoverview= FHC_JS_DATA_STORAGE_OBJECT.app_root + + FHC_JS_DATA_STORAGE_OBJECT.ci_router + + `/CisVue/Cms/getRoomInformation/${res.ort_kurzbz}`; + + if(res.content_id !=="N/A"){ + res.infolink= FHC_JS_DATA_STORAGE_OBJECT.app_root + + FHC_JS_DATA_STORAGE_OBJECT.ci_router + + `/CisVue/Cms/content/${res.content_id}`; + } + + let child = this.searchoptions.actions.raum.childactions.filter((child)=>{ + if(child.label =="Rauminformation" && res.content_id =="N/A"){ + return false; + } + return true; + }); + + let computedActions = { + childactions:child, + defaultaction:this.searchoptions.actions.raum.defaultaction + } + + return computedActions; + + + }, updateSearchOptions: function() { this.searchsettings.types = []; for( const idx in this.searchoptions.types ) { From 9e1bd2b64d89625f7602d58092849b96faa9ea80 Mon Sep 17 00:00:00 2001 From: SimonGschnell Date: Fri, 2 Aug 2024 10:36:34 +0200 Subject: [PATCH 20/34] adds form_validation --- .../api/frontend/v1/Stundenplan.php | 139 ++++-------------- public/js/api/fhcapifactory.js | 2 +- 2 files changed, 26 insertions(+), 115 deletions(-) diff --git a/application/controllers/api/frontend/v1/Stundenplan.php b/application/controllers/api/frontend/v1/Stundenplan.php index 37b384630..614f02919 100644 --- a/application/controllers/api/frontend/v1/Stundenplan.php +++ b/application/controllers/api/frontend/v1/Stundenplan.php @@ -18,11 +18,6 @@ if (! defined('BASEPATH')) exit('No direct script access allowed'); -/** - * This controller operates between (interface) the JS (GUI) and the SearchBarLib (back-end) - * Provides data to the ajax get calls about the searchbar component - * This controller works with JSON calls on the HTTP GET and the output is always JSON - */ class Stundenplan extends FHCAPI_Controller { @@ -46,32 +41,48 @@ class Stundenplan extends FHCAPI_Controller 'dbLogType' => 'API', // required 'dbExecuteUser' => 'RESTful API' )); + + $this->load->library('form_validation'); } //------------------------------------------------------------------------------------------------------------------ // Public methods + /** + * fetches Stunden layout from database + * @access public + * + */ public function Stunden() { $this->load->model('ressource/Stunde_model', 'StundeModel'); - $result = $this->StundeModel->load(); + $stunden = $this->StundeModel->load(); - if (isError($result)) - return $this->terminateWithError(getError($result), self::ERROR_TYPE_GENERAL); + $stunden = $this->getDataOrTerminateWithError($stunden); - $this->terminateWithSuccess(getData($result)); + $this->terminateWithSuccess($stunden); } - - /** - * Gets a JSON body via HTTP POST and provides the parameters - */ + + /** + * fetches room events from a certain date + * @access public + * + */ public function roomInformation() { $this->load->model('ressource/Stundenplan_model', 'StundenplanModel'); $this->load->model('ressource/Stunde_model', 'StundeModel'); - + + // form validation + $this->load->library('form_validation'); + $this->form_validation->set_data($_GET); + $this->form_validation->set_rules('ort_kurzbz',"Ort","required"); + $this->form_validation->set_rules('start_date',"start_date","required"); + $this->form_validation->set_rules('end_date',"end_date","required"); + if($this->form_validation->run() === FALSE) $this->terminateWithValidationErrors($this->form_validation->error_array()); + // storing the get parameter in local variables $ort_kurzbz = $this->input->get('ort_kurzbz', TRUE); $start_date = $this->input->get('start_date', TRUE); @@ -106,106 +117,6 @@ class Stundenplan extends FHCAPI_Controller } } - // this is the old way the events were grouped, kept in case that the query doesnt work out as expected - /* - $final_events = array(); - $grouped = array(); - $associative_day_events = $this->filterEventsIntoAssociativeDateArray($result, $start_date, $end_date); - foreach($associative_day_events as $date => $day_events ){ - - foreach($stunden as $stunde){ - - // filtering all the events at the same hour of the day - $stunden_events = array_filter($day_events, function($entry) use ($stunde){ - return $entry->stunde == $stunde->stunde; - }); - - $lehrverband_array = array(); - - // for loop that is just used to fill the lehrverband_array - foreach($stunden_events as $key=>$stunden_event){ - - // lehrverband bestimmen - if(strlen($stunden_event->gruppe_kurzbz)>0){ - $lehrverband = $stunden_event->gruppe_kurzbz; - }else{ - $lehrverband=$stunden_event->stg_typ . $stunden_event->stg_kurzbz .'-'.$stunden_event->semester; - // checks whether the verband is not null, '' or '0' - if($stunden_event->verband !=null && $stunden_event->verband != '0' && $stunden_event->verband != ''){ - $lehrverband.=$stunden_event->verband; - // if gruppe is not set it will concatenate nothing but it is only appended if the verband is set - $lehrverband.=$stunden_event->gruppe; - } - } - $lehrverband_array[$key] = $lehrverband; - } - - // compare nested loop start - foreach($stunden_events as $event_key => $stunden_event){ - - // skip the loop iteration if the event was already grouped - if(isset($grouped[$event_key])){ - continue; - } - - // lektor bestimmen - if($stunden_event->mitarbeiter_kurzbz != null){ - $stunden_events[$event_key]->lektor = $stunden_event->mitarbeiter_kurzbz; - } - - // lehrfach bestimmen - if(isset($stunden_event->lehrform)){ - $stunden_events[$event_key]->lehrfach .= '-'.$stunden_event->lehrform; - } - - // GRUPIEREN DER GLEICHEN EVENTS - // vergleiche das aktuelle Event mit allen anderen Events die am gleichen Tag und zur gleichen Stunde gehalten werden - foreach($stunden_events as $compare_key => $stunden_event_compare){ - - if($compare_key != $event_key){ - - // will be used to skip the loop iteration with this index because it was already grouped - $grouped[$compare_key] = TRUE; - - // can the events be grouped? - if ( - // the unr's have to be equal to be grouped - $stunden_event->unr==$stunden_event_compare->unr && - // and either the lektor or the ort_kurzbz have to be equal - ($stunden_event->ort_kurzbz==$stunden_event_compare->ort_kurzbz - || $stunden_event->lektor==$stunden_event_compare->lektor) - ) - { - // Bezeichnung des Events zusammenfuehren - // group the events properties if they are groupable - - //Lektoren - if(!mb_strstr($stunden_event->lektor,$stunden_event_compare->lektor)){ - $stunden_events[$event_key]->lektor = $stunden_event->lektor . ' \ ' . $stunden_event_compare->lektor; - $stunden_events[$event_key]->mitarbeiter_kurzbz = $stunden_event->mitarbeiter_kurzbz . ' \ ' . $stunden_event_compare->mitarbeiter_kurzbz; - } - - //Ort - if(!mb_strstr($stunden_event->ort_kurzbz,$stunden_event_compare->ort_kurzbz)){ - $stunden_events[$event_key]->ort_kurzbz = $stunden_event->ort_kurzbz . ' \ ' . $stunden_event_compare->ort_kurzbz; - } - - //Lehrverband - if(!mb_strstr($lehrverband_array[$event_key],$lehrverband_array[$compare_key])){ - $lehrverband_array[$event_key] .= ' / ' . $lehrverband_array[$compare_key]; - } - - } - } - } - - // add the grouped lehrverband entry to the event - $stunden_events[$event_key]->stg = $lehrverband_array[$event_key]; - $final_events[] = $stunden_events[$event_key]; - } - } - } */ - $this->terminateWithSuccess($result); } diff --git a/public/js/api/fhcapifactory.js b/public/js/api/fhcapifactory.js index f8e088ff9..65bde56fd 100644 --- a/public/js/api/fhcapifactory.js +++ b/public/js/api/fhcapifactory.js @@ -31,6 +31,6 @@ export default { filter, studstatus, profil, - profilUpdate,, + profilUpdate, stundenplan, }; From e44c1bccb3e0a85c0584995626a43c0fd5a3b6d5 Mon Sep 17 00:00:00 2001 From: SimonGschnell Date: Mon, 5 Aug 2024 09:17:04 +0200 Subject: [PATCH 21/34] adds shorthands with getDataOrTerminateWithError and adds also form_validation --- .../api/frontend/v1/Stundenplan.php | 42 ++++++------------- 1 file changed, 13 insertions(+), 29 deletions(-) diff --git a/application/controllers/api/frontend/v1/Stundenplan.php b/application/controllers/api/frontend/v1/Stundenplan.php index 614f02919..1e6aa494d 100644 --- a/application/controllers/api/frontend/v1/Stundenplan.php +++ b/application/controllers/api/frontend/v1/Stundenplan.php @@ -88,28 +88,14 @@ class Stundenplan extends FHCAPI_Controller $start_date = $this->input->get('start_date', TRUE); $end_date = $this->input->get('end_date', TRUE); - //return early if the get parameter are not present - if(!$ort_kurzbz || !$start_date || !$end_date){ - $this->terminateWithError("Missing parameters", self::ERROR_TYPE_GENERAL); - } - // querying the stunden $stunden = $this->StundeModel->load(); - if(isError($stunden)) - $this->terminateWithError(getError($stunden), self::ERROR_TYPE_GENERAL); - - $stunden = getData($stunden); + $stunden = $this->getDataOrTerminateWithError($stunden); $result = $this->StundenplanModel->groupedCalendarEvents($ort_kurzbz,$start_date,$end_date); - //$this->loglib->logErrorDB(print_r($result,TRUE),"this is the result of the grouped query"); - if(isError($result)){ - $this->terminateWithError(getError($result), self::ERROR_TYPE_GENERAL); - } - - $result = hasData($result) ? getData($result) : []; - + $result = $this->getDataOrTerminateWithError($result); foreach($result as $entry){ if(COUNT($entry->lektor)>1){ @@ -121,37 +107,35 @@ class Stundenplan extends FHCAPI_Controller } + // reservierungen is not used in the prototype for the students public function Reservierungen() { $this->load->model('ressource/Reservierung_model', 'ReservierungModel'); $this->load->model('ressource/Stunde_model', 'StundeModel'); $this->load->model('ressource/Mitarbeiter_model','MitarbeiterModel'); + //form validation + $this->load->library('form_validation'); + $this->form_validation->set_data($_GET); + $this->form_validation->set_rules('ort_kurzbz',"Ort","required"); + $this->form_validation->set_rules('start_date', "StartDate", "required"); + $this->form_validation->set_rules('end_date', "EndDate", "required"); + if($this->form_validation->run() == FALSE) $this->terminateWithValidationErrors($this->form_validation->error_array()); + // storing the get parameter in local variables $ort_kurzbz = $this->input->get('ort_kurzbz', TRUE); $start_date = $this->input->get('start_date', TRUE); $end_date = $this->input->get('end_date', TRUE); - // return early if the get parameter are not present - if(!$ort_kurzbz || !$start_date || !$end_date){ - $this->terminateWithError("Missing parameters", self::ERROR_TYPE_GENERAL); - } - // querying the stunden $stunden = $this->StundeModel->load(); - if(isError($stunden)) - $this->terminateWithError(getError($stunden), self::ERROR_TYPE_GENERAL); - - $stunden = getData($stunden); + $stunden = $this->getDataOrTerminateWithError($stunden); // querying the reservierungen $result = $this->ReservierungModel->getRoomReservierungen($ort_kurzbz, $start_date, $end_date); - if (isError($result)) - return $this->terminateWithError(getError($result), self::ERROR_TYPE_GENERAL); - - $result = hasData($result) ? getData($result) : []; + $result = $this->getDataOrTerminateWithError($result); // loop over the days $day_events = $this->filterEventsIntoAssociativeDateArray($result, $start_date, $end_date); From 46a070605735fcf940c783b6f5b46325e902cd40 Mon Sep 17 00:00:00 2001 From: SimonGschnell Date: Tue, 6 Aug 2024 14:29:24 +0200 Subject: [PATCH 22/34] updates roomEvents on change:range / groups the results of a studenplan query --- .../api/frontend/v1/Stundenplan.php | 13 +-- .../components/Cis/Stundenplan.php | 8 +- .../models/ressource/Stundenplan_model.php | 67 +++++++++++- .../js/components/Cis/Mylv/RoomInformation.js | 100 ++++++++---------- 4 files changed, 116 insertions(+), 72 deletions(-) diff --git a/application/controllers/api/frontend/v1/Stundenplan.php b/application/controllers/api/frontend/v1/Stundenplan.php index 1e6aa494d..923c7f6bb 100644 --- a/application/controllers/api/frontend/v1/Stundenplan.php +++ b/application/controllers/api/frontend/v1/Stundenplan.php @@ -87,22 +87,11 @@ class Stundenplan extends FHCAPI_Controller $ort_kurzbz = $this->input->get('ort_kurzbz', TRUE); $start_date = $this->input->get('start_date', TRUE); $end_date = $this->input->get('end_date', TRUE); - - // querying the stunden - $stunden = $this->StundeModel->load(); - $stunden = $this->getDataOrTerminateWithError($stunden); - - $result = $this->StundenplanModel->groupedCalendarEvents($ort_kurzbz,$start_date,$end_date); + $result = $this->StundenplanModel->stundenPlanGruppierung($this->StundenplanModel->getRoomQuery($ort_kurzbz, $start_date, $end_date)); $result = $this->getDataOrTerminateWithError($result); - foreach($result as $entry){ - if(COUNT($entry->lektor)>1){ - // gruppierung hat stattgefunden und das array muss in einem String konvertiert werden - } - } - $this->terminateWithSuccess($result); } diff --git a/application/controllers/components/Cis/Stundenplan.php b/application/controllers/components/Cis/Stundenplan.php index 6a89458a7..31ed34dbd 100755 --- a/application/controllers/components/Cis/Stundenplan.php +++ b/application/controllers/components/Cis/Stundenplan.php @@ -30,12 +30,14 @@ class Stundenplan extends Auth_Controller { $this->load->model('ressource/Stundenplan_model', 'StundenplanModel'); - $result = $this->StundenplanModel->loadForUid(get_uid()); + /* $result = $this->StundenplanModel->loadForUid(get_uid()); if (isError($result)) return $this->outputJsonError(getError($result)); - - $this->outputJsonSuccess(getData($result)); + */ + $res = $this->StundenplanModel->stundenPlanGruppierung($this->StundenplanModel->getStudenPlanQuery(get_uid())); + $res = getData($res); + $this->outputJsonSuccess($res); } /** diff --git a/application/models/ressource/Stundenplan_model.php b/application/models/ressource/Stundenplan_model.php index 693825e79..fed70ac74 100755 --- a/application/models/ressource/Stundenplan_model.php +++ b/application/models/ressource/Stundenplan_model.php @@ -133,6 +133,71 @@ class Stundenplan_model extends DB_Model return $gruppierteEvents; } + public function stundenPlanGruppierung($stundenplanViewQuery) + { + + + $gruppierteEvents = $this->execReadOnlyQuery(" + SELECT + + 'stundenplan' as type, + unr,datum, stunde, + CONCAT(lehrfach,'-',lehrform) as topic, + '' as beschreibung, + string_agg(DISTINCT gruppe, '/') as gruppe, + string_agg(DISTINCT lektor, '/') as lektor, + ort_kurzbz, studiengang_kz, titel,'' as beschreibung,lehreinheit_id,lehrfach_id,anmerkung,fix,lehrveranstaltung_id,stg_kurzbzlang,stg_bezeichnung,stg_typ,fachbereich_kurzbz,lehrfach,lehrfach_bez,farbe,lehrform,anmerkung_lehreinheit + + FROM + ( + SELECT + unr,datum, stunde, + 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 gruppe, + CASE + WHEN sp.mitarbeiter_kurzbz IS NOT NULL THEN sp.mitarbeiter_kurzbz + ELSE lektor + END as lektor, + ort_kurzbz, studiengang_kz, titel,'' as beschreibung,lehreinheit_id,lehrfach_id,anmerkung,fix,lehrveranstaltung_id,stg_kurzbzlang,stg_bezeichnung,stg_typ,fachbereich_kurzbz,lehrfach,lehrfach_bez,farbe,lehrform,anmerkung_lehreinheit + + FROM (".$stundenplanViewQuery.") sp + + ) as sp + + GROUP BY + + ort_kurzbz,unr, datum, stunde, lehreinheit_id, lehrfach_id,studiengang_kz,titel,anmerkung,fix,lehrveranstaltung_id,stg_kurzbzlang,stg_bezeichnung,stg_typ,fachbereich_kurzbz,lehrfach,lehrfach_bez,farbe,lehrform,anmerkung_lehreinheit + + ORDER BY datum, stunde + "); + + return $gruppierteEvents; + } + + public function getStudenPlanQuery($uid){ + return + "select sp.* + from lehre.vw_stundenplan sp + left join public.tbl_benutzergruppe bg ON sp.gruppe_kurzbz=bg.gruppe_kurzbz AND bg.uid =".$this->escape($uid)." + left join public.tbl_studiensemester ss1 ON bg.studiensemester_kurzbz=ss1.studiensemester_kurzbz AND ss1.start <=sp.datum AND ss1.ende>= sp.datum + left join public.tbl_studentlehrverband slv ON sp.studiengang_kz=slv.studiengang_kz and slv.student_uid=".$this->escape($uid)." and (slv.semester=sp.semester OR sp.semester IS NULL) AND (slv.verband=sp.verband OR sp.verband IS NULL OR sp.verband='' OR sp.verband='0') AND + (slv.gruppe=sp.gruppe OR sp.gruppe IS NULL OR sp.gruppe='' OR sp.gruppe='0') AND sp.gruppe_kurzbz IS NULL + left join public.tbl_studiensemester ss2 ON slv.studiensemester_kurzbz=ss2.studiensemester_kurzbz AND ss2.start<=sp.datum and ss2.ende >= sp.datum + WHERE ss1.studiensemester_kurzbz IS NOT NULL or ss2.studiensemester_kurzbz IS NOT NULL"; + } + + public function getRoomQuery($ort_kurzbz, $start_date, $end_date) + { + return + "select sp.* + FROM lehre.vw_stundenplan sp + WHERE ort_kurzbz = ".$this->escape($ort_kurzbz)." + AND datum >= ".$this->escape($start_date)." + AND datum <= ".$this->escape($end_date); + } + /** * @param string $uid * @@ -149,7 +214,7 @@ class Stundenplan_model extends DB_Model $this->db->or_where('ss2.studiensemester_kurzbz IS NOT NULL', null, false); $query = $this->db->get_compiled_select('lehre.vw_stundenplan sp'); - + return $this->execQuery($query, [$uid, $uid]); } diff --git a/public/js/components/Cis/Mylv/RoomInformation.js b/public/js/components/Cis/Mylv/RoomInformation.js index 885130a5f..c905dabd8 100644 --- a/public/js/components/Cis/Mylv/RoomInformation.js +++ b/public/js/components/Cis/Mylv/RoomInformation.js @@ -32,6 +32,13 @@ export default{ }, }, methods:{ + updateRange: function(data){ + this.calendarWeek = new CalendarDate(data.start); + Vue.nextTick(() => { + this.loadRoomEvents(); + }); + }, + // returns the string YYYY-MM-DD if param is instance of CalendarDate and null otherwise calendarDateToString: function(calendarDate){ @@ -40,69 +47,50 @@ export default{ null; }, + + loadStunden: async function(){ + await this.$fhcApi.factory.stundenplan.getStunden().then(res => { + res.data.forEach(std => { + this.stunden[std.stunde] = std; // TODO(chris): geht besser + }); + }); + }, + + loadRoomEvents: function(){ + this.$fhcApi.factory.stundenplan.getRoomInfo(this.ort_kurzbz, this.weekFirstDay, this.weekLastDay).then(res => { + let events; + if (res.data && res.data.forEach) { + res.data.forEach((el, i) => { + + el.id = i; + if (el.type === 'reservierung') { + el.color = '#' + (el.farbe || 'FFFFFF'); + } else { + el.color = '#' + (el.farbe || 'CCCCCC'); + } + + el.start = new Date(el.datum + ' ' + this.stunden[el.stunde].beginn); + el.end = new Date(el.datum + ' ' + this.stunden[el.stunde].ende); + el.title = el.lehrfach; + if (el.lehrform) + el.title += '-' + el.lehrform; + }); + + this.events = res.data; + } + }); + } }, - created() { + async mounted() { - this.$fhcApi.factory.stundenplan.getStunden().then(res =>{ - res.data.forEach(std => { - this.stunden[std.stunde] = std; // TODO(chris): geht besser - }); - - - // old testing room EDV_A6.09 - this.$fhcApi.factory.stundenplan.getRoomInfo(this.ort_kurzbz, this.weekFirstDay, this.weekLastDay).then(res =>{ - let events; - if (res.data && res.data.forEach) { - res.data.forEach((el, i) => { - - el.id = i; - if(el.type === 'reservierung') - { - el.color = '#' + (el.farbe || 'FFFFFF'); - }else{ - el.color = '#' + (el.farbe || 'CCCCCC'); - } - - el.start = new Date(el.datum + ' ' + this.stunden[el.stunde].beginn); - el.end = new Date(el.datum + ' ' + this.stunden[el.stunde].ende); - el.title = el.lehrfach; - if (el.lehrform) - el.title += '-' + el.lehrform; - }); - - this.events = res.data; - } - - // reservierungen are loaded with the stundenplan - /* this.$fhcApi.factory.stundenplan.getReservierungen('EDV_F4.26', this.weekFirstDay, this.weekLastDay).then(res => { - if (res.data && res.data.forEach) { - res.data.forEach((el, i) => { - el.reservierung = true; - el.color = '#' + (el.farbe || 'ffffff'); - el.start = new Date(el.datum + ' ' + this.stunden[el.stunde].beginn); - el.end = new Date(el.datum + ' ' + this.stunden[el.stunde].ende); - el.title = el.titel; - if (el.lehrform) - el.title += '-' + el.lehrform; - }); - - } - - let reservierungs_events = res.data; - this.events = [...(this.events?this.events:[]),...reservierungs_events]; - - - }); */ - }); - - - }); + this.loadStunden(); + this.loadRoomEvents(); }, template: /*html*/`
- +
From 8bc8c67f8d16be5253f245c1e39f26ba14cb3c5b Mon Sep 17 00:00:00 2001 From: SimonGschnell Date: Tue, 13 Aug 2024 15:10:23 +0200 Subject: [PATCH 23/34] better comments --- .../models/ressource/Stundenplan_model.php | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/application/models/ressource/Stundenplan_model.php b/application/models/ressource/Stundenplan_model.php index fed70ac74..5936106f2 100755 --- a/application/models/ressource/Stundenplan_model.php +++ b/application/models/ressource/Stundenplan_model.php @@ -133,7 +133,14 @@ class Stundenplan_model extends DB_Model return $gruppierteEvents; } - public function stundenPlanGruppierung($stundenplanViewQuery) + + /** + * function that takes a query that fetches lehre.vw_stundenplan rows and groups them so that they can be displayed in a calendar + * @param string $stundenplanViewQuery the subquery used to group the result + * + * @return stdClass + */ + public function stundenplanGruppierung($stundenplanViewQuery) { @@ -176,6 +183,12 @@ class Stundenplan_model extends DB_Model return $gruppierteEvents; } + /** + * 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_studenplan table + * + * @return string + */ public function getStudenPlanQuery($uid){ return "select sp.* @@ -188,6 +201,14 @@ class Stundenplan_model extends DB_Model WHERE ss1.studiensemester_kurzbz IS NOT NULL or ss2.studiensemester_kurzbz IS NOT NULL"; } + /** + * NO STANDALONE FUNCTION - Generates a SQL query string to fetch 'stundenplan' events for a specific room within a date range. + * @param string $ort_kurzbz the ort from which we want to query the stundenplan events + * @param string $start_date (inclusive) the minimum date that an event should have to be fetched + * @param string $end_date (inclusive) the maximum date that an event should not extend to be fetched + * + * @return string + */ public function getRoomQuery($ort_kurzbz, $start_date, $end_date) { return From f19c1b4eafb8e975bde42cd7f278226c113c3bc8 Mon Sep 17 00:00:00 2001 From: SimonGschnell Date: Mon, 2 Sep 2024 14:47:40 +0200 Subject: [PATCH 24/34] adds the lector and the gruppe as objects to the endpoint result instead of just strings --- .../components/Cis/Stundenplan.php | 44 ++++++++++++++++++- .../models/ressource/Stundenplan_model.php | 26 ++++++----- public/js/apps/Cis/Stundenplan.js | 3 +- public/js/components/Calendar/Calendar.js | 1 - 4 files changed, 60 insertions(+), 14 deletions(-) diff --git a/application/controllers/components/Cis/Stundenplan.php b/application/controllers/components/Cis/Stundenplan.php index 31ed34dbd..8755212af 100755 --- a/application/controllers/components/Cis/Stundenplan.php +++ b/application/controllers/components/Cis/Stundenplan.php @@ -35,8 +35,48 @@ class Stundenplan extends Auth_Controller if (isError($result)) return $this->outputJsonError(getError($result)); */ - $res = $this->StundenplanModel->stundenPlanGruppierung($this->StundenplanModel->getStudenPlanQuery(get_uid())); - $res = getData($res); + + + $res = $this->StundenplanModel->stundenplanGruppierung($this->StundenplanModel->getStudenPlanQuery(get_uid())); + + $res = getData($res); + + // get the benutzer object for the lektor of the lv + $this->load->model('ressource/Mitarbeiter_model','MitarbeiterModel'); + $this->load->model('organisation/Lehrverband_model', 'LehrverbandModel'); + foreach($res as $item){ + $lektor_obj_array = array(); + $gruppe_obj_array = array(); + foreach($item->lektor as $lv_lektor){ + $lektor_obj = $this->MitarbeiterModel->loadWhere(["kurzbz"=>$lv_lektor]); + if (isError($lektor_obj)) { + $this->outputJsonError(getError($lektor_obj)); + } + $lektor_obj = getData($lektor_obj); + $lektor_obj_array[] = $lektor_obj; + } + foreach ($item->gruppe as $lv_gruppe) { + $lv_gruppe = str_replace("(","",$lv_gruppe); + $lv_gruppe = str_replace(")", "", $lv_gruppe); + $lv_gruppe_array = explode(",",$lv_gruppe); + $gruppe = str_replace("\"","",$lv_gruppe_array[0]); + $verband = $lv_gruppe_array[1]; + $semester = $lv_gruppe_array[2]; + $studiengang_kz = $lv_gruppe_array[3]; + $lehrverband_obj = $this->LehrverbandModel->loadWhere(["gruppe" => $gruppe, "verband" => $verband, "semester" => $semester, "studiengang_kz" => $studiengang_kz]); + if (isError($lehrverband_obj)) { + $this->outputJsonError(getError($lehrverband_obj)); + } + $lehrverband_obj = getData($lehrverband_obj); + $gruppe_obj_array[] = $lehrverband_obj; + } + //replace the array of lektor strings with the objects of lektor information + $item->lektor = $lektor_obj_array; + //replace the array of gruppen string with the lehrverband object information + $item->gruppe = $gruppe_obj_array; + + } + $this->outputJsonSuccess($res); } diff --git a/application/models/ressource/Stundenplan_model.php b/application/models/ressource/Stundenplan_model.php index 5936106f2..11299fe3c 100755 --- a/application/models/ressource/Stundenplan_model.php +++ b/application/models/ressource/Stundenplan_model.php @@ -142,8 +142,11 @@ class Stundenplan_model extends DB_Model */ public function stundenplanGruppierung($stundenplanViewQuery) { - + /* 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 gruppe, */ $gruppierteEvents = $this->execReadOnlyQuery(" SELECT @@ -151,23 +154,26 @@ class Stundenplan_model extends DB_Model unr,datum, stunde, CONCAT(lehrfach,'-',lehrform) as topic, '' as beschreibung, - string_agg(DISTINCT gruppe, '/') as gruppe, - string_agg(DISTINCT lektor, '/') as lektor, - ort_kurzbz, studiengang_kz, titel,'' as beschreibung,lehreinheit_id,lehrfach_id,anmerkung,fix,lehrveranstaltung_id,stg_kurzbzlang,stg_bezeichnung,stg_typ,fachbereich_kurzbz,lehrfach,lehrfach_bez,farbe,lehrform,anmerkung_lehreinheit + array_agg(DISTINCT (gruppe,verband,semester,studiengang_kz)) as gruppe, + array_agg(DISTINCT gruppe_bezeichnung) as gruppe_bezeichnung, + array_agg(DISTINCT lektor) as lektor, + + ort_kurzbz, studiengang_kz, titel, lehrform, lehrfach, semester, verband FROM ( SELECT unr,datum, stunde, - 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 gruppe, + CASE WHEN sp.mitarbeiter_kurzbz IS NOT NULL THEN sp.mitarbeiter_kurzbz ELSE lektor END as lektor, - ort_kurzbz, studiengang_kz, titel,'' as beschreibung,lehreinheit_id,lehrfach_id,anmerkung,fix,lehrveranstaltung_id,stg_kurzbzlang,stg_bezeichnung,stg_typ,fachbereich_kurzbz,lehrfach,lehrfach_bez,farbe,lehrform,anmerkung_lehreinheit + 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 gruppe_bezeichnung, + ort_kurzbz, studiengang_kz, titel,'' as beschreibung,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 FROM (".$stundenplanViewQuery.") sp @@ -175,7 +181,7 @@ class Stundenplan_model extends DB_Model GROUP BY - ort_kurzbz,unr, datum, stunde, lehreinheit_id, lehrfach_id,studiengang_kz,titel,anmerkung,fix,lehrveranstaltung_id,stg_kurzbzlang,stg_bezeichnung,stg_typ,fachbereich_kurzbz,lehrfach,lehrfach_bez,farbe,lehrform,anmerkung_lehreinheit + unr, datum, stunde, lehrfach, lehrform, ort_kurzbz, titel, studiengang_kz, lehrform, lehrfach, semester, verband ORDER BY datum, stunde "); diff --git a/public/js/apps/Cis/Stundenplan.js b/public/js/apps/Cis/Stundenplan.js index 47d945c29..70d3f6361 100755 --- a/public/js/apps/Cis/Stundenplan.js +++ b/public/js/apps/Cis/Stundenplan.js @@ -54,9 +54,10 @@ const app = Vue.createApp({
+ {{event.orig.title}} {{event.orig.ort_kurzbz}} - {{event.orig.mitarbeiter_kurzbz}} + {{event.orig.lektor}}
` diff --git a/public/js/components/Calendar/Calendar.js b/public/js/components/Calendar/Calendar.js index 4fb4c821e..00f450d15 100755 --- a/public/js/components/Calendar/Calendar.js +++ b/public/js/components/Calendar/Calendar.js @@ -113,7 +113,6 @@ export default { this.$refs.calendarModal.show(); }) - console.log(day,"this is the day") this.$emit(day[0], day[1]); } }, From 87f82b7f5dd97063df4fd874d3039cf607bb80a9 Mon Sep 17 00:00:00 2001 From: SimonGschnell Date: Tue, 3 Sep 2024 12:07:13 +0200 Subject: [PATCH 25/34] also adds the stundenplan information as object in the response of the endpoint --- .../components/Cis/Stundenplan.php | 24 +++++++++++-------- .../models/ressource/Stundenplan_model.php | 19 +++++---------- public/js/apps/Cis/Stundenplan.js | 3 +-- .../js/components/Calendar/CalendarModal.js | 5 ++-- 4 files changed, 24 insertions(+), 27 deletions(-) diff --git a/application/controllers/components/Cis/Stundenplan.php b/application/controllers/components/Cis/Stundenplan.php index 8755212af..b33a0ddee 100755 --- a/application/controllers/components/Cis/Stundenplan.php +++ b/application/controllers/components/Cis/Stundenplan.php @@ -47,32 +47,36 @@ class Stundenplan extends Auth_Controller foreach($res as $item){ $lektor_obj_array = array(); $gruppe_obj_array = array(); + // load lektor object foreach($item->lektor as $lv_lektor){ + $this->MitarbeiterModel->addLimit(1); $lektor_obj = $this->MitarbeiterModel->loadWhere(["kurzbz"=>$lv_lektor]); if (isError($lektor_obj)) { $this->outputJsonError(getError($lektor_obj)); } - $lektor_obj = getData($lektor_obj); + $lektor_obj = current(getData($lektor_obj)); $lektor_obj_array[] = $lektor_obj; } + // load gruppe object foreach ($item->gruppe as $lv_gruppe) { - $lv_gruppe = str_replace("(","",$lv_gruppe); - $lv_gruppe = str_replace(")", "", $lv_gruppe); + $lv_gruppe = strtr($lv_gruppe,['('=>'',')'=>'','"'=>'']); $lv_gruppe_array = explode(",",$lv_gruppe); - $gruppe = str_replace("\"","",$lv_gruppe_array[0]); - $verband = $lv_gruppe_array[1]; - $semester = $lv_gruppe_array[2]; - $studiengang_kz = $lv_gruppe_array[3]; + list($gruppe,$verband, $semester,$studiengang_kz) = $lv_gruppe_array; + $this->LehrverbandModel->addLimit(1); $lehrverband_obj = $this->LehrverbandModel->loadWhere(["gruppe" => $gruppe, "verband" => $verband, "semester" => $semester, "studiengang_kz" => $studiengang_kz]); if (isError($lehrverband_obj)) { $this->outputJsonError(getError($lehrverband_obj)); } - $lehrverband_obj = getData($lehrverband_obj); + $lehrverband_obj = current(getData($lehrverband_obj)); $gruppe_obj_array[] = $lehrverband_obj; } - //replace the array of lektor strings with the objects of lektor information + // studiengangs object + $this->load->model('organisation/Studiengang_model','StudiengangModel'); + $this->StudiengangModel->addLimit(1); + $studiengang_object = $this->StudiengangModel->load($item->studiengang_kz); + $studiengang_object = current(getData($studiengang_object)); + $item->studiengang = $studiengang_object; $item->lektor = $lektor_obj_array; - //replace the array of gruppen string with the lehrverband object information $item->gruppe = $gruppe_obj_array; } diff --git a/application/models/ressource/Stundenplan_model.php b/application/models/ressource/Stundenplan_model.php index 11299fe3c..9f699c6cb 100755 --- a/application/models/ressource/Stundenplan_model.php +++ b/application/models/ressource/Stundenplan_model.php @@ -142,23 +142,16 @@ class Stundenplan_model extends DB_Model */ public function stundenplanGruppierung($stundenplanViewQuery) { - - /* 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 gruppe, */ $gruppierteEvents = $this->execReadOnlyQuery(" SELECT - 'stundenplan' as type, unr,datum, stunde, CONCAT(lehrfach,'-',lehrform) as topic, - '' as beschreibung, + array_agg(DISTINCT gruppen_kurzbz) as gruppen_kurzbz, array_agg(DISTINCT (gruppe,verband,semester,studiengang_kz)) as gruppe, - array_agg(DISTINCT gruppe_bezeichnung) as gruppe_bezeichnung, - array_agg(DISTINCT lektor) as lektor, + array_agg(DISTINCT lektor) as lektor, - ort_kurzbz, studiengang_kz, titel, lehrform, lehrfach, semester, verband + ort_kurzbz, studiengang_kz, titel, lehrfach, lehrform, lehrfach_bez FROM ( @@ -172,8 +165,8 @@ class Stundenplan_model extends DB_Model 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 gruppe_bezeichnung, - ort_kurzbz, studiengang_kz, titel,'' as beschreibung,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 + END as gruppen_kurzbz, + 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 (".$stundenplanViewQuery.") sp @@ -181,7 +174,7 @@ class Stundenplan_model extends DB_Model GROUP BY - unr, datum, stunde, lehrfach, lehrform, ort_kurzbz, titel, studiengang_kz, lehrform, lehrfach, semester, verband + unr, datum, stunde, ort_kurzbz, titel, studiengang_kz, lehrform, lehrfach, lehrfach_bez ORDER BY datum, stunde "); diff --git a/public/js/apps/Cis/Stundenplan.js b/public/js/apps/Cis/Stundenplan.js index 70d3f6361..773495c27 100755 --- a/public/js/apps/Cis/Stundenplan.js +++ b/public/js/apps/Cis/Stundenplan.js @@ -54,10 +54,9 @@ const app = Vue.createApp({
- {{event.orig.title}} + {{lektor.kurzbz}} {{event.orig.ort_kurzbz}} - {{event.orig.lektor}}
` diff --git a/public/js/components/Calendar/CalendarModal.js b/public/js/components/Calendar/CalendarModal.js index 7ca6e7930..40fb3a7b3 100644 --- a/public/js/components/Calendar/CalendarModal.js +++ b/public/js/components/Calendar/CalendarModal.js @@ -55,7 +55,8 @@ export default { template: /*html*/ `