|
|
|
@ -23,7 +23,6 @@ class ExercisesController < ApplicationController
|
|
|
|
|
before_action :commit_shixun_present,only: [:commit_shixun]
|
|
|
|
|
include ExportHelper
|
|
|
|
|
include ExercisesHelper
|
|
|
|
|
# require 'pdfkit'
|
|
|
|
|
|
|
|
|
|
def index
|
|
|
|
|
ActiveRecord::Base.transaction do
|
|
|
|
@ -43,45 +42,43 @@ class ExercisesController < ApplicationController
|
|
|
|
|
@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 #表示是课堂的未分班成员,只能查看统一设置的试卷(已发布的/已截止的)
|
|
|
|
|
@member_group_id = @current_student.first.try(:course_group_id).to_i # 成员的分班id,默认为0
|
|
|
|
|
if @member_group_id == 0 #表示是课堂的未分班成员,只能查看统一设置的试卷(已发布的/已截止的)
|
|
|
|
|
@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.exists? ?
|
|
|
|
|
member_show_exercises.unified_setting.or(member_show_exercises.where(id: exercise_settings_ids))
|
|
|
|
|
: []
|
|
|
|
|
not_exercise_ids = @course.exercise_group_settings.exercise_group_not_published.where("course_group_id = #{@member_group_id}").pluck(:exercise_id)
|
|
|
|
|
@exercises = member_show_exercises.where.not(id: not_exercise_ids)
|
|
|
|
|
# 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.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.exists? ? member_show_exercises.unified_setting : []
|
|
|
|
|
@exercises = member_show_exercises.unified_setting
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
if @exercises.size > 0
|
|
|
|
|
if params[:type].present?
|
|
|
|
|
choose_type = params[:type].to_i
|
|
|
|
|
member_group_id = @current_student.first.try(:course_group_id).to_i
|
|
|
|
|
if @is_teacher_or == 2 && member_group_id > 0
|
|
|
|
|
exercise_groups_sets = @course.exercise_group_settings.where(course_group_id: member_group_id)
|
|
|
|
|
.exercise_group_published
|
|
|
|
|
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.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.exists? ?
|
|
|
|
|
@exercises_all.exercise_by_status(3).unified_setting
|
|
|
|
|
.or(@exercises_all.where(id: exercise_ended_ids))
|
|
|
|
|
: []
|
|
|
|
|
end
|
|
|
|
|
ex_setting_ids = []
|
|
|
|
|
if @is_teacher_or != 2
|
|
|
|
|
@exercises = @exercises.where("exercise_status = #{choose_type}")
|
|
|
|
|
else
|
|
|
|
|
@exercises = @exercises.exercise_by_status(choose_type)
|
|
|
|
|
case choose_type
|
|
|
|
|
when 1
|
|
|
|
|
ex_setting_ids = @course.exercise_group_settings.where("course_group_id = #{@member_group_id}").exercise_group_not_published.pluck(:exercise_id)
|
|
|
|
|
when 2
|
|
|
|
|
ex_setting_ids = @course.exercise_group_settings.where("course_group_id = #{@member_group_id}")
|
|
|
|
|
.where("publish_time is not null and publish_time <= ? and end_time > ?",Time.now,Time.now).pluck(:exercise_id)
|
|
|
|
|
when 3
|
|
|
|
|
ex_setting_ids = @course.exercise_group_settings.where("course_group_id = #{@member_group_id}").exercise_group_ended.pluck(:exercise_id)
|
|
|
|
|
end
|
|
|
|
|
unified_setting_ids = @exercises.unified_setting.where("exercise_status = #{choose_type}").pluck(:id)
|
|
|
|
|
ex_ids = (ex_setting_ids + unified_setting_ids).uniq
|
|
|
|
|
@exercises = @exercises.where(id: ex_ids)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
@ -1302,9 +1299,11 @@ class ExercisesController < ApplicationController
|
|
|
|
|
respond_to do |format|
|
|
|
|
|
format.xlsx{
|
|
|
|
|
get_export_users(@exercise,@course,@export_ex_users)
|
|
|
|
|
exercise_export_name =
|
|
|
|
|
"#{current_user.real_name}_#{@course.name}_#{@exercise.exercise_name}_#{Time.now.strftime('%Y%m%d_%H%M%S')}"
|
|
|
|
|
render xlsx: "#{exercise_export_name.strip.first(30)}",template: "exercises/exercise_lists.xlsx.axlsx",locals: {table_columns:@table_columns,exercise_users:@user_columns}
|
|
|
|
|
exercise_export_name_ =
|
|
|
|
|
"#{current_user.real_name}_#{@course.name}_#{@exercise.exercise_name}"
|
|
|
|
|
exercise_export_name = Base64.urlsafe_encode64(exercise_export_name_.strip.first(30))
|
|
|
|
|
|
|
|
|
|
render xlsx: "#{exercise_export_name}",template: "exercises/exercise_lists.xlsx.axlsx",locals: {table_columns:@table_columns,exercise_users:@user_columns}
|
|
|
|
|
}
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
@ -1321,7 +1320,8 @@ class ExercisesController < ApplicationController
|
|
|
|
|
def export_exercise
|
|
|
|
|
@request_url = request.base_url
|
|
|
|
|
@exercise_questions = @exercise.exercise_questions.includes(:exercise_choices).order("question_number ASC")
|
|
|
|
|
filename = "#{@exercise.user.real_name}_#{@exercise.exercise_name}_#{Time.current.strftime('%Y%m%d_%H%M')}.pdf"
|
|
|
|
|
filename_ = "#{@exercise.user.real_name}_#{@exercise.exercise_name}"
|
|
|
|
|
filename = Base64.urlsafe_encode64(filename_.strip.first(30))
|
|
|
|
|
stylesheets = "#{Rails.root}/app/templates/exercise_export/exercise_export.css"
|
|
|
|
|
render pdf: 'exercise_export/blank_exercise', filename: filename, stylesheets: stylesheets
|
|
|
|
|
end
|
|
|
|
|