Merge branch 'dev_course' of https://bdgit.educoder.net/Hjqreturn/educoder into dev_course

dev_course
daiao 6 years ago
commit 3215cc4a0f

@ -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

@ -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 #不为教师,且试卷未截止;当前用户未提交 不显示分数

@ -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

@ -1,21 +1,21 @@
class MigrateCourseMembers < ActiveRecord::Migration[5.2]
def change
# add_column :course_groups, :position, :integer, default: 0
#
# Course.find_each do |course|
# position = 1
# course.course_groups.reorder("CONVERT(course_groups.name USING gbk) COLLATE gbk_chinese_ci ASC").find_each do |group|
# group.update_attribute(:position, position)
# position += 1
# end
# end
#
#
# add_column :course_groups, :course_members_count, :integer, default: 0
#
# CourseGroup.find_each do |g|
# CourseGroup.reset_counters g.id, :course_members
# end
add_column :course_groups, :position, :integer, default: 0
Course.find_each do |course|
position = 1
course.course_groups.reorder("CONVERT(course_groups.name USING gbk) COLLATE gbk_chinese_ci ASC").find_each do |group|
group.update_attribute(:position, position)
position += 1
end
end
add_column :course_groups, :course_members_count, :integer, default: 0
CourseGroup.find_each do |g|
CourseGroup.reset_counters g.id, :course_members
end
ActiveRecord::Base.transaction do
begin

Loading…
Cancel
Save