|
|
|
@ -30,7 +30,8 @@ class CoursesController < ApplicationController
|
|
|
|
|
:informs, :update_informs, :online_learning, :update_task_position, :tasks_list,
|
|
|
|
|
:join_excellent_course, :export_couser_info, :export_member_act_score, :new_informs,
|
|
|
|
|
:delete_informs, :change_member_role, :course_groups, :join_course_group, :statistics,
|
|
|
|
|
:work_score, :act_score, :calculate_all_shixun_scores, :move_to_category, :watch_video_histories]
|
|
|
|
|
:work_score, :act_score, :calculate_all_shixun_scores, :move_to_category, :watch_video_histories, :watch_statics,
|
|
|
|
|
:own_watch_histories]
|
|
|
|
|
before_action :user_course_identity, except: [:join_excellent_course, :index, :create, :new, :apply_to_join_course,
|
|
|
|
|
:search_course_list, :get_historical_course_students, :mine, :search_slim, :board_list]
|
|
|
|
|
before_action :teacher_allowed, only: [:update, :destroy, :settings, :search_teacher_candidate,
|
|
|
|
@ -1482,23 +1483,58 @@ class CoursesController < ApplicationController
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# 课堂视频观看记录总览
|
|
|
|
|
def watch_video_histories
|
|
|
|
|
return normal_status(403, "你没有权限操作") unless current_user.teacher_of_course?(@course)
|
|
|
|
|
|
|
|
|
|
@videos = CourseVideo.find_by_sql("
|
|
|
|
|
SELECT course_videos.id, videos.user_id, videos.title, IFNULL(hisotries.time,0) AS time, IFNULL(hisotries.num,0) AS num
|
|
|
|
|
FROM course_videos
|
|
|
|
|
JOIN videos ON course_videos.course_id = #{@course.id} AND videos.id = course_videos.video_id
|
|
|
|
|
LEFT JOIN (
|
|
|
|
|
SELECT watch_course_videos.course_video_id, sum(watch_course_videos.total_duration) AS time, count(watch_course_videos.course_video_id) AS num
|
|
|
|
|
FROM watch_course_videos
|
|
|
|
|
LEFT JOIN (
|
|
|
|
|
SELECT watch_course_videos.course_video_id, SUM(watch_course_videos.total_duration) AS time, COUNT(watch_course_videos.course_video_id) AS num
|
|
|
|
|
FROM watch_course_videos
|
|
|
|
|
JOIN course_videos ON course_videos.id = watch_course_videos.course_video_id AND watch_course_videos.end_at IS NOT NULL
|
|
|
|
|
WHERE course_videos.course_id = #{@course.id}
|
|
|
|
|
GROUP BY watch_course_videos.course_video_id
|
|
|
|
|
) AS hisotries ON hisotries.course_video_id = course_videos.id
|
|
|
|
|
")
|
|
|
|
|
@count = @videos.count
|
|
|
|
|
@videos = paginate @videos
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# 学生角度观看课堂视频的记录
|
|
|
|
|
def own_watch_histories
|
|
|
|
|
@current_user = current_user
|
|
|
|
|
@videos = CourseVideo.find_by_sql("
|
|
|
|
|
SELECT course_videos.id, watch_course_videos.start_at, watch_course_videos.total_duration, watch_course_videos.end_at, watch_course_videos.is_finished, videos.title, IFNULL(hisotries.time,0) AS time, IFNULL(hisotries.num,0) AS num
|
|
|
|
|
FROM course_videos
|
|
|
|
|
JOIN videos ON course_videos.course_id = #{@course.id} AND videos.id = course_videos.video_id
|
|
|
|
|
JOIN watch_course_videos ON course_videos.id = watch_course_videos.course_video_id AND watch_course_videos.user_id = #{current_user.id}
|
|
|
|
|
JOIN (
|
|
|
|
|
SELECT watch_course_videos.course_video_id, SUM(watch_course_videos.total_duration) AS time, COUNT(watch_course_videos.course_video_id) AS num
|
|
|
|
|
FROM watch_course_videos
|
|
|
|
|
JOIN course_videos ON course_videos.id = watch_course_videos.course_video_id
|
|
|
|
|
WHERE course_videos.course_id = #{@course.id}
|
|
|
|
|
GROUP BY watch_course_videos.course_video_id
|
|
|
|
|
) AS hisotries ON hisotries.course_video_id = course_videos.id
|
|
|
|
|
WHERE course_videos.course_id = #{@course.id} AND watch_course_videos.user_id = #{current_user.id} AND watch_course_videos.end_at IS NOT NULL
|
|
|
|
|
GROUP BY watch_course_videos.course_video_id
|
|
|
|
|
) AS hisotries ON hisotries.course_video_id = course_videos.id
|
|
|
|
|
")
|
|
|
|
|
@count = @videos.count
|
|
|
|
|
@videos = paginate @videos
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# 课堂视频的统计总览
|
|
|
|
|
def watch_statics
|
|
|
|
|
@total_duration = @course.course_videos.joins(:watch_course_videos).sum(:total_duration).round(2)
|
|
|
|
|
@frequencies = @course.course_videos.joins([watch_course_videos: :watch_video_histories]).count(:id)
|
|
|
|
|
@people_num = @course.course_videos.joins(:watch_course_videos).count(:id)
|
|
|
|
|
render json: {
|
|
|
|
|
total_duration: @total_duration,
|
|
|
|
|
freq: @frequencies,
|
|
|
|
|
people_num: @people_num
|
|
|
|
|
}
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
|
|
# Use callbacks to share common setup or constraints between actions.
|
|
|
|
|