From 955aa0fbd2b3e86d2bcacfafa3161d1bb1a6edd4 Mon Sep 17 00:00:00 2001 From: Daniel Spitzer Date: Sun, 25 May 2025 18:18:24 +0200 Subject: [PATCH] =?UTF-8?q?API=20Anpassungen=20*=20Abwesenenheiten=20f?= =?UTF-8?q?=C3=BCr=20Kalender=20implementiert?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/Api/v1/CalendarApicontroller.php | 67 ++++++++++----- application/Calendar/CalendarModel.php | 86 ++++++++++--------- .../Timerecording/TimerecordingModel.php | 1 + ...6_timerecording_add_microsoft_event_id.php | 31 +++++++ public/js/pages/Calendar/View.js | 10 ++- 5 files changed, 130 insertions(+), 65 deletions(-) create mode 100644 db/migrations/20250525092446_timerecording_add_microsoft_event_id.php diff --git a/application/Api/v1/CalendarApicontroller.php b/application/Api/v1/CalendarApicontroller.php index 416444ee1..6c19e10c4 100644 --- a/application/Api/v1/CalendarApicontroller.php +++ b/application/Api/v1/CalendarApicontroller.php @@ -11,6 +11,7 @@ class CalendarApicontroller extends mfBaseApicontroller $this->addRoute("/calendar/calendarUserSubscriptions", "updatecalendarUserSubscriptions", "POST"); $this->addRoute("/calendar/calendarUsers", "getcalendarUsers", "GET"); $this->addRoute("/calendar/calendarAbsence", "getCalendarAbsence", "GET"); + $this->addRoute("/calendar/calendarAbsence", "updateCalendarAbsence", "POST"); } @@ -45,36 +46,37 @@ class CalendarApicontroller extends mfBaseApicontroller } protected function getCalendarAbsence() - { $db = FronkDB::singleton(); - $sql = "SELECT `Timerecording`.`id`, `Timerecording`.`start` start_time, `Timerecording`.`end` end_time,`Calendar`.`microsoft_id`,`Calendar`.`go_calendar_id` calendar_id,`TimerecordingCategory`.`name`,`TimerecordingCategory`.`id` CategoryId,`Timerecording`.`create` ctime,`Timerecording`.`edit` mtime FROM `Timerecording` + { + $starttime = time() - 86400 * 30; + $db = FronkDB::singleton(); + $sql = "SELECT `Timerecording`.`id`, `Timerecording`.`start` start_time, `Timerecording`.`end` end_time,`Calendar`.`microsoft_id`,`Timerecording`.`microsoft_event_id`,`Calendar`.`go_calendar_id` calendar_id,`TimerecordingCategory`.`name`,`TimerecordingCategory`.`id` CategoryId,`Timerecording`.`create` ctime,`Timerecording`.`edit` mtime FROM `Timerecording` INNER JOIN `TimerecordingCategory` ON `TimerecordingCategory`.`id`=`Timerecording`.`timerecordingCategory_id` INNER JOIN `Calendar` ON `Calendar`.`user_id`=`Timerecording`.`user_id` -WHERE `TimerecordingCategory`.`hourday`!='1' AND `TimerecordingCategory`.`hourday`!='7' AND `TimerecordingCategory`.`hourday`!='5'"; +WHERE `TimerecordingCategory`.`hourday`!='1' AND `TimerecordingCategory`.`hourday`!='7' AND `TimerecordingCategory`.`hourday`!='5' AND `Timerecording`.start >= $starttime +AND `Timerecording`.`user_id` = '89' +"; $res = $db->query($sql); if ($db->num_rows($res)) { while ($data = $db->fetch_array($res)) { if ($data['CategoryId'] != 11) { - $starttime = date("Y-m-d", $data['start_time']); - $endtime = date("Y-m-d", $data['end_time']); - if ($starttime != $endtime) { - $endtime = $data['end_time'] + 86400; - $endtime = date("Y-m-d", $endtime); - } + $data['start_time'] = $data['start_time']; + $all_day_event = 1; } else { $starttime = date("Y-m-d H:i", $data['start_time']); $endtime = date("Y-m-d H:i", $data['end_time']); + $all_day_event = 0; } $rows[] = array( - 'id' => array('id' => "9999" . $data['id']), - 'category' => array('category' => $data['name']), - 'ccategory' => array('ccategory' => $data['name']), - 'cstart' => array('cstart' => $starttime), - 'cend' => array('cend' => $endtime), - 'calendar_id' => array('calendar_id' => $data['calendar_id']), - 'microsoft_id' => array('microsoft_id' => $data['microsoft_id']), - 'description' => array('description' => "") + 'id' => $data['id'], + 'name' => $data['name'], + 'start_time' => $data['start_time'], + 'end_time' => $data['end_time'], + 'all_day_event' => $all_day_event, + 'calendar_id' => $data['calendar_id'], + 'microsoft_id' => $data['microsoft_id'], + 'microsoft_event_id' => $data['microsoft_event_id'], ); } @@ -82,11 +84,36 @@ WHERE `TimerecordingCategory`.`hourday`!='1' AND `TimerecordingCategory`.`hourda $json['success'] = true; $json['data'] = $rows; $json['status'] = "success"; - $result = json_encode($json,JSON_UNESCAPED_UNICODE ); + $result = json_encode($json, JSON_UNESCAPED_UNICODE); echo $result; die(); } + protected function updateCalendarAbsence() + { + $id = $this->post['id']; + + $microsoft_event_id = $this->post['microsoft_event_id']; + + $timercording = new Timerecording($id); + + if (!($timercording->id) || $timercording->id != $id) { + die(); + } + $data = []; + if ($microsoft_event_id) { + $data['microsoft_event_id'] = $microsoft_event_id; + } else { + $data['microsoft_event_id'] = null; + } + + $timercording->update($data); + $timercording->save(); + $json['status'] = "success"; + $result = json_encode($json); + echo $result; + die(); + } protected function getcalendarUserSubscriptions() { @@ -218,7 +245,7 @@ WHERE `TimerecordingCategory`.`hourday`!='1' AND `TimerecordingCategory`.`hourda $message[0]['start_time'] = date('Y-m-d H:i', $json['start_time']); $message[0]['end_time'] = date('Y-m-d H:i', $json['end_time']); } - $message[0]['name']= $Calendarevent['data'][0]['category']['category']; + $message[0]['name'] = $Calendarevent['data'][0]['category']['category']; $message[0]['description'] = $Calendarevent['data'][0]['description']['description']; $message[0]['location'] = $Calendarevent['data'][0]['location']['location']; $message[0]['event_type'] = $Calendarevent['data'][0]['event_type']['event_type']; @@ -234,7 +261,7 @@ WHERE `TimerecordingCategory`.`hourday`!='1' AND `TimerecordingCategory`.`hourda $message[0]['ctime'] = $Calendarevent['data'][0]['ctime']['ctime']; $message[0]['cname'] = $Calendarevent['data'][0]['cname']['cname']; $message[0]['busy'] = $Calendarevent['data'][0]['busy']['busy']; - $message[0]['canceld']= $Calendarevent['data'][0]['canceld']['canceld']; + $message[0]['canceld'] = $Calendarevent['data'][0]['canceld']['canceld']; $message[0]['calendar_id_check'] = array('calendar_id' => $json['calendar_id'], 'order' => $json['calendar_id']);; $message[0]['userr'] = $Calendar[0]->calendar_id; $message[0]['bgColor'] = $calendarColors[$json['calendar_id']]['bgcolor']; diff --git a/application/Calendar/CalendarModel.php b/application/Calendar/CalendarModel.php index 69d998b58..03e26d17b 100644 --- a/application/Calendar/CalendarModel.php +++ b/application/Calendar/CalendarModel.php @@ -238,6 +238,9 @@ class CalendarModel $attachment = 0; $attachmentLinks = ""; } + if (in_array("Abwesenheit", $categories)) { + continue; + } if ($data['all_day_event'] == 1) { if (in_array("Feiertag", $categories)) { continue; @@ -344,59 +347,60 @@ class CalendarModel 'mname' => array('mname' => $data['mname']), 'isorganizer' => array('isorganizer' => $data['is_organizer']), 'busy' => array('busy' => $data['busy']), - 'canceld'=> array('canceld' => $data['canceld']), + 'canceld' => array('canceld' => $data['canceld']), 'timerecording' => array('timerecording' => 0), ); } } - $db = FronkDB::singleton(); - $sql = "SELECT `Timerecording`.`id`, `Timerecording`.`start` start_time, `Timerecording`.`end` end_time,`Calendar`.`go_calendar_id` calendar_id,`TimerecordingCategory`.`name`,`TimerecordingCategory`.`id` CategoryId,`Timerecording`.`create` ctime,`Timerecording`.`edit` mtime FROM `Timerecording` + if ($id == 0) { + $db = FronkDB::singleton(); + $sql = "SELECT `Timerecording`.`id`, `Timerecording`.`start` start_time, `Timerecording`.`end` end_time,`Calendar`.`go_calendar_id` calendar_id,`TimerecordingCategory`.`name`,`TimerecordingCategory`.`id` CategoryId,`Timerecording`.`create` ctime,`Timerecording`.`edit` mtime FROM `Timerecording` INNER JOIN `TimerecordingCategory` ON `TimerecordingCategory`.`id`=`Timerecording`.`timerecordingCategory_id` INNER JOIN `Calendar` ON `Calendar`.`user_id`=`Timerecording`.`user_id` WHERE `TimerecordingCategory`.`hourday`!='1' AND `TimerecordingCategory`.`hourday`!='7' AND `TimerecordingCategory`.`hourday`!='5' $whereTimeRecording"; - $res = $db->query($sql); - if ($db->num_rows($res)) { - while ($data = $db->fetch_array($res)) { + $res = $db->query($sql); + if ($db->num_rows($res)) { + while ($data = $db->fetch_array($res)) { - if ($calendarColors[$data['calendar_id']]['bgcolor']) { - $bgcolor = $calendarColors[$data['calendar_id']]['bgcolor']; - $txtcolor = $calendarColors[$data['calendar_id']]['txtcolor']; - } else { - $bgcolor = $standardCalendarColors[$colorCounter]; - $txtcolor = "#000"; - $colorCounter++; - } - if ($data['CategoryId'] != 11) { - $starttime = date("Y-m-d", $data['start_time']); - $endtime = date("Y-m-d", $data['end_time']); - if ($starttime != $endtime) { - $endtime = $data['end_time'] + 86400; - $endtime = date("Y-m-d", $endtime); + if ($calendarColors[$data['calendar_id']]['bgcolor']) { + $bgcolor = $calendarColors[$data['calendar_id']]['bgcolor']; + $txtcolor = $calendarColors[$data['calendar_id']]['txtcolor']; + } else { + $bgcolor = $standardCalendarColors[$colorCounter]; + $txtcolor = "#000"; + $colorCounter++; } + if ($data['CategoryId'] != 11) { + $starttime = date("Y-m-d", $data['start_time']); + $endtime = date("Y-m-d", $data['end_time']); + if ($starttime != $endtime) { + $endtime = $data['end_time'] + 86400; + $endtime = date("Y-m-d", $endtime); + } - } else { - $starttime = date("Y-m-d H:i", $data['start_time']); - $endtime = date("Y-m-d H:i", $data['end_time']); + } else { + $starttime = date("Y-m-d H:i", $data['start_time']); + $endtime = date("Y-m-d H:i", $data['end_time']); + } + $rows[] = array( + 'id' => array('id' => "9999" . $data['id']), + 'category' => array('category' => $data['name']), + 'ccategory' => array('ccategory' => $data['name']), + 'cstart' => array('cstart' => $starttime), + 'cend' => array('cend' => $endtime), + 'calendar_id' => array('calendar_id' => $data['calendar_id']), + 'ctime' => array('ctime' => date("d.m.Y H:i", $data['ctime'])), + 'cname' => array('cname' => $CalendarUsers[$data['calendar_id']]), + 'mtime' => array('mtime' => date("d.m.Y H:i", $data['mtime'])), + 'mname' => array('mname' => $CalendarUsers[$data['calendar_id']]), + 'description' => array('description' => ""), + 'bgColor' => array('bgColor' => $bgcolor), + 'txtColor' => array('txtColor' => $txtcolor), + 'timerecording' => array('timerecording' => 1), + 'calendar_name' => array('calendar_name' => $CalendarUsers[$data['calendar_id']]), + ); } - $rows[] = array( - 'id' => array('id' => "9999" . $data['id']), - 'category' => array('category' => $data['name']), - 'ccategory' => array('ccategory' => $data['name']), - 'cstart' => array('cstart' => $starttime), - 'cend' => array('cend' => $endtime), - 'calendar_id' => array('calendar_id' => $data['calendar_id']), - 'ctime' => array('ctime' => date("d.m.Y H:i", $data['ctime'])), - 'cname' => array('cname' => $CalendarUsers[$data['calendar_id']]), - 'mtime' => array('mtime' => date("d.m.Y H:i", $data['mtime'])), - 'mname' => array('mname' => $CalendarUsers[$data['calendar_id']]), - 'description' => array('description' => ""), - 'bgColor' => array('bgColor' => $bgcolor), - 'txtColor' => array('txtColor' => $txtcolor), - 'timerecording' => array('timerecording' => 1), - 'calendar_name' => array('calendar_name' => $CalendarUsers[$data['calendar_id']]), - ); } - } $json['success'] = true; $json['data'] = $rows; diff --git a/application/Timerecording/TimerecordingModel.php b/application/Timerecording/TimerecordingModel.php index b942f640e..1577a8005 100644 --- a/application/Timerecording/TimerecordingModel.php +++ b/application/Timerecording/TimerecordingModel.php @@ -20,6 +20,7 @@ class TimerecordingModel private $comment; private $approved; private $completed; + private $microsoft_even_id; public static function find($data) diff --git a/db/migrations/20250525092446_timerecording_add_microsoft_event_id.php b/db/migrations/20250525092446_timerecording_add_microsoft_event_id.php new file mode 100644 index 000000000..11d756a52 --- /dev/null +++ b/db/migrations/20250525092446_timerecording_add_microsoft_event_id.php @@ -0,0 +1,31 @@ +getEnvironment() == "thetool") { + $table = $this->table("Timerecording", ["signed" => true]); + $table->addColumn("microsoft_event_id", "string", ["null" => true, "after" => "completed"]); + $table->update(); + } + + if($this->getEnvironment() == "addressdb") { + + } + } + + public function down(): void + { + if($this->getEnvironment() == "thetool") { + $this->table("Timerecording")->removeColumn("microsoft_event_id")->save(); + } + + if($this->getEnvironment() == "addressdb") { + + } + } +} diff --git a/public/js/pages/Calendar/View.js b/public/js/pages/Calendar/View.js index 4bd7bdcec..40163d16b 100644 --- a/public/js/pages/Calendar/View.js +++ b/public/js/pages/Calendar/View.js @@ -1164,8 +1164,8 @@ if (typeof (EventSource) !== 'undefined') { calendar.render(); } - } else if (event.change_type == '1' || !cevent) { - if (event.calendar_id == event.calendar_id) { + } else if ((event.change_type == '1' || !cevent) && event.change_type != '3') { + if (event.calendar_id == event.calendar_id && event.name) { let info = calendar.addEvent({ id: event.cal_events_id, title: event.name, @@ -1192,7 +1192,7 @@ if (typeof (EventSource) !== 'undefined') { busy: event.busy }); - } else { + } else if (event.name) { let info = calendar.addEvent({ id: event.cal_events_id, title: event.name, @@ -1222,7 +1222,9 @@ if (typeof (EventSource) !== 'undefined') { calendar.render(); } else if (event.change_type == '3') { let cevent = calendar.getEventById(event.cal_events_id); - cevent.remove(); + if (cevent) { + cevent.remove(); + } } });