feat: Enhance task management with start and end time handling
- Added functionality to calculate task duration based on provided start and end times. - Implemented logic to derive end time from start time and duration if only start time is provided. - Updated task creation and update APIs to handle new time fields. - Introduced a modal for editing tasks with flexible time and duration inputs. - Improved UI for task creation and editing, including better handling of time inputs and duration selection. - Added two-way synchronization with Outlook for task updates.
This commit is contained in:
@@ -562,6 +562,75 @@ function microsoft_delete_event(int $userId, string $eventId): bool {
|
||||
return in_array($response['status'], [200, 204, 404]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Werkt een bestaande afspraak bij in Microsoft Outlook via Graph API (PATCH)
|
||||
*/
|
||||
function microsoft_update_event(int $userId, string $eventId, array $eventData): bool {
|
||||
if (empty($eventId)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$token = microsoft_get_valid_token($userId);
|
||||
if (!$token) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$payload = [];
|
||||
if (!empty($eventData['subject'])) {
|
||||
$payload['subject'] = $eventData['subject'];
|
||||
}
|
||||
|
||||
$date = !empty($eventData['date']) ? $eventData['date'] : date('Y-m-d');
|
||||
$startTime = !empty($eventData['start_time']) ? $eventData['start_time'] : '09:00';
|
||||
$endTime = !empty($eventData['end_time']) ? $eventData['end_time'] : '09:30';
|
||||
|
||||
if (preg_match('/^(\d{1,2})[:.](\d{2})$/', $startTime, $m)) {
|
||||
$startTime = sprintf('%02d:%02d', (int)$m[1], (int)$m[2]);
|
||||
}
|
||||
if (preg_match('/^(\d{1,2})[:.](\d{2})$/', $endTime, $m)) {
|
||||
$endTime = sprintf('%02d:%02d', (int)$m[1], (int)$m[2]);
|
||||
}
|
||||
|
||||
$payload['start'] = [
|
||||
'dateTime' => "{$date}T{$startTime}:00",
|
||||
'timeZone' => 'Europe/Amsterdam',
|
||||
];
|
||||
$payload['end'] = [
|
||||
'dateTime' => "{$date}T{$endTime}:00",
|
||||
'timeZone' => 'Europe/Amsterdam',
|
||||
];
|
||||
|
||||
$url = MS_GRAPH_BASE_URL . '/me/events/' . urlencode($eventId);
|
||||
$response = fociz_http_request($url, [
|
||||
'method' => 'PATCH',
|
||||
'headers' => [
|
||||
'Authorization' => "Bearer {$token}",
|
||||
'Content-Type' => 'application/json',
|
||||
'Accept' => 'application/json',
|
||||
],
|
||||
'body' => $payload,
|
||||
'timeout' => 12,
|
||||
]);
|
||||
|
||||
if ($response['status'] === 401) {
|
||||
$freshToken = microsoft_get_valid_token($userId, true);
|
||||
if ($freshToken && $freshToken !== $token) {
|
||||
$response = fociz_http_request($url, [
|
||||
'method' => 'PATCH',
|
||||
'headers' => [
|
||||
'Authorization' => "Bearer {$freshToken}",
|
||||
'Content-Type' => 'application/json',
|
||||
'Accept' => 'application/json',
|
||||
],
|
||||
'body' => $payload,
|
||||
'timeout' => 12,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
return in_array($response['status'], [200, 204]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ontkoppelt Microsoft integratie voor een gebruiker
|
||||
* Wist uitsluitend de persoonlijke tokens; behoudt de centrale Azure App gegevens indien aanwezig.
|
||||
|
||||
Reference in New Issue
Block a user