|
|
|
@ -682,16 +682,26 @@ module ExercisesHelper
|
|
|
|
|
def get_exercise_left_time(exercise,user)
|
|
|
|
|
ex_time = exercise.time
|
|
|
|
|
user_left_time = nil
|
|
|
|
|
time_now_i = Time.now.to_i
|
|
|
|
|
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
|
|
|
|
|
if (exercise_user_start + time_mill) > exercise_end_time
|
|
|
|
|
time_mill = exercise_end_time - exercise_user_start #如果开始答题时间加试卷的限时长大于试卷的截止时间,则以试卷的截止时间到开始答题时间为试卷的限时
|
|
|
|
|
#用户未开始答题时,即exercise_user_start为0
|
|
|
|
|
if exercise_user_start == 0
|
|
|
|
|
if (exercise_end_time - time_now_i) > time_mill
|
|
|
|
|
user_left_time = time_mill
|
|
|
|
|
else
|
|
|
|
|
user_left_time = (exercise_end_time < time_now_i) ? nil : (exercise_end_time - time_now_i)
|
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
if (exercise_user_start + time_mill) > exercise_end_time
|
|
|
|
|
time_mill = exercise_end_time - exercise_user_start #如果开始答题时间加试卷的限时长大于试卷的截止时间,则以试卷的截止时间到开始答题时间为试卷的限时
|
|
|
|
|
end
|
|
|
|
|
exercise_user_left_time = time_now_i - exercise_user_start #用户已回答的时间
|
|
|
|
|
user_left_time = (time_mill < exercise_user_left_time) ? nil : (time_mill - exercise_user_left_time) #当前用户对试卷的回答剩余时间
|
|
|
|
|
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) #当前用户对试卷的回答剩余时间
|
|
|
|
|
end
|
|
|
|
|
user_left_time
|
|
|
|
|
end
|
|
|
|
|