diff --git a/application/controllers/Pages.php b/application/controllers/Pages.php index a7a02ce..7bc9f21 100755 --- a/application/controllers/Pages.php +++ b/application/controllers/Pages.php @@ -451,11 +451,11 @@ class Pages extends CI_Controller { $workerEventId = null; $ownerEventId = null; if(!empty($worker->google_calendar_id)){ - $workerEventId = $this->googlecalendar->createEvent($worker->google_calendar_id, $gcalTitle, $gcalDescription, $gcalStart, $gcalEnd); + $workerEventId = $this->googlecalendar->createEvent($worker->google_calendar_id, $gcalTitle, $gcalDescription, $gcalStart, $gcalEnd, $worker->google_calendar_id); } $evelinCalId = $this->config->item('gcal_evelin_calendar_id'); if(!empty($evelinCalId)){ - $ownerEventId = $this->googlecalendar->createEvent($evelinCalId, $gcalTitle, $gcalDescription, $gcalStart, $gcalEnd); + $ownerEventId = $this->googlecalendar->createEvent($evelinCalId, $gcalTitle, $gcalDescription, $gcalStart, $gcalEnd, $evelinCalId); } $this->Service_model->updateBookingCalEvents($newBooking->booking_id, $workerEventId, $ownerEventId); } @@ -873,10 +873,10 @@ class Pages extends CI_Controller { $newWorkerEventId = null; $newOwnerEventId = null; if(!empty($worker->google_calendar_id)){ - $newWorkerEventId = $this->googlecalendar->createEvent($worker->google_calendar_id, $gcalTitle, $gcalDescription, $gcalStart, $gcalEnd); + $newWorkerEventId = $this->googlecalendar->createEvent($worker->google_calendar_id, $gcalTitle, $gcalDescription, $gcalStart, $gcalEnd, $worker->google_calendar_id); } if(!empty($evelinCalId)){ - $newOwnerEventId = $this->googlecalendar->createEvent($evelinCalId, $gcalTitle, $gcalDescription, $gcalStart, $gcalEnd); + $newOwnerEventId = $this->googlecalendar->createEvent($evelinCalId, $gcalTitle, $gcalDescription, $gcalStart, $gcalEnd, $evelinCalId); } $this->Service_model->updateBookingCalEvents($booking->booking_id, $newWorkerEventId, $newOwnerEventId); diff --git a/application/libraries/GoogleCalendar.php b/application/libraries/GoogleCalendar.php index 2b70d9c..8690036 100644 --- a/application/libraries/GoogleCalendar.php +++ b/application/libraries/GoogleCalendar.php @@ -27,19 +27,30 @@ class GoogleCalendar { } /** - * Create a calendar event. + * Create a calendar event and notify the attendee. + * @param string $calendarId Calendar to insert into + * @param string $title + * @param string $description + * @param string $startDatetime ISO 8601 (e.g. 2026-03-10T10:00:00) + * @param string $endDatetime + * @param string|null $attendeeEmail If set, added as attendee — triggers push notification + invite email * @return string|null The new event ID, or null on failure. */ - public function createEvent($calendarId, $title, $description, $startDatetime, $endDatetime) { + public function createEvent($calendarId, $title, $description, $startDatetime, $endDatetime, $attendeeEmail = null) { if (!$this->service || empty($calendarId)) return null; try { - $event = new Google_Service_Calendar_Event([ + $eventData = [ 'summary' => $title, 'description' => $description, 'start' => ['dateTime' => $startDatetime, 'timeZone' => 'Europe/Oslo'], 'end' => ['dateTime' => $endDatetime, 'timeZone' => 'Europe/Oslo'], - ]); - $result = $this->service->events->insert($calendarId, $event); + ]; + if (!empty($attendeeEmail)) { + $eventData['attendees'] = [['email' => $attendeeEmail]]; + } + $event = new Google_Service_Calendar_Event($eventData); + $params = !empty($attendeeEmail) ? ['sendUpdates' => 'all'] : []; + $result = $this->service->events->insert($calendarId, $event, $params); return $result->getId(); } catch (Exception $e) { return null; @@ -47,10 +58,11 @@ class GoogleCalendar { } /** - * Update an existing calendar event. + * Update an existing calendar event and notify the attendee. + * @param string|null $attendeeEmail If set, added as attendee — triggers update notification * @return string|null The event ID, or null on failure. */ - public function updateEvent($calendarId, $eventId, $title, $description, $startDatetime, $endDatetime) { + public function updateEvent($calendarId, $eventId, $title, $description, $startDatetime, $endDatetime, $attendeeEmail = null) { if (!$this->service || empty($calendarId) || empty($eventId)) return null; try { $event = $this->service->events->get($calendarId, $eventId); @@ -64,7 +76,11 @@ class GoogleCalendar { 'dateTime' => $endDatetime, 'timeZone' => 'Europe/Oslo', ])); - $result = $this->service->events->update($calendarId, $eventId, $event); + if (!empty($attendeeEmail)) { + $event->setAttendees([new Google_Service_Calendar_EventAttendee(['email' => $attendeeEmail])]); + } + $params = !empty($attendeeEmail) ? ['sendUpdates' => 'all'] : []; + $result = $this->service->events->update($calendarId, $eventId, $event, $params); return $result->getId(); } catch (Exception $e) { return null;