dev_course
cxt 5 years ago
parent e3d21286f3
commit 17b8f21a2a

@ -89,7 +89,7 @@ class ExercisesController < ApplicationController
@page = params[:page] || 1
@limit = params[:limit] || 15
@exercises = @exercises.page(@page).per(@limit)
@exercises = @exercises&.includes(:exercise_users,:exercise_questions,:exercise_group_settings)
@exercises = @exercises&.includes(:published_settings)
else
@exercises = []
end
@ -1183,12 +1183,12 @@ class ExercisesController < ApplicationController
ex_common_ids = @exercise.common_published_ids(current_user.id)
@exercise_course_groups = @course.get_ex_published_course(ex_common_ids)
@exercise_users_list = @exercise.all_exercise_users(current_user.id) #当前老师所在班级的全部学生
get_exercise_answers(@exercise_users_list)
get_exercise_answers(@exercise_users_list, @exercise_status)
end
elsif @user_course_identity > Course::ASSISTANT_PROFESSOR #当前为学生或者有过答题的(提交/未提交)
@ex_user_end_time = @exercise.get_exercise_end_time(current_user.id) #当前用户所看到的剩余时间
@exercise_all_users = @exercise.get_stu_exercise_users
get_exercise_answers(@exercise_all_users) # 未答和已答的
get_exercise_answers(@exercise_users_list, @exercise_status) # 未答和已答的
exercise_current_user = @exercise_all_users.exercise_commit_users(current_user.id) #当前用户是否开始做试卷(提交/未提交/没做)
if exercise_current_user.present?
@exercise_current_user_status = 1 #当前用户的状态,为学生
@ -1202,7 +1202,7 @@ class ExercisesController < ApplicationController
end
else
@exercise_all_users = @exercise.get_stu_exercise_users
get_exercise_answers(@exercise_all_users) # 未答和已答的
get_exercise_answers(@exercise_users_list, @exercise_status) # 未答和已答的
@exercise_current_user_status = 2 #当前用户非课堂成员
@exercise_users_list = []
end

@ -250,10 +250,15 @@ module ExercisesHelper
end
#获取试卷的已答/未答人数
def get_exercise_answers(ex_users)
@exercise_answers = ex_users.commit_exercise_by_status(1).size #表示已经提交了的用户
course_all_members_count = ex_users.size
@exercise_unanswers = (course_all_members_count - @exercise_answers)
def get_exercise_answers(ex_users, status)
if status == 1
@exercise_answers = 0
@exercise_unanswers = 0
else
@exercise_answers = ex_users.commit_exercise_by_status(1).size #表示已经提交了的用户
course_all_members_count = ex_users.size
@exercise_unanswers = (course_all_members_count - @exercise_answers)
end
end
def exercise_index_show(exercise,course,is_teacher_or,user)
@ -281,8 +286,8 @@ module ExercisesHelper
if is_teacher_or == 1
exercise_users_list = exercise.all_exercise_users(user.id) #当前老师所在班级的全部学生
unreview_count = exercise_users_list.exercise_unreview.size
get_exercise_answers(exercise_users_list)
unreview_count = exercise_status == 1 ? 0 : exercise_users_list.exercise_unreview.size
get_exercise_answers(exercise_users_list, exercise_status)
ex_pb_time = exercise.get_exercise_times(user.id,true)
exercise_publish_time = ex_pb_time[:publish_time]
exercise_end_time = ex_pb_time[:end_time]
@ -295,8 +300,8 @@ module ExercisesHelper
end
elsif is_teacher_or == 2
exercise_users_list = exercise.get_stu_exercise_users
get_exercise_answers(exercise_users_list) # 未答和已答的
unreview_count = exercise_users_list.exercise_unreview.size
get_exercise_answers(exercise_users_list, exercise_status) # 未答和已答的
unreview_count = exercise_status == 1 ? 0 : exercise_users_list.exercise_unreview.size
ex_pb_time = exercise.get_exercise_times(user.id,false)
exercise_publish_time = ex_pb_time[:publish_time]
exercise_end_time = ex_pb_time[:end_time]
@ -307,7 +312,7 @@ module ExercisesHelper
end
else
exercise_users_list = exercise.get_stu_exercise_users
get_exercise_answers(exercise_users_list) # 未答和已答的
get_exercise_answers(exercise_users_list, exercise_status) # 未答和已答的
exercise_publish_time = exercise.publish_time
exercise_end_time = exercise.end_time
unreview_count = nil

