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

View File

@@ -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'];