Skip to content

Commit

Permalink
Merge pull request #51 from bookboon/hotfix/author-thumb
Browse files Browse the repository at this point in the history
Add getThumbnail on Author too
  • Loading branch information
lkm committed Feb 21, 2020
2 parents b9cfca3 + a53bbf5 commit 68315d0
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
27 changes: 25 additions & 2 deletions src/Entity/Author.php
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
}
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Entity/Book.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
}

Expand Down
2 changes: 1 addition & 1 deletion src/Entity/Journey.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
}

Expand Down

0 comments on commit 68315d0

Please sign in to comment.