Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
freekmurze committed May 10, 2016
1 parent 0a8019e commit 1b85db0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/Event.php
Expand Up @@ -65,21 +65,21 @@ public static function createFromGoogleCalendarEvent(Google_Service_Calendar_Eve

public function convertToGoogleEvent() : Google_Service_Calendar_Event
{
$googleEvent = new Google_Service_Calendar_Event();
$googleEvent = $this->googleEvent ?? new Google_Service_Calendar_Event();

$googleEvent->summary = $this->name;

$start = new Google_Service_Calendar_EventDateTime();
$end = new Google_Service_Calendar_EventDateTime();

if ($this->allDayEvent) {
$start->setDateTime($this->startDateTime->format(DateTime::RFC3339));
$end->setDateTime($this->startDateTime->format(DateTime::RFC3339));
}
else {
$start->setDate($this->startDateTime->format('Y-m-d'));
$end->setDate($this->endDateTime->format('Y-m-d'));
}
else {
$start->setDateTime($this->startDateTime->format(DateTime::RFC3339));
$end->setDateTime($this->endDateTime->format(DateTime::RFC3339));
}

$googleEvent->setStart($start);
$googleEvent->setEnd($end);
Expand All @@ -103,7 +103,9 @@ public static function find($id, $calendarId = null)

public function save()
{
$method = $this->googleEvent ? 'updateEvent' : 'insertEvent';

return $this->getGoogleCalendar()->$method($this);
}

public function delete($id = null)
Expand Down
14 changes: 14 additions & 0 deletions src/GoogleCalendar.php
Expand Up @@ -107,6 +107,20 @@ public function insertEvent($event)
return $this->calendarService->events->insert($this->calendarId, $event);
}

/**
* @param \Spatie\GoogleCalendar\Event|Google_Service_Calendar_Event $event
*
* @return \Google_Service_Calendar_Event
*/
public function updateEvent($event)
{
if ($event instanceof Event) {
$event = $event->convertToGoogleEvent();
}

return $this->calendarService->events->update($this->calendarId, $event->id, $event);
}

/**
* @param string|\Spatie\GoogleCalendar\Event $eventId
*/
Expand Down

0 comments on commit 1b85db0

Please sign in to comment.