diff --git a/app/controllers/exercise_answers_controller.rb b/app/controllers/exercise_answers_controller.rb index cad482390..aa3966d25 100644 --- a/app/controllers/exercise_answers_controller.rb +++ b/app/controllers/exercise_answers_controller.rb @@ -97,7 +97,7 @@ class ExerciseAnswersController < ApplicationController @exercise = @exercise_question&.exercise @course = @exercise&.course @exercise_user = @exercise&.exercise_users.find_by(user_id: current_user.id) #当前用户 - @exercise_user_status = @exercise.get_exercise_status(current_user.id) + @exercise_user_status = @exercise.get_exercise_status(current_user) if @exercise_question.blank? normal_status(-1,"试卷问题不存在!") diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index 30cc51dc2..ea424a411 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -49,11 +49,6 @@ class ExercisesController < ApplicationController # 已发布 当前用户班级分组的 试卷id 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 @@ -210,7 +205,7 @@ class ExercisesController < ApplicationController @user_exercise_answer = 3 #教师页面 @user_commit_counts = @exercise.exercise_users.where(commit_status:1).count #已提交的用户数 end - @ex_status = @exercise.get_exercise_status(current_user.id) + @ex_status = @exercise.get_exercise_status(current_user) exercise_id_array = [@exercise.id] @exercise_publish_count = get_user_permission_course(exercise_id_array,2).count #是否存在已发布的 @@ -448,7 +443,7 @@ class ExercisesController < ApplicationController # course_group_ids = @course.teacher_course_group_ids(current_user.id) #当前老师的班级id数组 course_group_ids = @course.charge_group_ids(current_user) #当前老师的班级id数组 - exercise_status = @exercise.get_exercise_status(current_user.id) + exercise_status = @exercise.get_exercise_status(current_user) if exercise_status == 1 && course_group_ids.size > 0 # 试卷未发布,且老师的分班大于1 ,才可以修改统一设置,否则按试卷默认的来处理 unified_setting = params[:unified_setting] @@ -802,7 +797,7 @@ class ExercisesController < ApplicationController check_ids = Exercise.where(id:params[:check_ids]) course_students = @course.students #课堂的全部学生数 check_ids.each do |exercise| - exercise_status= exercise.get_exercise_status(current_user.id) + exercise_status= exercise.get_exercise_status(current_user) if exercise_status == 2 #跳过已截止的或未发布的 g_course = params[:group_ids] if g_course.present? @@ -897,7 +892,7 @@ class ExercisesController < ApplicationController ex_question_ids = @exercise.exercise_questions.pluck(:id) exercise_user = @exercise.exercise_users.exercise_commit_users(current_user.id).first if exercise_user.present? - if exercise_user.commit_status == 1 && @exercise.get_exercise_status(current_user.id) == 2 #用户已提交且试卷提交中 + if exercise_user.commit_status == 1 && @exercise.get_exercise_status(current_user) == 2 #用户已提交且试卷提交中 if @exercise.time == -1 || ((Time.now.to_i - exercise_user.start_at.to_i) < @exercise.time.to_i * 60) exercise_user.update_attributes(:score => nil, :end_at => nil, :status => nil, :commit_status => 0, :objective_score => 0.0, :subjective_score => -1.0) @@ -1024,7 +1019,7 @@ class ExercisesController < ApplicationController # @user_left_time = (time_mill < exercise_user_left_time) ? nil : (time_mill - exercise_user_left_time) #当前用户对试卷的回答剩余时间 # end - @t_user_exercise_status = @exercise.get_exercise_status(current_user.id) + @t_user_exercise_status = @exercise.get_exercise_status(current_user) @user_left_time = nil if @user_course_identity < Course::STUDENT || (@t_user_exercise_status == 3) || @@ -1137,7 +1132,7 @@ class ExercisesController < ApplicationController # @exercise_answerer = User.find_by(id:@exercise_current_user_id) #试卷回答者 @exercise_questions = @exercise.exercise_questions.order("question_number ASC") @question_status = [] - get_exercise_status = @exercise.get_exercise_status(current_user.id) + get_exercise_status = @exercise.get_exercise_status(current_user) if @ex_user.present? && @is_teacher_or == 0 if get_exercise_status == 2 #当前用户已提交,且试卷未截止 if @ex_user.commit_status == 0 #学生未提交,且当前为学生 @@ -1165,7 +1160,7 @@ class ExercisesController < ApplicationController begin @current_user_id = current_user.id exercise_ids = [@exercise.id] - @exercise_status = @exercise.get_exercise_status(current_user.id) + @exercise_status = @exercise.get_exercise_status(current_user) @course_all_members = @course.students @c_group_counts = @course.course_groups_count question_types = @exercise.exercise_questions.pluck(:question_type).uniq @@ -1370,7 +1365,7 @@ class ExercisesController < ApplicationController @exercise_commit_users = @exercise_all_users.commit_exercise_by_status(1) #试卷的已提交用户 @exercise_commit_user_ids = @exercise_commit_users.pluck(:user_id).uniq #已提交试卷的全部用户id @exercise_commit_user_counts = @exercise_commit_users.count #试卷的已提交用户人数 - @exercise_status = @exercise.get_exercise_status(current_user.id) + @exercise_status = @exercise.get_exercise_status(current_user) #提交率 if @course_all_members_count == 0 @@ -1552,7 +1547,7 @@ class ExercisesController < ApplicationController exercises_all.each do |exercise| if exercise.present? if exercise.unified_setting #统一设置只有两种情况,全部发布,全部截止 - exercise_user_status = exercise.get_exercise_status(current_user.id) #当前用户的能看到的试卷 + exercise_user_status = exercise.get_exercise_status(current_user) #当前用户的能看到的试卷 if exercise_user_status == exercise_status || exercise_status == 3 #未发布的情况 unpublish_group = unpublish_group + user_groups_id else @@ -1622,7 +1617,7 @@ class ExercisesController < ApplicationController ## 判断开始答题页面的用户权限 def check_user_on_answer - if @user_course_identity == Course::STUDENT && @exercise.get_exercise_status(current_user.id) == 1 #试卷未发布,且当前用户不为老师/管理员 + if @user_course_identity == Course::STUDENT && @exercise.get_exercise_status(current_user) == 1 #试卷未发布,且当前用户不为老师/管理员 normal_status(-1, "未发布试卷!") elsif @user_course_identity > Course::STUDENT && (!@exercise.is_public || (@exercise.is_public && !@exercise.unified_setting)) ##不为课堂成员,且试卷不为公开的,或试卷公开,但不是统一设置的 normal_status(-1, "试卷暂未公开!") @@ -1639,7 +1634,7 @@ class ExercisesController < ApplicationController #打回重做时的初步判断 def check_exercise_status @exercise_users = @exercise.all_exercise_users(current_user.id).commit_exercise_by_status(1) #当前教师所在分班的全部已提交的学生数 - if @exercise.get_exercise_status(current_user.id) != 2 + if @exercise.get_exercise_status(current_user) != 2 normal_status(-1,"非提交中的试卷不允许打回重做!") elsif @exercise_users.count < 1 normal_status(-1,"暂无人提交试卷!") @@ -1649,7 +1644,7 @@ class ExercisesController < ApplicationController #查看试题页面,当为学生时,除非试卷已截止,或已提交才可以查看 def check_exercise_is_end - ex_status = @exercise.get_exercise_status(current_user.id) + ex_status = @exercise.get_exercise_status(current_user) @ex_user = @exercise.exercise_users.find_by(user_id:@exercise_current_user_id) #该试卷的回答者 if @user_course_identity > Course::ASSISTANT_PROFESSOR if ex_status == 1 @@ -1666,7 +1661,7 @@ class ExercisesController < ApplicationController def check_exercise_public if @user_course_identity > Course::ASSISTANT_PROFESSOR #当前为学生,试卷公开统计,且已截止,且已提交 ex_user = @exercise.exercise_users.exercise_commit_users(current_user.id).first - unless @exercise.get_exercise_status(current_user.id) == 3 && ex_user.present? && ex_user.commit_status == 1 && + unless @exercise.get_exercise_status(current_user) == 3 && ex_user.present? && ex_user.commit_status == 1 && @exercise.show_statistic normal_status(-1,"学生暂不能查看") end diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index d6a000ffa..5f93bc36b 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -539,7 +539,7 @@ class GamesController < ApplicationController # 编程题评测 def game_build sec_key = params[:sec_key] - game_challenge = Challenge.select([:id, :position, :picture_path]).find(@game.challenge_id) + game_challenge = Challenge.select([:id, :position, :picture_path, :exec_time]).find(@game.challenge_id) # 更新评测次数 @game.update_column(:evaluate_count, (@game.evaluate_count.to_i + 1)) @@ -587,7 +587,7 @@ class GamesController < ApplicationController :times => params[:first].to_i, :podType => @shixun.webssh, :content_modified => content_modified, :containers => "#{Base64.urlsafe_encode64(shixun_container_limit(@shixun))}", :persistenceName => @shixun.identifier, :tpmScript => "#{tpmScript}", :sec_key => sec_key, - :timeLimit => "#{@shixun.exec_time}", :isPublished => (@shixun.status < 2 ? 0 : 1) } + :timeLimit => "#{game_challenge.exec_time}", :isPublished => (@shixun.status < 2 ? 0 : 1) } # 评测有文件输出的需要特殊传字段 path:表示文件存储的位置 br_params['file'] = Base64.urlsafe_encode64({path: "#{game_challenge.picture_path}"}.to_json) if game_challenge.picture_path.present? diff --git a/app/controllers/poll_votes_controller.rb b/app/controllers/poll_votes_controller.rb index f1da3a1b2..c11248054 100644 --- a/app/controllers/poll_votes_controller.rb +++ b/app/controllers/poll_votes_controller.rb @@ -134,7 +134,7 @@ class PollVotesController < ApplicationController end def check_answer_in_question - poll_user_status = @poll.get_poll_status(current_user.id) + poll_user_status = @poll.get_poll_status(current_user) poll_user = @poll.poll_users.find_by(user_id: current_user.id) #当前用户 question_type = @poll_question&.question_type diff --git a/app/controllers/polls_controller.rb b/app/controllers/polls_controller.rb index d94299454..fa8d7dd8c 100644 --- a/app/controllers/polls_controller.rb +++ b/app/controllers/polls_controller.rb @@ -31,50 +31,48 @@ class PollsController < ApplicationController @current_user_ = current_user @course_status = @course.is_end ? 0 : 1 # 课堂是否结束 @course_is_public = @course.is_public - @polls_count = @polls_all.count # 全部页面,需返回 - @polls_unpublish_counts = @polls_all.poll_by_status(1).count #未发布的问卷数 - @polls_published_counts = @polls_all.poll_by_status([2, 3]).count # 已发布的问卷数 # 课堂的学生人数 @course_all_members = @course.students #当前课堂的全部学生 - @course_all_members_count = @course_all_members.count #当前课堂的学生数 @current_student = @course_all_members.find_by(user_id: current_user.id) #当前用户是否为课堂的学生 - # polls的不同用户群体的显示 if @user_course_identity < Course::STUDENT # @is_teacher_or 1为老师/管理员/助教 @is_teacher_or = 1 - @teacher_groups_ids = @course.charge_group_ids(current_user) @polls = @polls_all #老师能看到全部的问卷,不管是已发布的/未发布的/已截止的/统一设置的/私有设置的(看到内容不同) elsif @user_course_identity == Course::STUDENT # 2为课堂成员,能看到统一设置的和自己班级的 @is_teacher_or = 2 - member_group_id = @current_student.try(:course_group_id).to_i # 成员的分班id,默认为0 - if member_group_id == 0 #表示是课堂的未分班成员,只能查看统一设置的试卷(已发布的/已截止的) + @member_group_id = @current_student.try(:course_group_id).to_i # 成员的分班id,默认为0 + if @member_group_id == 0 #表示是课堂的未分班成员,只能查看统一设置的试卷(已发布的/已截止的) @polls = member_show_polls.size > 0 ? member_show_polls.public_or_unset : [] else #已分班级的成员,可以查看统一设置和单独设置(试卷是发布在该班级)试卷 # 已发布 当前用户班级分组的 试卷id - poll_settings_ids = @course.poll_group_settings.where(course_group_id: member_group_id).poll_group_published.pluck(:poll_id).uniq # 选择成员的班级id等于课堂问卷设置的班级id - @polls = member_show_polls.present? ? member_show_polls.public_or_unset.or(member_show_polls.where(id: poll_settings_ids)) : [] + not_poll_ids = @course.poll_group_settings.poll_group_not_published.where("course_group_id = #{@member_group_id}").pluck(:poll_id) + @polls = member_show_polls.where.not(id: not_poll_ids) end else #用户未登陆或不是该课堂成员,仅显示统一设置的(已发布的/已截止的),如有公开,则不显示锁,不公开,则显示锁 @is_teacher_or = 0 - @polls = member_show_polls.size > 0 ? member_show_polls.public_or_unset : [] + @polls = member_show_polls.public_or_unset end + if @polls.count > 0 if params[:type].present? choose_type = params[:type] - member_group_id = @current_student.try(:course_group_id).to_i # 成员的分班id,默认为0 - if @is_teacher_or == 2 && member_group_id > 0 - poll_groups_sets = @course.poll_group_settings.where(course_group_id: member_group_id).poll_group_published - poll_settings_ids = poll_groups_sets.pluck(:poll_id) - poll_ended_ids = poll_groups_sets.poll_group_ended.pluck(:poll_id).uniq - # poll_settings_ids = @course.poll_group_settings.where(course_group_id: member_group_id).poll_group_ended.pluck(:poll_id).uniq - if choose_type.to_i == 2 - @polls = @polls_all.present? ? @polls_all.poll_by_status(2).public_or_unset.or(@polls_all.where(id:(poll_settings_ids - poll_ended_ids).uniq)).distinct : [] - elsif choose_type.to_i == 3 - @polls = @polls_all.present? ? @polls_all.poll_by_status(3).public_or_unset.or(@polls_all.where(id: poll_ended_ids)).distinct : [] - end + poll_setting_ids = [] + if @is_teacher_or != 2 + @polls = @polls.where("polls_status = #{choose_type}") else - @polls = @polls.poll_by_status(choose_type) + case choose_type + when 1 + poll_setting_ids = @course.poll_group_settings.where("course_group_id = #{@member_group_id}").poll_group_not_published.pluck(:poll_id) + when 2 + poll_setting_ids = @course.poll_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(:poll_id) + when 3 + poll_setting_ids = @course.poll_group_settings.where("course_group_id = #{@member_group_id}").poll_group_ended.pluck(:poll_id) + end + unified_setting_ids = @polls.public_or_unset.where("polls_status = #{choose_type}").pluck(:id) + ex_ids = (poll_setting_ids + unified_setting_ids).uniq + @polls = @polls.where(id: ex_ids) end end @@ -91,10 +89,15 @@ class PollsController < ApplicationController @polls = @polls.page(@page).per(@limit) @polls = @polls&.includes(:poll_users,:poll_questions,:poll_group_settings) - else @polls = [] end + + @polls_count = @polls_all.size # 全部页面,需返回 + @polls_unpublish_counts = @polls_all.poll_by_status(1).size #未发布的问卷数 + @polls_published_counts = @polls_count - @polls_unpublish_counts # 已发布的问卷数 + @course_all_members_count = @course_all_members.size #当前课堂的学生数 + rescue Exception => e uid_logger_error(e.message) tip_exception(e.message) @@ -202,7 +205,7 @@ class PollsController < ApplicationController @is_teacher_or = 1 @user_poll_answer = 3 #教师页面 end - poll_status = @poll.get_poll_status(current_user.id) + poll_status = @poll.get_poll_status(current_user) poll_id_array = [@poll.id] @poll_publish_count = get_user_permission_course(poll_id_array,2).count #是否存在已发布的 @poll_unpublish_count = get_user_permission_course(poll_id_array,1).count #是否存在未发布的 @@ -344,7 +347,7 @@ class PollsController < ApplicationController begin check_ids = Poll.where(id: params[:check_ids]) check_ids.each do |poll| - poll_status = poll.get_poll_status(current_user.id) + poll_status = poll.get_poll_status(current_user) if poll_status == 2 #跳过已截止的或未发布的 g_course = params[:group_ids] #表示是否传入分班参数,如果传入分班的参数,那么poll的统一设置需修改,poll_group_settings if g_course @@ -687,7 +690,7 @@ class PollsController < ApplicationController course_group_ids = @course.charge_group_ids(current_user) #当前老师的班级id数组 - poll_status = @poll.get_poll_status(current_user.id) + poll_status = @poll.get_poll_status(current_user) if poll_status == 1 && course_group_ids.size > 0 # 问卷未发布,且老师的分班大于1 ,才可以修改统一设置,否则按poll默认的来处理 unified_setting = params[:unified_setting] else @@ -847,7 +850,7 @@ class PollsController < ApplicationController ActiveRecord::Base.transaction do begin poll_user_current = @poll.poll_users.find_by_group_ids(@poll_current_user_id).first #查找当前用户是否有过答题 - @poll_status = @poll.get_poll_status(current_user.id) + @poll_status = @poll.get_poll_status(current_user) if poll_user_current.blank? if @user_course_identity > Course::ASSISTANT_PROFESSOR #当为老师的时候,不创建poll_user表,理论上老师是不能进入答题的 poll_user_params = { @@ -955,7 +958,7 @@ class PollsController < ApplicationController ActiveRecord::Base.transaction do begin poll_ids = [@poll.id] - @poll_list_status = @poll.get_poll_status(current_user.id) + @poll_list_status = @poll.get_poll_status(current_user) @poll_publish_count = get_user_permission_course(poll_ids,2).count @poll_unpublish_count = get_user_permission_course(poll_ids,1).count @course_all_members = @course.students @@ -1103,7 +1106,7 @@ class PollsController < ApplicationController ## 判断开始答题页面的用户权限 def check_user_on_answer - poll_status = @poll.get_poll_status(current_user.id) + poll_status = @poll.get_poll_status(current_user) if @user_course_identity == Course::STUDENT && poll_status == 1 #问卷未发布,且当前用户不为老师/管理员 normal_status(-1, "未发布问卷!") elsif @user_course_identity > Course::STUDENT && (!@poll.is_public || (@poll.is_public && !@poll.unified_setting)) ##不为课堂成员,且问卷不为公开的,或问卷公开,但是不是统一设置的 @@ -1160,7 +1163,7 @@ class PollsController < ApplicationController def check_poll_question_complete #commit_poll 的权限 poll_user_current = @poll.poll_users.find_by_group_ids(current_user.id).first - poll_status = @poll.get_poll_status(current_user.id) + poll_status = @poll.get_poll_status(current_user) if @user_course_identity < Course::STUDENT || (poll_status == 3) || (poll_user_current.present? && poll_user_current.commit_status == 1) normal_status(-1,"用户没有权限!") #老师/管理员在提交时没有权限 else @@ -1182,7 +1185,7 @@ class PollsController < ApplicationController end def check_poll_commit_result - poll_status = @poll.get_poll_status(current_user.id) + poll_status = @poll.get_poll_status(current_user) commit_poll_user = @poll.poll_users.find_by_group_ids(current_user.id).commit_by_status(1) #当前用户已提交问卷的 unless (@user_course_identity < Course::STUDENT) || ((@poll.show_result == 1) && (poll_status == 3) && commit_poll_user.present?) normal_status(-1,"没有权限!") #当前为老师/问卷公开统计,且问卷已截止,且用户有过回答的 @@ -1214,18 +1217,12 @@ class PollsController < ApplicationController def get_user_permission_course(poll_ids,status) #获取用户权限范围内的已发布/未发布 poll_status = status.to_i unpublish_group = [] - # g_course_ids = @course.teacher_course_groups.get_user_groups(current_user.id).pluck(:course_group_id).reject(&:blank?).uniq - # if g_course_ids.blank? || g_course_ids.include?(0) #当前用户的分班权限为空,即具体全部的分班权限 - # user_groups_id = @course.course_groups.pluck(:id) - # else - # user_groups_id = g_course_ids - # end user_groups_id = @course.charge_group_ids(current_user) all_polls = Poll.where(id:poll_ids) all_polls.each do |poll| if poll.present? if poll.unified_setting - poll_user_status = poll.get_poll_status(current_user.id) #当前用户的能看到的试卷 + poll_user_status = poll.get_poll_status(current_user) #当前用户的能看到的试卷 if poll_user_status == poll_status || poll_status == 3 #未发布的情况 unpublish_group = unpublish_group + user_groups_id else diff --git a/app/controllers/zips_controller.rb b/app/controllers/zips_controller.rb index 2d21237f5..e8a2874dd 100644 --- a/app/controllers/zips_controller.rb +++ b/app/controllers/zips_controller.rb @@ -42,7 +42,7 @@ class ZipsController < ApplicationController ActiveRecord::Base.transaction do begin @exercise = Exercise.includes(:exercise_users,:exercise_questions).find_by(id:params[:exercise_id]) - @exercise_status = @exercise.present? ? @exercise.get_exercise_status(current_user.id) : 1 + @exercise_status = @exercise.present? ? @exercise.get_exercise_status(current_user) : 1 group_id = params[:exercise_group_id] if @exercise.blank? normal_status(-1,"试卷不存在") diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index 8174d1eea..ca2f6d47c 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -252,7 +252,7 @@ module ExercisesHelper #获取试卷的已答/未答人数 def get_exercise_answers(ex_users) @exercise_answers = ex_users.commit_exercise_by_status(1).size #表示已经提交了的用户 - course_all_members_count = ex_users.exists? ? ex_users.size : 0 + course_all_members_count = ex_users.size @exercise_unanswers = (course_all_members_count - @exercise_answers) end @@ -266,7 +266,7 @@ module ExercisesHelper elsif is_teacher_or == 1 #当前为老师的时候,显示的是老师身份的对应试卷的状态,因为该试卷,可能对应老师的多个分班 exercise_status = exercise.exercise_status else - exercise_status = exercise.get_exercise_status(user.id) #当前用户查看的试卷的发布状态 + exercise_status = exercise.get_exercise_status(user) #当前用户查看的试卷的发布状态 end case exercise_status @@ -509,7 +509,7 @@ module ExercisesHelper ex_user_user = ex_user.user exercise_user_name = ex_user_user.real_name exercise_user_id = ex_user_user.id - ex_user_exercise_status = exercise.get_exercise_status(exercise_user_id) + ex_user_exercise_status = exercise.get_exercise_status(ex_user_user) ex_user_student_id = ex_user_user.student_id if ex_user.start_at.present? && ex_user.commit_status == 0 #用户已回答,但未提交 commit_status = 2 #继续答题 diff --git a/app/helpers/polls_helper.rb b/app/helpers/polls_helper.rb index aee95eef7..54a9fe1f0 100644 --- a/app/helpers/polls_helper.rb +++ b/app/helpers/polls_helper.rb @@ -2,9 +2,8 @@ module PollsHelper #获取试卷的已答/未答人数 def get_poll_answers(poll_users) - @commit_poll_users = poll_users.commit_by_status(1) #当前老师的全部学生中已提交的 - @poll_answers = @commit_poll_users.present? ? @commit_poll_users.size : 0 #表示已经提交了的用户 - course_all_members_count = poll_users.present? ? poll_users.size : 0 + @poll_answers = poll_users.commit_by_status(1).size #表示已经提交了的用户 + course_all_members_count = poll_users.size @poll_unanswers = (course_all_members_count - @poll_answers) end @@ -55,7 +54,7 @@ module PollsHelper #当前为老师(非课堂成员、统一设置)的时候,显示的是老师身份的对应试卷的状态,因为该试卷,可能对应老师的多个分班 poll_status = poll.polls_status else - poll_status = poll.get_poll_status(user.id) #当前用户查看的试卷的发布状态 + poll_status = poll.get_poll_status(user) #当前用户查看的试卷的发布状态 end if is_teacher_or == 1 diff --git a/app/models/course.rb b/app/models/course.rb index 7729a2650..f61ff1e2a 100644 --- a/app/models/course.rb +++ b/app/models/course.rb @@ -124,7 +124,7 @@ class Course < ApplicationRecord #当前老师的班级id def teacher_course_ids(user_id) - course_teacher_member = teacher_course_groups.get_user_groups(user_id) #获取当前老师的分班 + course_teacher_member = teacher_course_groups.get_user_groups(user_id).select(:course_group_id) #获取当前老师的分班 if course_teacher_member.blank? if none_group_count > 0 #有未分班的,则发布到未发布分班 un_group_ids = [0] diff --git a/app/models/exercise.rb b/app/models/exercise.rb index bc5424b6e..150988a49 100644 --- a/app/models/exercise.rb +++ b/app/models/exercise.rb @@ -57,10 +57,10 @@ class Exercise < ApplicationRecord #统一设置,为当前老师有权限的分班学生,分班设置,也为当前老师有权限的分班的学生 def all_exercise_users(user_id) - ex_users = self.exercise_users + ex_users = exercise_users group_ids = common_published_ids(user_id) if group_ids.present? - ex_users = ex_users.where(user_id: course.students.where(course_group_id: group_ids).pluck(:user_id)) + ex_users = ex_users.where(user_id: course.students.where(course_group_id: group_ids).select(:user_id).pluck(:user_id)) end ex_users end @@ -72,7 +72,7 @@ class Exercise < ApplicationRecord un_group_ids = (course.none_group_count > 0) ? [0] : [] published_group_ids = (current_user_groups + un_group_ids).uniq #统一设置时,为当前用户的分班id及未分班 else - ex_group_setting = exercise_group_settings.pluck("course_group_id").uniq + ex_group_setting = exercise_group_settings.select(:course_group_id).pluck("course_group_id").uniq common_all_ids = ex_group_setting & current_user_groups #当前用户有权限的已发布的分班id #非统一设置时,为当前用户有权限的且已发布分班的id published_group_ids = common_all_ids.uniq end @@ -89,11 +89,9 @@ class Exercise < ApplicationRecord end #判断是否为分班,如果分班,试卷的截止时间为当前分班时间,否则为试卷的截止时间 - def get_exercise_status(user_id) - user_group = course.course_members.find_by(user_id: user_id) - if user_group.present? && user_group.role == "STUDENT" #当为学生的时候,需根据分班来判断试卷状态 + def get_exercise_status(user) + if user.student_of_course?(course) #当为学生的时候,需根据分班来判断试卷状态 ex_time = get_exercise_times(user_id,false) - pb_time = ex_time[:publish_time] ed_time = ex_time[:end_time] @@ -115,18 +113,17 @@ class Exercise < ApplicationRecord if unified_setting || teacher #当试卷为统一设置或当前为老师的时候 pb_time = publish_time en_time = end_time - - if en_time.present? && (en_time <= Time.now) && (exercise_status != 3) + if (exercise_status != 3) && en_time.present? && (en_time <= Time.now) update_column("exercise_status",3) end else ex_group_setting = exercise_group_settings - user_group = course.students.course_find_by_ids("user_id",user_id) + user_group = course.students.where(user_id:user_id).select(:course_group_id) if user_group.exists? - user_group_id = user_group.first.course_group_id - user_ex_group_setting = ex_group_setting.find_in_exercise_group("course_group_id",user_group_id) - pb_time = user_ex_group_setting.exists? ? user_ex_group_setting.first.publish_time : nil - en_time = user_ex_group_setting.exists? ? user_ex_group_setting.first.end_time : nil + user_group_id = user_group.first&.course_group_id + user_ex_group_setting = ex_group_setting.where(course_group_id:user_group_id).select(:publish_time,:end_time) + pb_time = user_ex_group_setting.first&.publish_time + en_time = user_ex_group_setting.first&.end_time else pb_time = nil en_time = nil @@ -141,13 +138,13 @@ class Exercise < ApplicationRecord #判断当前用户的答题状态 def check_user_answer_status(user) - ex_answer_user = exercise_users.find_by(user_id: user.id) - user_ex_status = get_exercise_status(user.id) + ex_answer_user = exercise_users.where(user_id: user.id).select(:start_at,:end_at,:commit_status) + user_ex_status = get_exercise_status(user) user_status = 2 - if ex_answer_user.present? && (ex_answer_user.start_at.present? || ex_answer_user.end_at.present?) #学生有过答题的,或者立即截止,但学生未做试卷的 + if ex_answer_user.exists? && (ex_answer_user.first&.start_at.present? || ex_answer_user.first&.end_at.present?) #学生有过答题的,或者立即截止,但学生未做试卷的 user_status = ex_answer_user.commit_status end - if ex_answer_user.present? && ex_answer_user.start_at.blank? && user_ex_status == 3 + if ex_answer_user.exists? && ex_answer_user.first&.start_at.blank? && user_ex_status == 3 user_status = 4 end diff --git a/app/models/poll.rb b/app/models/poll.rb index 0434068cd..ed3c143fa 100644 --- a/app/models/poll.rb +++ b/app/models/poll.rb @@ -45,8 +45,7 @@ class Poll < ApplicationRecord poll_users else ex_group_setting_ids = poll_group_settings.poll_group_published.pluck(:course_group_id) - course_user_ids = course.students.where(course_group_id:ex_group_setting_ids).pluck(:user_id) - poll_users.where(user_id:course_user_ids) + poll_users.where(user_id: course.students.where(course_group_id:ex_group_setting_ids).pluck(:user_id).uniq) end end @@ -55,7 +54,7 @@ class Poll < ApplicationRecord poll_all_users = poll_users group_ids = poll_published_ids(user_id) if group_ids.present? - poll_all_users = poll_all_users.where(user_id: course.students.where(course_group_id: group_ids).pluck(:user_id).uniq) + poll_all_users = poll_all_users.where(user_id: course.students.where(course_group_id: group_ids).select(:user_id).pluck(:user_id).uniq) end poll_all_users end @@ -71,20 +70,14 @@ class Poll < ApplicationRecord end (current_user_groups + un_group_ids).uniq #统一设置时,为当前用户的分班id else - ex_group_setting = poll_group_settings.pluck("course_group_id").uniq + ex_group_setting = poll_group_settings.select(:course_group_id).pluck("course_group_id").uniq ex_group_setting & current_user_groups #当前用户有权限的已发布的分班id #非统一设置时,为当前用户有权限的且已发布分班的id end end - def get_poll_status(user_id) - user_group = course.course_members.find_by(user_id: user_id, is_active: 1) - if user_group.present? - if user_group.role == "STUDENT" #为学生 - is_teacher = false - else - is_teacher = true - end - ex_time = get_poll_times(user_id,is_teacher) + def get_poll_status(user) + if user.student_of_course?(course) + ex_time = get_poll_times(user_id,false) pb_time = ex_time[:publish_time] ed_time = ex_time[:end_time] if pb_time.present? && ed_time.present? && pb_time <= Time.now && ed_time > Time.now @@ -102,30 +95,20 @@ class Poll < ApplicationRecord #获取问卷的发布时间和截止时间。teacher 为boolean,当为true时,表示的是当前为老师 def get_poll_times(user_id,teacher) - if unified_setting + if unified_setting || teacher pb_time = publish_time en_time = end_time else poll_group_setting = poll_group_settings - if teacher #当前为老师,为设置组的最大值和最小值 - user_group = course.teacher_course_groups.get_user_groups(user_id) - user_group_ids = user_group.present? ? user_group.pluck(:course_group_id) : course.course_groups.pluck(:id) - user_poll_group_settings = poll_group_setting.find_in_poll_group("course_group_id",user_group_ids) - pb_time_min = user_poll_group_settings.publish_time_present.map(&:publish_time) - en_time_max = user_poll_group_settings.end_time_present.map(&:end_time) - pb_time = pb_time_min.size > 0 ? pb_time_min.min : nil - en_time = en_time_max.size > 0 ? en_time_max.max : nil + user_group = course.course_members.where(user_id: user_id).select(:course_group_id) + if user_group.exists? + user_group_id = user_group.first&.course_group_id + user_p_group_setting = poll_group_setting.where(course_group_id: user_group_id).select(:publish_time,:end_time) + pb_time = user_p_group_setting.first&.publish_time + en_time = user_p_group_setting.first&.end_time else - user_group = course.students.find_by(user_id: user_id) - if user_group.present? - user_group_id = user_group.course_group_id - user_p_group_setting = poll_group_setting.find_by(course_group_id: user_group_id) - pb_time = user_p_group_setting.present? ? user_p_group_setting.publish_time : nil - en_time = user_p_group_setting.present? ? user_p_group_setting.end_time : nil - else - pb_time = nil - en_time = nil - end + pb_time = nil + en_time = nil end end { @@ -136,19 +119,11 @@ class Poll < ApplicationRecord #判断当前用户的答题状态 def check_user_votes_status(user) - poll_answer_user = poll_users.find_by(user_id: user.id) - # user_poll_status = get_poll_status(user.id) + poll_answer_user = poll_users.where(user_id: user.id).select(:start_at,:end_at,:commit_status) user_status = 2 - - if poll_answer_user.present? && (poll_answer_user.start_at.present? || poll_answer_user.end_at.present?) #学生有过答题的,或者立即截止,但学生未做试卷的 + if poll_answer_user.exists? && (poll_answer_user.first&.start_at.present? || poll_answer_user.first&.end_at.present?) #学生有过答题的,或者立即截止,但学生未做试卷的 user_status = poll_answer_user.commit_status end - # - # if poll_answer_user.present? && poll_answer_user.start_at.blank? && user_poll_status == 3 - # # user_status = 4 - # user_status = 2 #问卷用户存在,且未开始答题,且问卷已截止时,返回未提交标示 - # end - user_status end diff --git a/app/views/exercises/index.json.jbuilder b/app/views/exercises/index.json.jbuilder index 4c143da4b..bccce4f2b 100644 --- a/app/views/exercises/index.json.jbuilder +++ b/app/views/exercises/index.json.jbuilder @@ -2,13 +2,12 @@ if @exercises_count > 0 json.exercises do json.array! @exercises do |exercise| - ex_index = exercise_index_show(exercise,@course,@is_teacher_or,@current_user_) json.extract! exercise, :id, :exercise_name,:is_public,:created_at if @is_teacher_or == 2 second_left = get_exercise_left_time(exercise,@current_user_) json.time second_left.present? ? (second_left / 60) : nil end - + ex_index = exercise_index_show(exercise,@course,@is_teacher_or,@current_user_) json.exercise_status ex_index[:ex_status] json.lock_status ex_index[:lock_icon] json.publish_time ex_index[:publish_time] # 试卷的发布时间 diff --git a/app/views/polls/index.json.jbuilder b/app/views/polls/index.json.jbuilder index b657da7a0..0face0966 100644 --- a/app/views/polls/index.json.jbuilder +++ b/app/views/polls/index.json.jbuilder @@ -1,18 +1,4 @@ - json.polls_counts do - json.polls_total_counts @polls_count #全部问卷数 - json.polls_all_counts @polls_select_count #选择后的问卷数 - json.polls_unpublish_counts @polls_unpublish_counts #未发布问卷数 - json.polls_published_counts @polls_published_counts #已发布问卷数 - # json.polls_ended_counts @polls_ended_counts #已截止问卷数 - json.left_banner_id @left_banner_id - json.left_banner_name @left_banner_name -end -json.course_types do - json.course_status @course_status # 课堂的当前是否结束,如结束,则为1,否则为0 - json.course_is_public @course_is_public #判断课堂是否为公开,只有公开课才有设为公开的按钮 - json.user_permission @is_teacher_or # 当前用户存在且为课堂教师/管理员/超级管理员时为1 ,课堂成员为2,否则为0 -end if @polls_count > 0 json.polls do @@ -32,3 +18,17 @@ else json.polls [] end +json.polls_counts do + json.polls_total_counts @polls_count #全部问卷数 + json.polls_all_counts @polls_select_count #选择后的问卷数 + json.polls_unpublish_counts @polls_unpublish_counts #未发布问卷数 + json.polls_published_counts @polls_published_counts #已发布问卷数 + json.left_banner_id @left_banner_id + json.left_banner_name @left_banner_name +end + +json.course_types do + json.course_status @course_status # 课堂的当前是否结束,如结束,则为1,否则为0 + json.course_is_public @course_is_public #判断课堂是否为公开,只有公开课才有设为公开的按钮 + json.user_permission @is_teacher_or # 当前用户存在且为课堂教师/管理员/超级管理员时为1 ,课堂成员为2,否则为0 +end diff --git a/config/locales/users/zh-CN.yml b/config/locales/users/zh-CN.yml index 5c4ad76a7..48b8ca075 100644 --- a/config/locales/users/zh-CN.yml +++ b/config/locales/users/zh-CN.yml @@ -1,4 +1,11 @@ 'zh-CN': + activerecord: + models: + user: '用户' + attributes: + user: + phone: '手机号' + mail: '邮箱' user: identity: teacher: 教师 diff --git a/config/routes.rb b/config/routes.rb index d3d04edfb..ee8b6a187 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -69,6 +69,8 @@ Rails.application.routes.draw do resources :tidings, only: [:index] scope module: :users do + resource :interest, only: [:create] + resources :accounts, only: [:show, :update] do resource :phone_bind, only: [:create] resource :email_bind, only: [:create] @@ -77,7 +79,6 @@ Rails.application.routes.draw do resource :auth_attachment, only: [:update] resource :authentication_apply, only: [:create] resource :professional_auth_apply, only: [:create] - resource :interest, only: [:create] end end end