Skip to content

Commit

Permalink
Merge pull request #23 from nokimaro/master
Browse files Browse the repository at this point in the history
Multiple albums and artists for MusicRecording
  • Loading branch information
Torann authored Aug 18, 2017
2 parents cb3ae42 + 52d6004 commit dbf7249
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 10 deletions.
19 changes: 14 additions & 5 deletions src/ContextTypes/MusicAbstractContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,26 @@ protected function setGenreAttribute($items)
/**
* Set artist attribute
*
* @param array|string $item
* @param array|string $items
* @return array
*/
protected function setByArtistAttribute($item)
protected function setByArtistAttribute($items)
{
if ( ! is_array($item))
if ( ! is_array($items))
{
return $item;
return $items;
}

return $this->getNestedContext(MusicGroup::class, $item);
//Check if not multidimensional array (for backward compatibility)
if((count($items) == count($items, COUNT_RECURSIVE)))
{
return $this->getNestedContext(MusicGroup::class, $items);
}

//multiple artists
return array_map(function ($item) {
return $this->getNestedContext(MusicGroup::class, $item);
}, $items);
}

/**
Expand Down
19 changes: 14 additions & 5 deletions src/ContextTypes/MusicRecording.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,26 @@ class MusicRecording extends MusicAbstractContext
/**
* Set in album attribute
*
* @param array|string $item
* @param array|string $items
* @return array
*/
protected function setInAlbumAttribute($item)
protected function setInAlbumAttribute($items)
{
if ( ! is_array($item))
if ( ! is_array($items))
{
return $item;
return $items;
}

//Check if not multidimensional array (for backward compatibility)
if((count($items) == count($items, COUNT_RECURSIVE)))
{
return $this->getNestedContext(MusicAlbum::class, $items);
}

return $this->getNestedContext(MusicAlbum::class, $item);
//multiple albums
return array_map(function ($item) {
return $this->getNestedContext(MusicAlbum::class, $item);
}, $items);
}

/**
Expand Down

0 comments on commit dbf7249

Please sign in to comment.