Skip to content

Commit

Permalink
Fix missing default playlist when transferring course contents, fix #879
Browse files Browse the repository at this point in the history
 (#931)

Co-authored-by: Dennis Benz <dennis.benz@uos.de>
  • Loading branch information
dennis531 and Dennis Benz committed Feb 7, 2024
1 parent eb5ef6e commit c41df15
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 11 deletions.
2 changes: 1 addition & 1 deletion lib/Models/Helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ static public function checkCoursePlaylist($course_id)
*/
public static function checkCourseDefaultPlaylist($course_id)
{
$default_playlist = PlaylistSeminars::findOneBySQL('seminar_id = ? AND is_default = 1', [$course_id]);
$default_playlist = PlaylistSeminars::getDefaultPlaylistSeminar($course_id);
return !empty($default_playlist);
}

Expand Down
11 changes: 11 additions & 0 deletions lib/Models/PlaylistSeminars.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,17 @@ public function toSanitizedArray()
return $playlist_data;
}

/**
* Get default playlist seminar of passed course
*
* @param String $course_id
* @return PlaylistSeminars|null
*/
public static function getDefaultPlaylistSeminar(String $course_id)
{
return self::findOneBySQL('seminar_id = ? AND is_default = 1', [$course_id]);
}

/**
* Get the courses of the passed video
*
Expand Down
15 changes: 14 additions & 1 deletion lib/Routes/Video/VideoCopyToCourse.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,32 @@ public function __invoke(Request $request, Response $response, $args)
try {
// Managing playlists.
$playlists = Playlists::findByCourse_id($course_id);
$default_playlist_seminar = PlaylistSeminars::getDefaultPlaylistSeminar($course_id);

if (!empty($courses) && !empty($playlists)) {
foreach ($courses as $course) {
if ($perm->have_studip_perm('tutor', $course['id']) && $course['id'] !== $course_id) {
$has_target_default_playlist = Helpers::checkCourseDefaultPlaylist($course['id']);

foreach ($playlists as $playlist) {
// Copy source playlist to target course
$new_playlist = $playlist->copy();

$is_default = false;
if (!$has_target_default_playlist
&& !empty($default_playlist_seminar)
&& $default_playlist_seminar->playlist_id === $playlist->id)
{
// Set default playlist of source course if target course has no default playlist
$is_default = true;
}

// Link playlist copy to target course
PlaylistSeminars::create([
'playlist_id' => $new_playlist->id,
'seminar_id' => $course['id'],
'visibility' => 'visible'
'visibility' => 'visible',
'is_default' => $is_default,
]);
}
}
Expand Down
3 changes: 1 addition & 2 deletions vueapp/components/Videos/Actions/VideoCopyToSeminar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export default {
},
computed: {
...mapGetters(['userCourses', 'cid', 'courseVideosToCopy']),
...mapGetters(['userCourses', 'cid']),
user_courses_filtered() {
let userCoursesFiltered = {};
Expand Down Expand Up @@ -112,7 +112,6 @@ export default {
let data = {
cid: this.cid,
courses: this.courses,
tokens: this.courseVideosToCopy
};
await this.$store.dispatch('copyVideosToCourses', data)
.then(({ data }) => {
Expand Down
8 changes: 1 addition & 7 deletions vueapp/store/videos.module.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,13 +225,7 @@ const actions = {
},

async copyVideosToCourses(context, data) {
return ApiService.post('videos/' + data.cid + '/copy',
{
courses: data.courses,
tokens: data?.tokens ?? [],
type: data.type,
}
);
return ApiService.post('videos/' + data.cid + '/copy', {courses: data.courses});
},

async setVideoSort({dispatch, commit}, sort) {
Expand Down

0 comments on commit c41df15

Please sign in to comment.