From e1a3ced78be6b1d29161cbf9bf263f3fcf02c70b Mon Sep 17 00:00:00 2001 From: Lasse Mammen Date: Fri, 21 Feb 2020 16:50:12 +0000 Subject: [PATCH] Add getting for journey image --- src/Entity/Book.php | 3 +-- src/Entity/Journey.php | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/Entity/Book.php b/src/Entity/Book.php index 0c30ff6..69ecba4 100644 --- a/src/Entity/Book.php +++ b/src/Entity/Book.php @@ -288,11 +288,10 @@ public function getIsbn() * Returns closes thumbnail size to input, default 210px. * * @param int $size appromimate size - * @param bool $ssl Whether or not to return https:// url for thumbnail * * @return string url for thumbnail */ - public function getThumbnail(int $size = 210, bool $ssl = false) + public function getThumbnail(int $size = 210) { $thumbs = []; foreach ($this->safeGet('thumbnail') as $thumb) { diff --git a/src/Entity/Journey.php b/src/Entity/Journey.php index 924dce6..0d5400e 100644 --- a/src/Entity/Journey.php +++ b/src/Entity/Journey.php @@ -100,6 +100,29 @@ public function getPublished() : string return $this->safeGet('published'); } + /** + * Returns closes thumbnail size to input, default 210px. + * + * @param int $size appromimate size + * + * @return string url for thumbnail + */ + public function getThumbnail(int $size = 210) + { + $thumbs = []; + foreach ($this->safeGet('thumbnail') as $thumb) { + $thumbs[$thumb['width']] = $thumb['_link']; + } + + $sizes = array_keys($thumbs); + while (true) { + $thumbSize = array_shift($sizes); + if ((int) $size <= (int) $thumbSize || count($sizes) === 0) { + return $thumbs[$thumbSize]; + } + } + } + /** * @return bool is featured */