From 01be5588be227918c6f8b74c70d9a2c9886d40bc Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Mon, 24 Jun 2019 18:31:14 +0800 Subject: [PATCH] fix bug --- app/controllers/exercises_controller.rb | 8 ++++---- app/helpers/exercises_helper.rb | 8 +++++--- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index c3e8c4e5d..3e4dea5e3 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -201,16 +201,16 @@ class ExercisesController < ApplicationController def common_header ActiveRecord::Base.transaction do begin + @user_left_time = nil if @user_course_identity > Course::ASSISTANT_PROFESSOR @is_teacher_or = 0 @user_exercise_answer = @exercise.check_user_answer_status(current_user) @user_commit_counts = 0 - get_exercise_left_time(@exercise,current_user) + @user_left_time = get_exercise_left_time(@exercise,current_user) else @is_teacher_or = 1 @user_exercise_answer = 3 #教师页面 @user_commit_counts = @exercise.exercise_users.where(commit_status:1).count #已提交的用户数 - @user_left_time = nil end @ex_status = @exercise.get_exercise_status(current_user.id) @@ -1022,8 +1022,6 @@ class ExercisesController < ApplicationController end end - get_exercise_left_time(@exercise,@exercise_user_current) - # ex_time = @exercise.time # if ex_time > 0 # time_mill = ex_time * 60 #转为秒 @@ -1038,10 +1036,12 @@ class ExercisesController < ApplicationController @t_user_exercise_status = @exercise.get_exercise_status(current_user.id) + @user_left_time = nil if @user_course_identity < Course::STUDENT || (@t_user_exercise_status == 3) || (@exercise_user_current.present? && @exercise_user_current.commit_status == 1) @user_exercise_status = 1 #当前用户为老师/试卷已截止/试卷已提交不可编辑 else + @user_left_time = get_exercise_left_time(@exercise,current_user) @user_exercise_status = 0 #可编辑 end diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index b734d9685..3f3229136 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -681,9 +681,11 @@ module ExercisesHelper result end - def get_exercise_left_time(exercise,exercise_user) + def get_exercise_left_time(exercise,user) ex_time = exercise.time + user_left_time = nil if ex_time > 0 + exercise_user = exercise.exercise_users.find_by(user_id:user.id) time_mill = ex_time * 60 #转为秒 exercise_end_time = exercise.end_time.present? ? exercise.end_time.to_i : 0 exercise_user_start = exercise_user.present? ? exercise_user.start_at.to_i : 0 @@ -691,9 +693,9 @@ module ExercisesHelper time_mill = exercise_end_time - exercise_user_start #如果开始答题时间加试卷的限时长大于试卷的截止时间,则以试卷的截止时间到开始答题时间为试卷的限时 end exercise_user_left_time = Time.now.to_i - exercise_user_start #用户已回答的时间 - @user_left_time = (time_mill < exercise_user_left_time) ? nil : (time_mill - exercise_user_left_time) #当前用户对试卷的回答剩余时间 + user_left_time = (time_mill < exercise_user_left_time) ? nil : (time_mill - exercise_user_left_time) #当前用户对试卷的回答剩余时间 end - @user_left_time + user_left_time end #实训题学生代码的行数