@ -7,6 +7,8 @@ class Exercise < ApplicationRecord
has_many :score_exercise_users, -> { where("is_delete = 0 and commit_status != 0").order("score desc") }, class_name: "ExerciseUser"
has_many :exercise_questions, :dependent => :delete_all
has_many :exercise_group_settings, :dependent => :delete_all
has_many :published_settings, -> { exercise_group_published }, class_name: "ExerciseGroupSetting"
has_many :tidings, as: :container
has_many :course_acts, class_name: 'CourseActivity', as: :course_act, :dependent => :delete_all
@ -41,8 +43,8 @@ class Exercise < ApplicationRecord
exercise_users
else
ex_group_setting_ids = exercise_group_settings.exercise_group_published.pluck(:course_group_id)
course_user_ids = course.students.where(course_group_id:ex_group_setting_ids).pluck(:user_id)
exercise_users.where(user_id:course_user_ids)
exercise_users.joins("join course_members on exercise_users.user_id=course_members.user_id").
where(course_members: {course_group_id: ex_group_setting_ids})
end
end
@ -55,17 +57,38 @@ class Exercise < ApplicationRecord
end
end
#统一设置,为当前老师有权限的分班学生,分班设置,也为当前老师有权限的分班的学生
def all_exercise_users(user_id)
ex_users = exercise_users
group_ids = common_published_ids(user_id)
if group_ids.present?
ex_users = ex_users.joins("join course_members on exercise_users.user_id=course_members.user_id").
# 根据是否统一发布获取作业的作品列表
def all_works
exercise_users = self.unified_setting ? self.exercise_users :
self.exercise_users.joins("join course_members on exercise_users.user_id=course_members.user_id").
where(course_members: {course_group_id: self.published_settings.pluck(:course_group_id)})
end
# 分班权限的老师可见的作品列表
def all_exercise_users user_id
# member = course.course_member(user_id)
teacher_course_groups = course.teacher_course_groups.where(user_id: user_id)
ex_users = self.all_works
# 有分班权限的统计管理的分班且已发布的学生情况
if teacher_course_groups.exists?
group_ids = teacher_course_groups.pluck(:course_group_id)
ex_users = all_student_works.joins("join course_members on student_works.user_id=course_members.user_id").
where(course_members: {course_group_id: group_ids})
end
ex_users
end
# #统一设置,为当前老师有权限的分班学生,分班设置,也为当前老师有权限的分班的学生
# def all_exercise_users(user_id)
# ex_users = exercise_users
# group_ids = common_published_ids(user_id)
# if group_ids.present?
# ex_users = ex_users.joins("join course_members on exercise_users.user_id=course_members.user_id").
# where(course_members: {course_group_id: group_ids})
# end
# ex_users
# end
#当前用户已发布的班级id和试卷分组已发布的班级id的交集
def common_published_ids(user_id)
current_user_groups = course.teacher_course_ids(user_id)

@ -89,7 +89,7 @@ class HomeworkCommon < ApplicationRecord
teacher_course_groups = member.try(:teacher_course_groups)
all_student_works = self.all_works
# 有分班权限的统计管理的分班且已发布的学生情况
if member.present? && teacher_course_groups.size > 0
if member.present? && teacher_course_groups.exists?
group_ids = teacher_course_groups.pluck(:course_group_id)
all_student_works = all_student_works.joins("join course_members on student_works.user_id=course_members.user_id").
where(course_members: {course_group_id: group_ids})

Loading…
Cancel
Save