From d71c181d12b90c4d6f6773fa928d8a008967a961 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Fri, 7 Feb 2020 17:30:50 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AF=BE=E5=A0=82=E5=A2=9E=E5=8A=A0=E8=A7=86?= =?UTF-8?q?=E9=A2=91=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/course.rb | 10 ++++++---- .../20200207090252_add_video_to_course_module.rb | 12 ++++++++++++ 2 files changed, 18 insertions(+), 4 deletions(-) create mode 100644 db/migrate/20200207090252_add_video_to_course_module.rb diff --git a/app/models/course.rb b/app/models/course.rb index 1d5175ed3..eb7ffd91f 100644 --- a/app/models/course.rb +++ b/app/models/course.rb @@ -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 diff --git a/db/migrate/20200207090252_add_video_to_course_module.rb b/db/migrate/20200207090252_add_video_to_course_module.rb new file mode 100644 index 000000000..1d0364524 --- /dev/null +++ b/db/migrate/20200207090252_add_video_to_course_module.rb @@ -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