课堂增加视频模块

dev_video
cxt 5 years ago
parent 81ceac90e7
commit d71c181d12

@ -206,7 +206,7 @@ class Course < ApplicationRecord
end
def all_course_module_types
%w[activity announcement online_learning shixun_homework common_homework group_homework exercise attachment course_group graduation poll board statistics]
%w[activity announcement online_learning shixun_homework common_homework group_homework exercise attachment course_group graduation poll board statistics video]
end
def get_course_module_by_type(type)
@ -406,6 +406,7 @@ class Course < ApplicationRecord
when 'exercise' then '试卷'
when 'poll' then '问卷'
when 'attachment' then '资源'
when 'video' then '视频'
when 'board' then '讨论'
when 'course_group' then '分班'
when 'statistics' then '统计'
@ -425,9 +426,10 @@ class Course < ApplicationRecord
when 'exercise' then 8
when 'poll' then 9
when 'attachment' then 10
when 'board' then 11
when 'course_group' then 12
when 'statistics' then 13
when 'video' then 11
when 'board' then 12
when 'course_group' then 13
when 'statistics' then 14
else 100
end
end

@ -0,0 +1,12 @@
class AddVideoToCourseModule < ActiveRecord::Migration[5.2]
def change
Course.all.each do |course|
unless course.course_modules.exists?(module_type: "video")
atta_position = course.course_modules.find_by(module_type: 'attachment')&.position.to_i
video_position = atta_position != 0 ? (atta_position + 1) : 11
course.course_modules.where("position >= #{video_position}").update_all("position = position + 1")
course.course_modules << CourseModule.new(module_type: "video", hidden: 1, module_name: "视频", position: video_position)
end
end
end
end
Loading…
Cancel
Save