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) => {