Skip to content

Commit

Permalink
Make sure a course mediaupload isnt added to default playlist
Browse files Browse the repository at this point in the history
  • Loading branch information
ssrahn committed Sep 1, 2023
1 parent 87cd322 commit 2146bcc
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions lib/Models/Videos.php
Original file line number Diff line number Diff line change
Expand Up @@ -789,15 +789,25 @@ public static function addToCoursePlaylist($eventType, $episode, $video)
// get the courses this series belongs to
$series = SeminarSeries::findBySeries_id($episode->is_part_of);
foreach ($series as $s) {
$playlist = Helpers::checkCoursePlaylist($s['seminar_id']);

$pvideo = PlaylistVideos::findOneBySQL('video_id = ? AND playlist_id = ?', [$video->id, $playlist->id]);

if (empty($pvideo)) {
$pvideo = new PlaylistVideos();
$pvideo->video_id = $video->id;
$pvideo->playlist_id = $playlist->id;
$pvideo->store();
// Only add video to default playlist if it is not connected to a different playlist in this course
$stmt = \DBManager::get()->prepare($sql = 'SELECT count(*) FROM oc_playlist_seminar
INNER JOIN oc_playlist_video ON (oc_playlist_video.playlist_id = oc_playlist_seminar.playlist_id)
WHERE oc_playlist_seminar.seminar_id = ?
AND oc_playlist_video.video_id = ?
');
$stmt->execute([$video->id, $s['seminar_id']]);
if ($stmt->fetchColumn() == 0) {
// Add video to default playlist here
$playlist = Helpers::checkCoursePlaylist($s['seminar_id']);

$pvideo = PlaylistVideos::findOneBySQL('video_id = ? AND playlist_id = ?', [$video->id, $playlist->id]);

if (empty($pvideo)) {
$pvideo = new PlaylistVideos();
$pvideo->video_id = $video->id;
$pvideo->playlist_id = $playlist->id;
$pvideo->store();
}
}
}
}
Expand Down

0 comments on commit 2146bcc

Please sign in to comment.