From 5b3752275c33aa6ae3227dc12440c98caf904b45 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Thu, 20 Jun 2019 20:17:26 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E8=AF=BE=E7=A8=8B=E9=A6=96=E9=A1=B5?= =?UTF-8?q?=E6=80=A7=E8=83=BD=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/courses_controller.rb | 11 ++++++----- app/models/course.rb | 2 +- app/views/courses/index.json.jbuilder | 4 ++-- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 65f8f5ff9..e012f34ca 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -54,12 +54,12 @@ class CoursesController < ApplicationController # u.login), s.name from courses c, users u, user_extensions ue, schools s where c.is_delete=0 and # c.tea_id=u.id and u.id=ue.user_id and ue.school_id=s.id") - # @courses = Course.where(is_delete: 0, is_hidden: 0).includes([teacher: :user_extension], :school) + @courses = Course.where(is_delete: 0, is_hidden: 0).includes(:course_modules, :course_members, teacher: [user_extension: :school]) - @courses = Course.where(is_delete: 0, is_hidden: 0).select("courses.id, courses.tea_id, courses.name, courses.exercises_count, courses.polls_count, - courses.is_public, courses.is_end, courses.visits, courses.course_members_count,courses.homework_commons_count,(SELECT MAX(created_at) - FROM `course_activities` WHERE course_activities.course_id = courses.id) AS a") - .order("courses.id = 1309 desc, a desc") + # @courses = Course.where(is_delete: 0, is_hidden: 0).select("courses.id, courses.tea_id, courses.name, courses.exercises_count, courses.polls_count, + # courses.is_public, courses.is_end, courses.visits, courses.course_members_count,courses.homework_commons_count,(SELECT MAX(created_at) + # FROM `course_activities` WHERE course_activities.course_id = courses.id) AS a") + # .order("courses.id = 1309 desc, a desc") elsif @order == "mine" @courses = Course.joins(:course_members) .where("is_delete = 0 AND is_hidden = 0 AND course_members.user_id = ?", @user.id) @@ -103,6 +103,7 @@ class CoursesController < ApplicationController # GET /courses/1 # GET /courses/1.json def show + # render :json => {first_category_url: module_url(course.course_modules.where.not(module_type: "activity").where(hidden: 0).first, course)} end # GET /courses/new diff --git a/app/models/course.rb b/app/models/course.rb index dd2248d7c..1ea9e782e 100644 --- a/app/models/course.rb +++ b/app/models/course.rb @@ -7,7 +7,7 @@ class Course < ApplicationRecord has_many :course_infos, dependent: :destroy # 课堂左侧导航栏的模块 - has_many :course_modules, dependent: :destroy + has_many :course_modules, -> {where hidden: 0}, dependent: :destroy has_many :board_course_modules, -> { board_module }, class_name: "CourseModule" has_many :attachment_course_modules, -> { attachment_module }, class_name: "CourseModule" has_many :common_course_modules, -> { common_homework_module }, class_name: "CourseModule" diff --git a/app/views/courses/index.json.jbuilder b/app/views/courses/index.json.jbuilder index ec9ebfc3f..23e8715af 100644 --- a/app/views/courses/index.json.jbuilder +++ b/app/views/courses/index.json.jbuilder @@ -10,9 +10,9 @@ json.courses do json.tasks_count get_tasks_count course json.visits course.visits json.is_public course.is_public - json.is_accessible @user.present? ? @user.member_of_course?(course) || @user.creator_of_course?(course) : course.is_public == 1 + json.is_accessible course.is_public? ? true : (course.tea_id == @user.id || @user.course_identity(course) < 5) json.is_end course.is_end - json.first_category_url module_url(course.course_modules.where.not(module_type: "activity").where(hidden: 0).order(position: :desc).first, course) + json.first_category_url module_url(course.course_modules.first, course) end end json.courses_count @courses_count From 363f5c67b97a0522874e86350ca1240345caeba2 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Thu, 20 Jun 2019 20:23:42 +0800 Subject: [PATCH 2/2] fix bug --- .../exercise_answers_controller.rb | 23 +++++++++++++++++++ app/helpers/exercises_helper.rb | 8 +++++-- app/helpers/polls_helper.rb | 14 +++++++---- 3 files changed, 39 insertions(+), 6 deletions(-) diff --git a/app/controllers/exercise_answers_controller.rb b/app/controllers/exercise_answers_controller.rb index c709980f9..81f117daf 100644 --- a/app/controllers/exercise_answers_controller.rb +++ b/app/controllers/exercise_answers_controller.rb @@ -1,6 +1,8 @@ class ExerciseAnswersController < ApplicationController before_action :require_login before_action :get_exercise_question + before_action :commit_exercise_time + include ExercisesHelper def create #每一次答案的点击,请求一次,实训题不在这里回答 ActiveRecord::Base.transaction do @@ -31,6 +33,7 @@ class ExerciseAnswersController < ApplicationController end elsif q_type == 1 #多选题的 choice_ids = params[:exercise_choice_id].present? ? params[:exercise_choice_id] : [] + ea_ids = ea.pluck(:exercise_choice_id) common_answer_ids = choice_ids & ea_ids #已经存在的试卷选项id new_ids = choice_ids - common_answer_ids # 新增的id @@ -113,4 +116,24 @@ class ExerciseAnswersController < ApplicationController end end + def commit_exercise_time + @exercise_user_current = @exercise.exercise_users.exercise_commit_users(current_user.id).first #查找当前用户是否有过答题 + if @exercise.exercise_status == 3 || (@exercise.time > 0 && ((@exercise_user_current&.start_at + (@exercise.time.to_i + 1).minutes) < Time.now)) + #当前用户存在,且已回答,且试卷时间已过,且未提交,则自动提交。最好是前端控制 + objective_score = calculate_student_score(@exercise,current_user)[:total_score] + subjective_score = @exercise_user_current&.subjective_score < 0.0 ? 0.0 : @exercise_user_current&.subjective_score + total_score = objective_score + subjective_score + commit_option = { + :status => 1, + :commit_status => 1, + :end_at => Time.now, + :objective_score => objective_score, + :score => total_score, + :subjective_score => subjective_score + } + @exercise_user_current.update_attributes(commit_option) + normal_status(-1,"考试时间已到,已交卷成功!") + end + end + end diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index 4f4c015eb..95ec0ac24 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -478,8 +478,12 @@ module ExercisesHelper ex_user_end_at = ex_user.end_at course_member = course.students.course_find_by_ids("user_id",ex_user.user.id) current_user_group_id = course_member.first.course_group_id if course_member.present? - course_group = course.course_groups.by_group_ids(current_user_group_id) - current_user_group_name = course_group.first.name if course_group.present? + if current_user_group_id == 0 + current_user_group_name = "未分班" + else + course_group = course.course_groups.by_group_ids(current_user_group_id) + current_user_group_name = course_group.first.name if course_group.present? + end teacher_review = ex_user.subjective_score < 0.0 ? false : true if ex_user_exercise_status != 3 || commit_status != 1 #试卷未截止或用户未提交 # if (user_status != 0 && ex_user_exercise_status != 3)|| commit_status == 0 #不为教师,且试卷未截止;当前用户未提交 不显示分数 diff --git a/app/helpers/polls_helper.rb b/app/helpers/polls_helper.rb index 5b4702174..56bbb9b77 100644 --- a/app/helpers/polls_helper.rb +++ b/app/helpers/polls_helper.rb @@ -110,14 +110,20 @@ module PollsHelper poll_user_name = user.nickname end course_member = course_members.find_by(user_id:user.id) - current_user_group_id = course_members.present? ? course_member.course_group_id : nil - course_group = course.course_groups.find_by_id(current_user_group_id) + course_group_id = course_members.present? ? course_member.course_group_id : nil + if course_group_id == 0 + course_group_name = "未分班" + else + course_group = course.course_groups.find_by_id(course_group_id) + course_group_id = course_group&.id + course_group_name = course_group&.name + end { "user_name":poll_user_name, "user_id": user.id, "student_id":user_student_id, - "group_name":course_group.try(:name), - "group_id":course_group.try(:id), + "group_name":course_group_name, + "group_id":course_group_id, "login":user.login } end