Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 43 additions & 1 deletion lib/Brightcove/API/CMS.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,49 @@ public function listPlaylists($sort = NULL, $limit = NULL, $offset = NULL) {
if (strlen($query) > 0) {
$query = '?' . substr($query, 1);
}
return $this->cmsRequest('GET', "/playlists{$query}", Playlist::class, TRUE);

$playlists = $this->cmsRequest('GET', "/playlists{$query}", Playlist::class, TRUE);

// Check if there are smart playlists as we need to build their videos
// separately.
$smart_playlists = [];
foreach ($playlists as $key => $playlist) {
/* @var \Brightcove\Object\Playlist $playlist */
if ($playlist->getType() !== 'EXPLICIT') {
$smart_playlists[$key] = $playlist->getId();
}
}

if (!empty($smart_playlists)) {
foreach ($smart_playlists as $playlist_key => $smart_playlist_id) {
$video_ids = $this->getSmartPlaylistVideos("/playlists/{$smart_playlist_id}/videos");

if (!empty($video_ids)) {
/* @var \Brightcove\Object\Playlist $playlist */
$playlist = $playlists[$playlist_key];
$playlist->setVideoIds($video_ids);
}
}
}
return $playlists;
}

/**
* Get smart playlist videos to add to the Playlist objects.
*
* @param string $endpoint
* Endpoint to get smart playlist videos.
*
* @return array
* Video ids.
*/
protected function getSmartPlaylistVideos($endpoint) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a concern that the playlist being returned doesn't appear to be honoring the optional $limit parameter. I think it needs to be incorporated here somehow.

$video_results = $this->cmsRequest('GET', $endpoint, NULL);
$video_ids = [];
foreach ($video_results as $video) {
$video_ids[] = $video['id'];
}
return $video_ids;
}

/**
Expand Down