@@ -464,28 +464,36 @@ public static function adjustVideoPermissionsForNewCourseTutors($eventType, $sem
464464
465465 $ perm ->store ();
466466 }
467+ }
468+ }
467469
468- // Now compile the list of playlist seminar videos, in order to add tutor perm to that video as well.
469- $ playlist_seminar_videos = PlaylistSeminarVideos::findBySQL ('playlist_seminar_id = ? ' , [$ playlist ->id ]);
470+ /**
471+ * Revoke the video permissions of the course tutors
472+ *
473+ * @Notification UserDidLeaveCourse
474+ *
475+ * @param string $eventType
476+ * @param string $seminar_id
477+ * @param string $user_id
478+ */
479+ public static function revokeTutorsVideoPermissions ($ eventType , $ seminar_id , $ user_id ) {
480+ global $ perm ;
470481
471- if (empty ($ playlist_seminar_videos )) {
472- // No videos found, so we can stop here.
473- continue ;
474- }
482+ // First get the course playlists.
483+ $ playlists = PlaylistSeminars::findBySQL ('seminar_id = ? ' , [$ seminar_id ]);
475484
476- foreach ($ playlist_seminar_videos as $ psv ) {
477- // Check if the user already has permissions on the video.
478- $ perm = VideosUserPerms::findOneBySQL ('video_id = ? AND user_id = ? ' , [$ psv ->video_id , $ user_id ]);
485+ if (empty ($ playlists )) {
486+ // No playlists found, so we can stop here.
487+ return ;
488+ }
479489
480- if (empty ($ perm )) {
481- // If not, create a new permission for the user.
482- $ perm = new VideosUserPerms ();
483- $ perm ->video_id = $ psv ->video_id ;
484- $ perm ->user_id = $ user_id ;
485- $ perm ->perm = 'write ' ;
490+ foreach ($ playlists as $ playlist ) {
491+ // Check if the user has permissions on the playlist.
492+ $ perm = PlaylistsUserPerms::findOneBySQL ('playlist_id = ? AND user_id = ? ' , [$ playlist ->id , $ user_id ]);
486493
487- $ perm ->store ();
488- }
494+ if (!empty ($ perm )) {
495+ // If yes, delete the permission for the user.
496+ $ perm ->delete ();
489497 }
490498 }
491499 }
0 commit comments