From 1ad274851aa826e5a27aa7b02274deea728fefb6 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Tue, 17 Dec 2019 23:10:55 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9E=E8=AE=AD=E4=BD=9C=E4=B8=9A=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/helpers/homework_commons_helper.rb | 172 ++++++++++++------------- 1 file changed, 83 insertions(+), 89 deletions(-) diff --git a/app/helpers/homework_commons_helper.rb b/app/helpers/homework_commons_helper.rb index dffc6cf3e..8d15c1b81 100644 --- a/app/helpers/homework_commons_helper.rb +++ b/app/helpers/homework_commons_helper.rb @@ -24,109 +24,103 @@ module HomeworkCommonsHelper time = course.end_date.strftime("%Y-%m-%d") time_status = 6 else - if homework_common.end_time && homework_common.end_time < Time.now && homework_common.allow_late && - (homework_common.late_time.nil? || homework_common.late_time > Time.now) - status << "补交中" - time = "补交剩余时间:" + how_much_time(homework_common.late_time) - time_status = 2 - else - ho_detail_manual = homework_common.homework_detail_manual - if ho_detail_manual - # 作业状态大于“提交”状态时,不用考虑分班权限 - if ho_detail_manual.comment_status > 1 - case ho_detail_manual.comment_status - when 2 - unless homework_common.allow_late - status << "已截止" - time = course.end_date.present? ? ("评阅剩余时间:" + how_much_time(course.end_date.end_of_day)) : "" - time_status = 5 - end - when 3 - if ho_detail_manual.evaluation_end && ho_detail_manual.evaluation_end > Time.now - status << "匿评中" - time = "提交剩余时间:" + how_much_time(ho_detail_manual.evaluation_end) - time_status = 3 - end - when 4 - if ho_detail_manual.appeal_time && ho_detail_manual.appeal_time > Time.now - status << "申诉中" - time = "申诉剩余时间:" + how_much_time(ho_detail_manual.appeal_time) - time_status = 4 - end - when 5, 6 + ho_detail_manual = homework_common.homework_detail_manual + if ho_detail_manual + # 作业状态大于“提交”状态时,不用考虑分班权限 + if ho_detail_manual.comment_status > 1 + case ho_detail_manual.comment_status + when 3 + if ho_detail_manual.evaluation_end && ho_detail_manual.evaluation_end > Time.now + status << "匿评中" + time = "提交剩余时间:" + how_much_time(ho_detail_manual.evaluation_end) + time_status = 3 + end + when 4 + if ho_detail_manual.appeal_time && ho_detail_manual.appeal_time > Time.now + status << "申诉中" + time = "申诉剩余时间:" + how_much_time(ho_detail_manual.appeal_time) + time_status = 4 + end + else + if homework_common.end_time && homework_common.end_time < Time.now && homework_common.allow_late && + (homework_common.late_time.nil? || homework_common.late_time > Time.now) + status << "补交中" + time = "补交剩余时间:" + how_much_time(homework_common.late_time) + time_status = 2 + else status << "已截止" time = course.end_date.present? ? ("评阅剩余时间:" + how_much_time(course.end_date.end_of_day)) : "" time_status = 5 end - else - # member = course.course_members.find_by(user_id: user.id, is_active: 1) - # teacher_course_groups = member.try(:teacher_course_groups) - # identity = user.course_identity(course) + end + else + # member = course.course_members.find_by(user_id: user.id, is_active: 1) + # teacher_course_groups = member.try(:teacher_course_groups) + # identity = user.course_identity(course) - # 作业统一设置、游客身份、超级管理员、分班权限不限的老师身份 - if homework_common.unified_setting || identity > Course::STUDENT || identity == Course::ADMIN || - (identity < Course::STUDENT && teacher_course_groups.blank?) - case ho_detail_manual.comment_status - when 0 - status << "未发布" - time = homework_common.publish_time.present? ? "将于 #{format_time(homework_common.publish_time)} 发布" : "创建于#{time_from_now(homework_common.created_at)}" - time_status = 0 - when 1 - if homework_common.end_time && homework_common.end_time >= Time.now - status << "提交中" - time = "提交剩余时间:" + how_much_time(homework_common.end_time) - time_status = 1 - elsif homework_common.end_time && homework_common.end_time < Time.now - if homework_common.allow_late && (homework_common.late_time.nil? || homework_common.late_time >= Time.now) - time = "补交剩余时间:" + how_much_time(homework_common.late_time) - time_status = 2 - else - status << "已截止" - time = course.end_date.present? ? ("评阅剩余时间:" + how_much_time(course.end_date.end_of_day)) : "" - time_status = 5 - end + # 作业统一设置、游客身份、超级管理员、分班权限不限的老师身份 + if homework_common.unified_setting || identity > Course::STUDENT || identity == Course::ADMIN || + (identity < Course::STUDENT && teacher_course_groups.blank?) + case ho_detail_manual.comment_status + when 0 + status << "未发布" + time = homework_common.publish_time.present? ? "将于 #{format_time(homework_common.publish_time)} 发布" : "创建于#{time_from_now(homework_common.created_at)}" + time_status = 0 + when 1 + if homework_common.end_time && homework_common.end_time >= Time.now + status << "提交中" + time = "提交剩余时间:" + how_much_time(homework_common.end_time) + time_status = 1 + elsif homework_common.end_time && homework_common.end_time < Time.now + if homework_common.allow_late && (homework_common.late_time.nil? || homework_common.late_time >= Time.now) + time = "补交剩余时间:" + how_much_time(homework_common.late_time) + time_status = 2 + else + status << "已截止" + time = course.end_date.present? ? ("评阅剩余时间:" + how_much_time(course.end_date.end_of_day)) : "" + time_status = 5 end end + end + else + # 未分班的学生始终显示“未发布”(按理不会来到这个判断) + if member.role == "STUDENT" && member.course_group_id == 0 + status << "未发布" + time = "" + time_status = 0 else - # 未分班的学生始终显示“未发布”(按理不会来到这个判断) - if member.role == "STUDENT" && member.course_group_id == 0 + if member.role == "STUDENT" + setting = homework_common.homework_group_settings.find_by(course_group_id: member.course_group_id) + min_publish_time = setting.try(:publish_time) + max_end_time = setting.try(:end_time) + else + # 多个分班权限的取最小publish_time,最大end_time + min_publish_time = homework_common.homework_group_settings.where.not(publish_time: nil). + where(course_group_id: teacher_course_groups.pluck(:course_group_id)).pluck(:publish_time).min + max_end_time = homework_common.homework_group_settings.where.not(end_time: nil). + where(course_group_id: teacher_course_groups.pluck(:course_group_id)).pluck(:end_time).max + end + + if min_publish_time.nil? status << "未发布" - time = "" + time = "创建于#{time_from_now(homework_common.created_at)}" time_status = 0 + elsif min_publish_time > Time.now + status << "未发布" + time = "将于 #{format_time(min_publish_time)} 发布" + time_status = 0 + elsif max_end_time.present? && max_end_time > Time.now #6.14 -hs 添加present? + status << "提交中" + time = "提交剩余时间:" + how_much_time(max_end_time) + time_status = 1 else - if member.role == "STUDENT" - setting = homework_common.homework_group_settings.find_by(course_group_id: member.course_group_id) - min_publish_time = setting.try(:publish_time) - max_end_time = setting.try(:end_time) - else - # 多个分班权限的取最小publish_time,最大end_time - min_publish_time = homework_common.homework_group_settings.where.not(publish_time: nil). - where(course_group_id: teacher_course_groups.pluck(:course_group_id)).pluck(:publish_time).min - max_end_time = homework_common.homework_group_settings.where.not(end_time: nil). - where(course_group_id: teacher_course_groups.pluck(:course_group_id)).pluck(:end_time).max - end - - if min_publish_time.nil? - status << "未发布" - time = "创建于#{time_from_now(homework_common.created_at)}" - time_status = 0 - elsif min_publish_time > Time.now - status << "未发布" - time = "将于 #{format_time(min_publish_time)} 发布" - time_status = 0 - elsif max_end_time.present? && max_end_time > Time.now #6.14 -hs 添加present? - status << "提交中" - time = "提交剩余时间:" + how_much_time(max_end_time) - time_status = 1 - else - status << "已截止" - time = course.end_date.present? ? ("评阅剩余时间:" + how_much_time(course.end_date.end_of_day)) : "" - time_status = 5 - end + status << "已截止" + time = course.end_date.present? ? ("评阅剩余时间:" + how_much_time(course.end_date.end_of_day)) : "" + time_status = 5 end end - status << "未开启补交" if !homework_common.allow_late && time_status == 1 end + status << "未开启补交" if !homework_common.allow_late && time_status == 1 end end end