API Anpassungen

* Abwesenenheiten für Kalender implementiert
This commit is contained in:
Daniel Spitzer
2025-05-25 18:18:24 +02:00
parent 08e70ad73d
commit 955aa0fbd2
5 changed files with 130 additions and 65 deletions
+44 -17
View File
@@ -11,6 +11,7 @@ class CalendarApicontroller extends mfBaseApicontroller
$this->addRoute("/calendar/calendarUserSubscriptions", "updatecalendarUserSubscriptions", "POST"); $this->addRoute("/calendar/calendarUserSubscriptions", "updatecalendarUserSubscriptions", "POST");
$this->addRoute("/calendar/calendarUsers", "getcalendarUsers", "GET"); $this->addRoute("/calendar/calendarUsers", "getcalendarUsers", "GET");
$this->addRoute("/calendar/calendarAbsence", "getCalendarAbsence", "GET"); $this->addRoute("/calendar/calendarAbsence", "getCalendarAbsence", "GET");
$this->addRoute("/calendar/calendarAbsence", "updateCalendarAbsence", "POST");
} }
@@ -45,36 +46,37 @@ class CalendarApicontroller extends mfBaseApicontroller
} }
protected function getCalendarAbsence() 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 `TimerecordingCategory` ON `TimerecordingCategory`.`id`=`Timerecording`.`timerecordingCategory_id`
INNER JOIN `Calendar` ON `Calendar`.`user_id`=`Timerecording`.`user_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); $res = $db->query($sql);
if ($db->num_rows($res)) { if ($db->num_rows($res)) {
while ($data = $db->fetch_array($res)) { while ($data = $db->fetch_array($res)) {
if ($data['CategoryId'] != 11) { if ($data['CategoryId'] != 11) {
$starttime = date("Y-m-d", $data['start_time']); $data['start_time'] = $data['start_time'];
$endtime = date("Y-m-d", $data['end_time']); $all_day_event = 1;
if ($starttime != $endtime) {
$endtime = $data['end_time'] + 86400;
$endtime = date("Y-m-d", $endtime);
}
} else { } else {
$starttime = date("Y-m-d H:i", $data['start_time']); $starttime = date("Y-m-d H:i", $data['start_time']);
$endtime = date("Y-m-d H:i", $data['end_time']); $endtime = date("Y-m-d H:i", $data['end_time']);
$all_day_event = 0;
} }
$rows[] = array( $rows[] = array(
'id' => array('id' => "9999" . $data['id']), 'id' => $data['id'],
'category' => array('category' => $data['name']), 'name' => $data['name'],
'ccategory' => array('ccategory' => $data['name']), 'start_time' => $data['start_time'],
'cstart' => array('cstart' => $starttime), 'end_time' => $data['end_time'],
'cend' => array('cend' => $endtime), 'all_day_event' => $all_day_event,
'calendar_id' => array('calendar_id' => $data['calendar_id']), 'calendar_id' => $data['calendar_id'],
'microsoft_id' => array('microsoft_id' => $data['microsoft_id']), 'microsoft_id' => $data['microsoft_id'],
'description' => array('description' => "") 'microsoft_event_id' => $data['microsoft_event_id'],
); );
} }
@@ -87,6 +89,31 @@ WHERE `TimerecordingCategory`.`hourday`!='1' AND `TimerecordingCategory`.`hourda
die(); 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() protected function getcalendarUserSubscriptions()
{ {
+5 -1
View File
@@ -238,6 +238,9 @@ class CalendarModel
$attachment = 0; $attachment = 0;
$attachmentLinks = ""; $attachmentLinks = "";
} }
if (in_array("Abwesenheit", $categories)) {
continue;
}
if ($data['all_day_event'] == 1) { if ($data['all_day_event'] == 1) {
if (in_array("Feiertag", $categories)) { if (in_array("Feiertag", $categories)) {
continue; continue;
@@ -349,6 +352,7 @@ class CalendarModel
); );
} }
} }
if ($id == 0) {
$db = FronkDB::singleton(); $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` $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 `TimerecordingCategory` ON `TimerecordingCategory`.`id`=`Timerecording`.`timerecordingCategory_id`
@@ -396,7 +400,7 @@ WHERE `TimerecordingCategory`.`hourday`!='1' AND `TimerecordingCategory`.`hourda
'calendar_name' => array('calendar_name' => $CalendarUsers[$data['calendar_id']]), 'calendar_name' => array('calendar_name' => $CalendarUsers[$data['calendar_id']]),
); );
} }
}
} }
$json['success'] = true; $json['success'] = true;
$json['data'] = $rows; $json['data'] = $rows;
@@ -20,6 +20,7 @@ class TimerecordingModel
private $comment; private $comment;
private $approved; private $approved;
private $completed; private $completed;
private $microsoft_even_id;
public static function find($data) public static function find($data)
@@ -0,0 +1,31 @@
<?php
declare(strict_types=1);
use Phinx\Migration\AbstractMigration;
final class TimerecordingAddMicrosoftEventId extends AbstractMigration
{
public function up(): void
{
if($this->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") {
}
}
}
+5 -3
View File
@@ -1164,8 +1164,8 @@ if (typeof (EventSource) !== 'undefined') {
calendar.render(); calendar.render();
} }
} else if (event.change_type == '1' || !cevent) { } else if ((event.change_type == '1' || !cevent) && event.change_type != '3') {
if (event.calendar_id == event.calendar_id) { if (event.calendar_id == event.calendar_id && event.name) {
let info = calendar.addEvent({ let info = calendar.addEvent({
id: event.cal_events_id, id: event.cal_events_id,
title: event.name, title: event.name,
@@ -1192,7 +1192,7 @@ if (typeof (EventSource) !== 'undefined') {
busy: event.busy busy: event.busy
}); });
} else { } else if (event.name) {
let info = calendar.addEvent({ let info = calendar.addEvent({
id: event.cal_events_id, id: event.cal_events_id,
title: event.name, title: event.name,
@@ -1222,8 +1222,10 @@ if (typeof (EventSource) !== 'undefined') {
calendar.render(); calendar.render();
} else if (event.change_type == '3') { } else if (event.change_type == '3') {
let cevent = calendar.getEventById(event.cal_events_id); let cevent = calendar.getEventById(event.cal_events_id);
if (cevent) {
cevent.remove(); cevent.remove();
} }
}
}); });
}, false); }, false);