diff --git a/src/Entity/Author.php b/src/Entity/Author.php index b28d0bd..603d0bf 100644 --- a/src/Entity/Author.php +++ b/src/Entity/Author.php @@ -79,10 +79,33 @@ protected function isValid(array $array) : bool /** * @return string - * + * @deprecated use getThumbnail */ public function getProfileImage() { - return $this->safeGet('profileImage', ''); + return $this->getThumbnail(380); + } + + /** + * 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]; + } + } } /** diff --git a/src/Entity/Book.php b/src/Entity/Book.php index 69ecba4..3de7ff4 100644 --- a/src/Entity/Book.php +++ b/src/Entity/Book.php @@ -294,7 +294,7 @@ public function getIsbn() public function getThumbnail(int $size = 210) { $thumbs = []; - foreach ($this->safeGet('thumbnail') as $thumb) { + foreach ($this->safeGet('thumbnail', []) as $thumb) { $thumbs[$thumb['width']] = $thumb['_link']; } diff --git a/src/Entity/Journey.php b/src/Entity/Journey.php index 0d5400e..3d75f63 100644 --- a/src/Entity/Journey.php +++ b/src/Entity/Journey.php @@ -110,7 +110,7 @@ public function getPublished() : string public function getThumbnail(int $size = 210) { $thumbs = []; - foreach ($this->safeGet('thumbnail') as $thumb) { + foreach ($this->safeGet('thumbnail', []) as $thumb) { $thumbs[$thumb['width']] = $thumb['_link']; }