|
|
|
@ -103,25 +103,37 @@ class CoursesController < ApplicationController
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def course_videos
|
|
|
|
|
videos = @course.course_videos
|
|
|
|
|
course_videos = @course.course_videos
|
|
|
|
|
course_videos = course_videos.joins("
|
|
|
|
|
JOIN videos ON course_videos.video_id = videos.id
|
|
|
|
|
LEFT JOIN (
|
|
|
|
|
SELECT watch_course_videos.course_video_id,
|
|
|
|
|
SUM(watch_course_videos.total_duration) AS total_duration,
|
|
|
|
|
count(watch_course_videos.course_video_id) AS count
|
|
|
|
|
FROM watch_course_videos
|
|
|
|
|
JOIN course_videos ON watch_course_videos.course_video_id = course_videos.id AND watch_course_videos.end_at IS NOT NULL
|
|
|
|
|
JOIN course_members ON course_members.user_id = watch_course_videos.user_id AND course_members.course_id = #{@course.id} AND role = 4
|
|
|
|
|
WHERE course_videos.course_id = #{@course.id}
|
|
|
|
|
GROUP BY watch_course_videos.course_video_id
|
|
|
|
|
) AS watch_courses ON watch_courses.course_video_id = course_videos.id
|
|
|
|
|
").where("((videos.transcoded = TRUE OR videos.user_id = #{current_user.id}) OR course_videos.is_link = TRUE)")
|
|
|
|
|
|
|
|
|
|
@video_module = @course.course_modules.find_by(module_type: "video")
|
|
|
|
|
|
|
|
|
|
if params[:category_id].present? && params[:category_id].to_i != 0
|
|
|
|
|
@category = @video_module&.course_second_categories.find_by(id: params[:category_id])
|
|
|
|
|
tip_exception("子目录id有误") if !@category.present?
|
|
|
|
|
videos = videos.where(course_second_category_id: params[:category_id].to_i)
|
|
|
|
|
course_videos = course_videos.where(course_second_category_id: params[:category_id].to_i)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
videos = custom_sort(videos, params[:sort_by], params[:sort_direction])
|
|
|
|
|
course_videos = custom_sort(course_videos, params[:sort_by], params[:sort_direction])
|
|
|
|
|
|
|
|
|
|
course_videos = course_videos.includes(video: [user: :user_extension], user: :user_extension)
|
|
|
|
|
|
|
|
|
|
#sql = "left join videos on videos.id=course_videos.video_id AND (videos.transcoded=1 OR videos.user_id = #{current_user.id})"
|
|
|
|
|
#@videos = paginate videos.joins(sql).includes(video: [user: :user_extension], user: :user_extension)
|
|
|
|
|
videos = videos.includes(video: [user: :user_extension],user: :user_extension).select("course_videos.id, course_videos.title, course_videos.link, course_videos.user_id")
|
|
|
|
|
videos = videos.where(videos: {transcoded: true})
|
|
|
|
|
.or(videos.where(videos: {user_id: current_user.id}))
|
|
|
|
|
.or(videos.where(course_videos: {is_link: true}))
|
|
|
|
|
@count = videos.count("course_videos.id")
|
|
|
|
|
@count = course_videos.count("course_videos.id")
|
|
|
|
|
logger.info("#######count:#{@count}")
|
|
|
|
|
@videos = paginate videos
|
|
|
|
|
course_videos = course_videos.select("IFNULL(watch_courses.total_duration, 0) AS total_duration, IFNULL(watch_courses.count,0) AS count, course_videos.video_id, course_videos.title, course_videos.is_link, course_videos.user_id")
|
|
|
|
|
@videos = paginate course_videos
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def delete_course_video
|
|
|
|
|