From 5f9b7c77410e8659c3c005a6f53c147d8215cbcf Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Tue, 11 Jun 2019 15:57:10 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AF=95=E5=8D=B7=E5=A2=9E=E5=8A=A0=E6=9F=A5?= =?UTF-8?q?=E7=9C=8B=E4=B8=AA=E4=BA=BA=E6=88=90=E7=BB=A9=E7=9A=84=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/exercise_controller.rb | 12 ++- app/helpers/exercise_helper.rb | 2 +- app/views/exercise/_exercise_setting.html.erb | 12 +++ .../_exercise_student_result.html.erb | 101 ++++++++++-------- app/views/exercise/_student_exercise.html.erb | 2 +- ...213_add_column_exercise_view_self_score.rb | 8 ++ 6 files changed, 84 insertions(+), 53 deletions(-) create mode 100644 db/migrate/20190611070213_add_column_exercise_view_self_score.rb diff --git a/app/controllers/exercise_controller.rb b/app/controllers/exercise_controller.rb index 1a7fb58a..fd8a7216 100755 --- a/app/controllers/exercise_controller.rb +++ b/app/controllers/exercise_controller.rb @@ -416,6 +416,7 @@ class ExerciseController < ApplicationController @exercise.time = (params[:time].strip == "" ? -1 : params[:time]) if params[:time] @exercise.question_random = params[:question_random] ? 1 : 0 @exercise.choice_random = params[:choice_random] ? 1 : 0 + @exercise.view_score = params[:view_score] ? 1 : 0 @exercise.score_open = params[:score_open] ? 1 : 0 @exercise.answer_open = params[:answer_open] ? 1 : 0 @exercise.show_statistic = params[:show_statistic] ? 1 : 0 @@ -1342,11 +1343,14 @@ class ExerciseController < ApplicationController end @exercise = Exercise.find params[:id] @course = @exercise.course - @is_teacher = params[:pdf] ? true : User.current.allowed_to?(:as_teacher,@course) || User.current.admin? - if @is_teacher || (User.current.member_of_course?(@exercise.course) && @exercise.exercise_status > 2) - @user = User.find params[:user_id] + @is_teacher = params[:pdf] && User.current.nil? ? true : User.current.allowed_to?(:as_teacher,@course) || User.current.admin? + @user = User.find params[:user_id] + current_ex_user = ExerciseUser.where("user_id =? and exercise_id=?", User.current.id, @exercise.id).first if User.current + if @is_teacher || (User.current.member_of_course?(@exercise.course) && @exercise.end_time <= Time.now && + current_ex_user && (@exercise.score_open || User.current == @user)) @exercise_user = ExerciseUser.where("user_id =? and exercise_id=?", @user.id, @exercise.id).first @exercise_questions = (@exercise.user_question_list @exercise_user.id).reorder("question_number = 0 asc, question_number asc") + @show_score = User.current.present? && User.current == @user && !@exercise.view_score ? false : true respond_to do |format| if params[:pdf] format.html { render :layout => "pdf" } @@ -1470,7 +1474,7 @@ class ExerciseController < ApplicationController :status => answer_status) end - score4 += exercise_cha_score + score4 += exercise_cha_score.to_f end end end diff --git a/app/helpers/exercise_helper.rb b/app/helpers/exercise_helper.rb index 28ebf46f..9ce0a9ee 100755 --- a/app/helpers/exercise_helper.rb +++ b/app/helpers/exercise_helper.rb @@ -126,7 +126,7 @@ module ExerciseHelper score = 0 if eq.question_type == 5 eq.exercise_shixun_answers.where(:user_id => user.id).each do |answer| - score += answer.score + score += answer.score.to_f end end score diff --git a/app/views/exercise/_exercise_setting.html.erb b/app/views/exercise/_exercise_setting.html.erb index 41f183b1..734991ce 100755 --- a/app/views/exercise/_exercise_setting.html.erb +++ b/app/views/exercise/_exercise_setting.html.erb @@ -138,6 +138,12 @@