diff --git a/app/helpers/courses_helper.rb b/app/helpers/courses_helper.rb index 27444b3c9..9a4366528 100644 --- a/app/helpers/courses_helper.rb +++ b/app/helpers/courses_helper.rb @@ -81,6 +81,8 @@ module CoursesHelper "/classrooms/#{course.id}/statistics" when "video" "/classrooms/#{course.id}/course_videos" + when "attendance" + "/classrooms/#{course.id}/signin" end end @@ -131,31 +133,33 @@ module CoursesHelper # 课堂模块的任务数 def course_task_count(course, module_type) case module_type - when "shixun_homework" - get_homework_commons_count(course, 4, 0) - when "common_homework" - get_homework_commons_count(course, 1, 0) - when "group_homework" - get_homework_commons_count(course, 3, 0) - when "graduation" - 0 - when "exercise" - course.exercises_count - when "poll" - course.polls_count - when "attachment" - get_attachment_count(course, 0) - when "board" - course_board = course.course_board - course_board.present? ? course_board.messages.size : 0 - when "course_group" - course.course_groups_count - when "announcement" - course.informs.count - when "online_learning" - course.shixuns.count - when "video" - course.videos_count + course.live_links.count + when "shixun_homework" + get_homework_commons_count(course, 4, 0) + when "common_homework" + get_homework_commons_count(course, 1, 0) + when "group_homework" + get_homework_commons_count(course, 3, 0) + when "graduation" + 0 + when "exercise" + course.exercises_count + when "poll" + course.polls_count + when "attachment" + get_attachment_count(course, 0) + when "board" + course_board = course.course_board + course_board.present? ? course_board.messages.size : 0 + when "course_group" + course.course_groups_count + when "announcement" + course.informs.count + when "online_learning" + course.shixuns.count + when "video" + course.videos_count + course.live_links.count + when "attendance" + course.attendances.count end end diff --git a/app/models/course.rb b/app/models/course.rb index abe17b3cd..bd36e65eb 100644 --- a/app/models/course.rb +++ b/app/models/course.rb @@ -226,7 +226,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 video] + %w[activity announcement online_learning shixun_homework common_homework group_homework exercise attachment course_group graduation poll board statistics video attendance] end def get_course_module_by_type(type) @@ -429,6 +429,7 @@ class Course < ApplicationRecord when 'video' then '视频直播' when 'board' then '讨论' when 'course_group' then '分班' + when 'attendance' then '签到' when 'statistics' then '统计' else '' end @@ -449,7 +450,8 @@ class Course < ApplicationRecord when 'video' then 11 when 'board' then 12 when 'course_group' then 13 - when 'statistics' then 14 + when 'attendance' then 14 + when 'statistics' then 15 else 100 end end diff --git a/db/migrate/20200312075912_add_attendance_to_course_module.rb b/db/migrate/20200312075912_add_attendance_to_course_module.rb new file mode 100644 index 000000000..02bb48fe1 --- /dev/null +++ b/db/migrate/20200312075912_add_attendance_to_course_module.rb @@ -0,0 +1,16 @@ +class AddAttendanceToCourseModule < ActiveRecord::Migration[5.2] + def change + Course.all.each do |course| + unless course.course_modules.exists?(module_type: "attendance") + atta_position = course.course_modules.find_by(module_type: 'course_group')&.position.to_i + attendance_position = atta_position != 0 ? (atta_position + 1) : 14 + course.course_modules.where("position >= #{attendance_position}").update_all("position = position + 1") + if course.is_end + course.course_modules << CourseModule.new(module_type: "attendance", hidden: 1, module_name: "签到", position: attendance_position) + else + course.course_modules << CourseModule.new(module_type: "attendance", hidden: 0, module_name: "签到", position: attendance_position) + end + end + end + end +end