From 42336c92483dd7e0c28b3047f8d9a1e3ae1c1480 Mon Sep 17 00:00:00 2001 From: Nikolay Dmitriyev Date: Fri, 16 Jun 2017 02:19:26 +0400 Subject: [PATCH 1/2] Multiple artists in MusicRecording --- src/ContextTypes/MusicAbstractContext.php | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/ContextTypes/MusicAbstractContext.php b/src/ContextTypes/MusicAbstractContext.php index f5bd4ea..0096061 100644 --- a/src/ContextTypes/MusicAbstractContext.php +++ b/src/ContextTypes/MusicAbstractContext.php @@ -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); } /** From 52d6004012ba82a250c0cb8152d156a29c759941 Mon Sep 17 00:00:00 2001 From: Nikolay Dmitriyev Date: Fri, 16 Jun 2017 02:20:07 +0400 Subject: [PATCH 2/2] Multiple albums in MusicRecording --- src/ContextTypes/MusicRecording.php | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/ContextTypes/MusicRecording.php b/src/ContextTypes/MusicRecording.php index a093b6d..70a369e 100644 --- a/src/ContextTypes/MusicRecording.php +++ b/src/ContextTypes/MusicRecording.php @@ -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); } /**