From f6a5a0ebbca775e8f6d72ac8d4f65c7b9aea6b21 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Thu, 18 Jul 2019 15:27:07 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AF=95=E5=8D=B7=EF=BC=8C=E9=97=AE=E5=8D=B7?= =?UTF-8?q?=E7=9A=84=E7=8A=B6=E6=80=81=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/exercise.rb | 12 ++++++++---- app/models/poll.rb | 28 +++++++++++++++++----------- 2 files changed, 25 insertions(+), 15 deletions(-) diff --git a/app/models/exercise.rb b/app/models/exercise.rb index aba0a00bc..8286a96e2 100644 --- a/app/models/exercise.rb +++ b/app/models/exercise.rb @@ -127,8 +127,10 @@ class Exercise < ApplicationRecord #判断是否为分班,如果分班,试卷的截止时间为当前分班时间,否则为试卷的截止时间 def get_exercise_status(user) - return Exercise::UNPUBLISHED if user.nil? - if user.student_of_course?(course) #当为学生的时候,需根据分班来判断试卷状态 + if course.end_time.present? && course.end_time <= Time.now + status = 4 + else + if user.present? && user.student_of_course?(course) #当为学生的时候,需根据分班来判断试卷状态 ex_time = get_exercise_times(user_id,false) pb_time = ex_time[:publish_time] ed_time = ex_time[:end_time] @@ -139,9 +141,11 @@ class Exercise < ApplicationRecord else status = Exercise::UNPUBLISHED end - else - status = exercise_status #当为老师的时候,则为试卷的总状态 + else + status = exercise_status #当为老师的时候,则为试卷的总状态 + end end + status end diff --git a/app/models/poll.rb b/app/models/poll.rb index e6a363f1d..5fda30609 100644 --- a/app/models/poll.rb +++ b/app/models/poll.rb @@ -100,19 +100,25 @@ class Poll < ApplicationRecord end def get_poll_status(user) - if user.student_of_course?(course) - ex_time = get_poll_times(user_id,false) - pb_time = ex_time[:publish_time] - ed_time = ex_time[:end_time] - if pb_time.present? && ed_time.present? && pb_time <= Time.now && ed_time > Time.now - status = 2 - elsif ed_time.present? && ed_time <= Time.now - status = 3 + if course.end_time.present? && course.end_time <= Time.now + status = 4 + else + if user.present? && user.student_of_course?(course) + ex_time = get_poll_times(user_id,false) + pb_time = ex_time[:publish_time] + ed_time = ex_time[:end_time] + if course.end_time.present? && course.end_time <= Time.now + status = 4 + elsif pb_time.present? && ed_time.present? && pb_time <= Time.now && ed_time > Time.now + status = 2 + elsif ed_time.present? && ed_time <= Time.now + status = 3 + else + status = 1 + end else - status = 1 + status = polls_status end - else - status = polls_status end status end