Skip to content

Commit

Permalink
Add getThumbnail on Author too
Browse files Browse the repository at this point in the history
  • Loading branch information
lkm committed Feb 21, 2020
1 parent b9cfca3 commit a53bbf5
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 a53bbf5

Please sign in to comment.