From 84b6110c56e58c409628273315ad252bb82b9172 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Sat, 29 Jun 2019 14:44:18 +0800 Subject: [PATCH 1/2] fix bug --- .../exercise_questions_controller.rb | 2 +- app/helpers/exercises_helper.rb | 17 ++++++++++++----- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/app/controllers/exercise_questions_controller.rb b/app/controllers/exercise_questions_controller.rb index 79d671605..b231d6af7 100644 --- a/app/controllers/exercise_questions_controller.rb +++ b/app/controllers/exercise_questions_controller.rb @@ -616,7 +616,7 @@ class ExerciseQuestionsController < ApplicationController elsif params[:question_type].to_i == 2 && (params[:standard_answers].count > 1 || params[:question_choices].blank? || params[:question_choices].include?("")) #判断题的标准答案不能大于1个,选项不能为空 normal_status(-1,"判断题选项不能为空/标准答案不能大于1个!") elsif params[:question_type].to_i <= 1 && (params[:question_choices].blank? || params[:question_choices].include?("") || params[:question_choices].count < 2) #选择题选项不能为空,且不能小于2 - normal_status(-1,"选择题选项内容不能为空,且不能少于3个!") + normal_status(-1,"选择题选项内容不能为空,且不能少于2个!") elsif params[:question_type].to_i == 3 && (params[:standard_answers].blank? || params[:standard_answers].count > 5 ) #填空题选项最多为5个,且如果为1个的话,不允许修改is_ordered normal_status(-1,"填空题标准答案不能为空/不能超过5个!") elsif params[:question_type].to_i == 4 && params[:standard_answers].count > 2 #简单题参考答案最多为1个 diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index 04890954b..1442e1da3 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -167,10 +167,13 @@ module ExercisesHelper ex_score = ex&.question_score full_scores = effictive_users.search_exercise_answer("score",ex_score).count #满分人数 no_full_scores = effictive_users.exercise_no_full_scores(ex_score).count #部分分数人数 - all_zero_scores = effictive_users.search_exercise_answer("score",0.0).count #包含为0分的,及未评阅的 - review_scores = ex.exercise_answer_comments.count #主观题的评阅数量 - un_review_scores = effictive_users_count - review_scores #未评阅数 - zero_scores = all_zero_scores - un_review_scores #已评阅,且答案未0分的人数 + zero_scores = effictive_users.search_exercise_answer("score",0.0).count #包含为0分的,及未评阅的 + # review_scores = ex.exercise_answer_comments.count #主观题的评阅数量 + un_review_scores = effictive_users_count - full_scores - no_full_scores - zero_scores #未评阅数 + if un_review_scores < 0 + un_review_scores = 0 + end + # zero_scores = all_zero_scores - un_review_scores #已评阅,且答案未0分的人数 main_scores_array = [full_scores,no_full_scores,zero_scores,un_review_scores] main_scores_array.each_with_index do |s,index| if index == 0 @@ -642,7 +645,11 @@ module ExercisesHelper end if student_status == 2 #当前为老师,或为学生且已提交 user_score_pre = exercise_answers.score_reviewed - user_score = user_score_pre.present? ? user_score_pre.pluck(:score).sum : 0.0 + if ques_type == 4 && user_score_pre.blank? #主观题时,且没有大于0的分数时,为空 + user_score = nil + else + user_score = user_score_pre.present? ? user_score_pre.pluck(:score).sum : 0.0 + end end if user_score.present? && (user_score > q.question_score) From ab098a3e24d305b9069ee2c7419d0d3331b7f28a Mon Sep 17 00:00:00 2001 From: jasder Date: Sat, 29 Jun 2019 15:04:25 +0800 Subject: [PATCH 2/2] =?UTF-8?q?FIX=20=E8=B5=84=E6=BA=90=E5=88=97=E8=A1=A8?= =?UTF-8?q?=E9=A1=B6=E9=83=A8=E6=95=B0=E9=87=8F=E7=BB=9F=E8=AE=A1=E6=9B=B4?= =?UTF-8?q?=E6=94=B9=E7=AE=97=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/files_controller.rb | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/app/controllers/files_controller.rb b/app/controllers/files_controller.rb index 7e150c44c..c303c7e78 100644 --- a/app/controllers/files_controller.rb +++ b/app/controllers/files_controller.rb @@ -17,25 +17,27 @@ class FilesController < ApplicationController sort_type = params[:sort_type] || 'created_on' # created_on:时间排序, downloads:下载次数排序; quotes: 引用次数排序 course_second_category_id = params[:course_second_category_id] || 0 # 0: 为主目录, 其他为次目录id @user = current_user || nil - @attachments = @course.attachments.by_keywords(params[:search]) + @attachments = @course.attachments.by_course_second_category_id(course_second_category_id) .includes(attachment_group_settings: :course_group, author: [:user_extension, :course_members]) - .by_course_second_category_id(course_second_category_id) .ordered(sort: sort.to_i, sort_type: sort_type.strip) get_category(@course, course_second_category_id) - case @user.course_identity(@course) - when 5 - # 课程学生 - @attachments = @attachments.published - when 6 || 7 - # 非课堂成员 - @attachments = @attachments.publiced.published - end + @attachments = + case @user.course_identity(@course) + when 5 + @attachments.published + when 6, 7 + @attachments.publiced.published + else + @attachments + end @total_count = @attachments.size @public_count = @attachments.publiced.size @private_count = @total_count - @public_count + @attachments = @attachments.by_keywords(params[:search]) + @attachments = @attachments.page(@page).per(@page_size) end