Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/set videos for smart playlists #38

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
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