Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 73 additions & 0 deletions src/Attachment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php

namespace CalendArt\Adapter\Google;

use InvalidArgumentException;

use CalendArt\UriAttachment;

class Attachment implements UriAttachment
{
private $name;
private $uri;
private $icon;
private $id;
private $mimeType;
private $raw;

public function __construct($name, $uri)
{
$this->uri = $uri;
$this->name = $name;
}

public static function hydrate(array $data)
{
if (!isset($data['fileId'])) {
throw new InvalidArgumentException(sprintf('Missing at least one of the mandatory properties "fileId" ; got ["%s"]', implode('", "', array_keys($data))));
}

$attachment = new static($data['title'], $data['fileUrl']);
$attachment->id = $data['fileId'];
$attachment->icon = $data['iconLink'];
$attachment->mimeType = $data['mimeType'];
$attachment->raw = $data;

return $attachment;
}

public function getUri()
{
return $this->uri;
}

public function getName()
{
return $this->name;
}

public function getIcon()
{
return $this->icon;
}

public function getId()
{
return $this->id;
}

public function getMimeType()
{
return $this->mimeType;
}

public function getRaw()
{
return $this->raw;
}

public function getContents()
{
return file_get_contents($this->getUri());
}
}
23 changes: 15 additions & 8 deletions src/Event/BasicEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,17 @@

namespace CalendArt\Adapter\Google\Event;

use Datetime,
InvalidArgumentException;
use Datetime;
use InvalidArgumentException;

use Doctrine\Common\Collections\Collection,
Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Collections\ArrayCollection;

use CalendArt\Adapter\Google\User,
CalendArt\Adapter\Google\Calendar,
CalendArt\Adapter\Google\AbstractEvent,
CalendArt\Adapter\Google\EventParticipation;
use CalendArt\Adapter\Google\User;
use CalendArt\Adapter\Google\Calendar;
use CalendArt\Adapter\Google\Attachment;
use CalendArt\Adapter\Google\AbstractEvent;
use CalendArt\Adapter\Google\EventParticipation;

/**
* Base event class for google events
Expand Down Expand Up @@ -168,6 +169,12 @@ public static function hydrate(Calendar $calendar, array $data)
$event->stackable = true === $data['transparent'];
}

if (isset($data['attachments'])) {
$this->attachments = array_map(function ($attachment) {
return Attachment::hydrate($attachment);
}, $data['attachments']);
}

$owner = static::buildUser($data['creator'])->addEvent($event);
$event->owner = $owner;

Expand Down