|
|
|
@ -32,38 +32,34 @@ class ExercisesController < ApplicationController
|
|
|
|
|
@exercises_all = @course.exercises
|
|
|
|
|
member_show_exercises = @exercises_all.is_exercise_published #已发布的或已截止的试卷
|
|
|
|
|
@current_user_ = current_user
|
|
|
|
|
@exercises_count = @exercises_all.size # 全部页面,需返回
|
|
|
|
|
@exercises_unpublish_counts = @exercises_all.exercise_by_status(1).size #未发布的试卷数
|
|
|
|
|
@exercises_published_counts = @exercises_all.exercise_by_status([2,3]).size # 已发布的试卷数,包含已截止的
|
|
|
|
|
@exercises_ended_counts = @exercises_all.exercise_by_status(3).size #已截止的试卷数
|
|
|
|
|
|
|
|
|
|
# 课堂的学生人数
|
|
|
|
|
@course_all_members = @course.students #当前课堂的全部学生
|
|
|
|
|
@course_all_members_count = @course_all_members.size #当前课堂的学生数
|
|
|
|
|
@current_student = @course_all_members.course_find_by_ids("user_id",current_user.id) #当前用户是否为课堂的学生
|
|
|
|
|
|
|
|
|
|
# exercises的不同用户群体的显示
|
|
|
|
|
if @user_course_identity < Course::STUDENT # @is_teacher_or 1为老师/管理员/助教
|
|
|
|
|
@is_teacher_or = 1
|
|
|
|
|
# @teacher_groups_ids = @course.teacher_course_groups.get_user_groups(current_user.id).pluck(:course_group_id).reject(&:blank?)
|
|
|
|
|
@exercises = @exercises_all #老师能看到全部的试卷,不管是已发布的/未发布的/已截止的/统一设置的/私有设置的(看到内容不同)
|
|
|
|
|
elsif @user_course_identity == Course::STUDENT # 2为课堂成员,能看到统一设置的和自己班级的
|
|
|
|
|
@is_teacher_or = 2
|
|
|
|
|
# get_exercise_left_time(@exercise,current_user)
|
|
|
|
|
member_group_id = @current_student.first.try(:course_group_id).to_i # 成员的分班id,默认为0
|
|
|
|
|
if member_group_id == 0 #表示是课堂的未分班成员,只能查看统一设置的试卷(已发布的/已截止的)
|
|
|
|
|
@exercises = member_show_exercises.present? ? member_show_exercises.unified_setting : []
|
|
|
|
|
@exercises = member_show_exercises.exists? ? member_show_exercises.unified_setting : []
|
|
|
|
|
else #已分班级的成员,可以查看统一设置和单独设置(试卷是发布在该班级)试卷
|
|
|
|
|
# 已发布 当前用户班级分组的 试卷id
|
|
|
|
|
exercise_settings_ids = @course.exercise_group_settings.exercise_group_published
|
|
|
|
|
.where(course_group_id: member_group_id).pluck(:exercise_id).uniq
|
|
|
|
|
@exercises = member_show_exercises.present? ?
|
|
|
|
|
@exercises = member_show_exercises.exists? ?
|
|
|
|
|
member_show_exercises.unified_setting.or(member_show_exercises.where(id: exercise_settings_ids))
|
|
|
|
|
: []
|
|
|
|
|
end
|
|
|
|
|
else #用户未登陆或不是该课堂成员,仅显示统一设置的(已发布的/已截止的),如有公开,则不显示锁,不公开,则显示锁
|
|
|
|
|
@is_teacher_or = 0
|
|
|
|
|
@exercises = member_show_exercises.present? ? member_show_exercises.unified_setting : []
|
|
|
|
|
@exercises = member_show_exercises.exists? ? member_show_exercises.unified_setting : []
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
if @exercises.size > 0
|
|
|
|
|
if params[:type].present?
|
|
|
|
|
choose_type = params[:type].to_i
|
|
|
|
@ -74,12 +70,12 @@ class ExercisesController < ApplicationController
|
|
|
|
|
exercise_settings_ids = exercise_groups_sets.pluck(:exercise_id)
|
|
|
|
|
exercise_ended_ids = exercise_groups_sets.exercise_group_ended.pluck(:exercise_id).uniq
|
|
|
|
|
if choose_type == 2
|
|
|
|
|
@exercises = @exercises_all.present? ?
|
|
|
|
|
@exercises = @exercises_all.exists? ?
|
|
|
|
|
@exercises_all.exercise_by_status(2).unified_setting
|
|
|
|
|
.or(@exercises_all.where(id: (exercise_settings_ids - exercise_ended_ids).uniq))
|
|
|
|
|
: []
|
|
|
|
|
elsif choose_type == 3
|
|
|
|
|
@exercises = @exercises_all.present? ?
|
|
|
|
|
@exercises = @exercises_all.exists? ?
|
|
|
|
|
@exercises_all.exercise_by_status(3).unified_setting
|
|
|
|
|
.or(@exercises_all.where(id: exercise_ended_ids))
|
|
|
|
|
: []
|
|
|
|
@ -106,6 +102,11 @@ class ExercisesController < ApplicationController
|
|
|
|
|
@exercises = []
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
@course_all_members_count = @course_all_members.size #当前课堂的学生数
|
|
|
|
|
@exercises_count = @exercises_all.size # 全部页面,需返回
|
|
|
|
|
@exercises_unpublish_counts = @exercises_all.exercise_by_status(1).size #未发布的试卷数
|
|
|
|
|
@exercises_published_counts = @exercises_count - @exercises_unpublish_counts # 已发布的试卷数,包含已截止的
|
|
|
|
|
|
|
|
|
|
rescue Exception => e
|
|
|
|
|
uid_logger_error(e.message)
|
|
|
|
|
tip_exception(e.message)
|
|
|
|
|