diff --git a/src/Attachment.php b/src/Attachment.php new file mode 100644 index 0000000..6f03ef6 --- /dev/null +++ b/src/Attachment.php @@ -0,0 +1,73 @@ +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()); + } +} diff --git a/src/Event/BasicEvent.php b/src/Event/BasicEvent.php index c2254a1..13d5d4a 100644 --- a/src/Event/BasicEvent.php +++ b/src/Event/BasicEvent.php @@ -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 @@ -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;