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

dev_course
cxt 6 years ago
commit 9586dee9cb

@ -50,9 +50,11 @@ class CoursesController < ApplicationController
order_str = @order != "course_members_count" && @order != "created_at" ? "updated_at" : @order order_str = @order != "course_members_count" && @order != "created_at" ? "updated_at" : @order
if @order == "all" if @order == "all"
# @course = Course.where(is_delete: 0, is_hidden: 0).find_by_sql("select c.name, c.id, s.name, u.last_name from # @course = Course.where(is_delete: 0, is_hidden: 0).select("select c.name, c.id, s.name, u.login, ifnull(concat(u.lastname,u.firstname),
# courses c, users u, user_extensions ue, schools s where c.is_delete=0 and c.tea_id=u.id and # u.login), s.name from courses c, users u, user_extensions ue, schools s where c.is_delete=0 and
# u.id=ue.user_id and ue.school_id=s.id limit 10;") # c.tea_id=u.id and u.id=ue.user_id and ue.school_id=s.id")
# @courses = Course.where(is_delete: 0, is_hidden: 0).includes([teacher: :user_extension], :school)
@courses = Course.where(is_delete: 0, is_hidden: 0).select("courses.id, courses.tea_id, courses.name, courses.exercises_count, courses.polls_count, @courses = Course.where(is_delete: 0, is_hidden: 0).select("courses.id, courses.tea_id, courses.name, courses.exercises_count, courses.polls_count,
courses.is_public, courses.is_end, courses.visits, courses.course_members_count,courses.homework_commons_count,(SELECT MAX(created_at) courses.is_public, courses.is_end, courses.visits, courses.course_members_count,courses.homework_commons_count,(SELECT MAX(created_at)

@ -431,7 +431,9 @@ class ExercisesController < ApplicationController
ActiveRecord::Base.transaction do ActiveRecord::Base.transaction do
begin begin
error_count = 0 # 判断循环里是否有已发布/已截止的,且时间更改了的分班。 error_count = 0 # 判断循环里是否有已发布/已截止的,且时间更改了的分班。
course_group_ids = @course.teacher_course_group_ids(current_user.id) #当前老师的班级id数组 # 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.id)
if exercise_status == 1 && (course_group_ids - [0]).count > 0 # 试卷未发布且老师的分班大于1 ,才可以修改统一设置,否则按试卷默认的来处理 if exercise_status == 1 && (course_group_ids - [0]).count > 0 # 试卷未发布且老师的分班大于1 ,才可以修改统一设置,否则按试卷默认的来处理
@ -695,13 +697,15 @@ class ExercisesController < ApplicationController
if ex_status == 1 #如果试卷存在已发布的,或者是已截止的,那么则直接跳过 if ex_status == 1 #如果试卷存在已发布的,或者是已截止的,那么则直接跳过
g_course = params[:group_ids] #表示是否传入分班参数,如果传入分班的参数,那么试卷的统一设置需修改 g_course = params[:group_ids] #表示是否传入分班参数,如果传入分班的参数,那么试卷的统一设置需修改
if g_course if g_course
course_groups = @course.teacher_course_groups.get_user_groups(current_user.id) # course_groups = @course.teacher_course_groups.get_user_groups(current_user.id)
#
# if course_groups.blank?
# user_course_groups = @course.course_groups.present? ? @course.course_groups.pluck(:id) : []
# else
# user_course_groups = course_groups.pluck(:course_group_id).reject(&:blank?).uniq
# end
user_course_groups = @course.charge_group_ids(current_user)
if course_groups.blank?
user_course_groups = @course.course_groups.present? ? @course.course_groups.pluck(:id) : []
else
user_course_groups = course_groups.pluck(:course_group_id).reject(&:blank?).uniq
end
if g_course.map(&:to_i).sort == user_course_groups.sort # 如果是设置为全部班级,则试卷不用分组,且试卷设定为统一设置,否则则分组设置 if g_course.map(&:to_i).sort == user_course_groups.sort # 如果是设置为全部班级,则试卷不用分组,且试卷设定为统一设置,否则则分组设置
exercise.exercise_group_settings.destroy_all exercise.exercise_group_settings.destroy_all
@ -1505,13 +1509,14 @@ class ExercisesController < ApplicationController
def get_user_permission_course(exercise_ids,status) def get_user_permission_course(exercise_ids,status)
exercise_status = status.to_i #传入的试卷发布状态 exercise_status = status.to_i #传入的试卷发布状态
unpublish_group = [] unpublish_group = []
g_course_ids = @course.teacher_course_groups.get_user_groups(current_user.id).pluck(:course_group_id).reject(&:blank?).uniq #当前用户有权限的分班 # 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) # if g_course_ids.blank? || g_course_ids.include?(0)
user_groups_id = @course.course_groups.pluck(:id) # user_groups_id = @course.course_groups.pluck(:id)
else # else
user_groups_id = g_course_ids # user_groups_id = g_course_ids
end # end
user_groups_id = @course.charge_group_ids(current_user)
exercises_all = Exercise.where(id:exercise_ids) exercises_all = Exercise.where(id:exercise_ids)
exercises_all.each do |exercise| exercises_all.each do |exercise|
if exercise.present? if exercise.present?

@ -170,15 +170,9 @@ class MessagesController < ApplicationController
def bulk_move def bulk_move
# 课堂的目录之间移动,有子栏目的才显示此项 # 课堂的目录之间移动,有子栏目的才显示此项
return normal_status(403) unless current_user.teacher_of_course?(@board.course) return normal_status(403) unless current_user.teacher_of_course?(@board.course)
begin Message.bulk_move_to_other_board(params[:ids], params[:to_board_id])
Message.bulk_move_to_other_board(params[:ids], params[:to_board_id], current_user.id)
rescue Exception => e
uid_logger_error(e.message)
tip_exception(e.message)
raise ActiveRecord::Rollback
end
end end
def bulk_public def bulk_public

@ -43,7 +43,7 @@ class PollsController < ApplicationController
# polls的不同用户群体的显示 # polls的不同用户群体的显示
if @user_course_identity < Course::STUDENT # @is_teacher_or 1为老师/管理员/助教 if @user_course_identity < Course::STUDENT # @is_teacher_or 1为老师/管理员/助教
@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?) @teacher_groups_ids = @course.charge_group_ids(current_user)
@polls = @polls_all #老师能看到全部的问卷,不管是已发布的/未发布的/已截止的/统一设置的/私有设置的(看到内容不同) @polls = @polls_all #老师能看到全部的问卷,不管是已发布的/未发布的/已截止的/统一设置的/私有设置的(看到内容不同)
elsif @user_course_identity == Course::STUDENT # 2为课堂成员能看到统一设置的和自己班级的 elsif @user_course_identity == Course::STUDENT # 2为课堂成员能看到统一设置的和自己班级的
@is_teacher_or = 2 @is_teacher_or = 2
@ -254,12 +254,12 @@ class PollsController < ApplicationController
if pl_status == 1 #如果问卷存在已发布的,或者是已截止的,那么则直接跳过 if pl_status == 1 #如果问卷存在已发布的,或者是已截止的,那么则直接跳过
g_course = params[:group_ids] #表示是否传入分班参数,如果传入分班的参数那么poll的统一设置需修改 g_course = params[:group_ids] #表示是否传入分班参数,如果传入分班的参数那么poll的统一设置需修改
if g_course if g_course
course_groups = @course.teacher_course_groups.get_user_groups(current_user.id) user_course_groups = @course.charge_group_ids(current_user)
if course_groups.blank? # if course_groups.blank?
user_course_groups = @course.course_groups.present? ? @course.course_groups.pluck(:id) : [] # user_course_groups = @course.course_groups.present? ? @course.course_groups.pluck(:id) : []
else # else
user_course_groups = course_groups.pluck(:course_group_id) # user_course_groups = course_groups.pluck(:course_group_id)
end # end
if g_course.map(&:to_i).sort == user_course_groups.sort # 如果是设置为全部班级,则问卷不用分组,且问卷设定为统一设置,否则则分组设置 if g_course.map(&:to_i).sort == user_course_groups.sort # 如果是设置为全部班级,则问卷不用分组,且问卷设定为统一设置,否则则分组设置
poll.poll_group_settings.destroy_all poll.poll_group_settings.destroy_all
poll_unified = true poll_unified = true
@ -673,7 +673,7 @@ class PollsController < ApplicationController
@user_published_setting = @poll.poll_group_settings.find_in_poll_group("course_group_id",@being_setting_course_ids) @user_published_setting = @poll.poll_group_settings.find_in_poll_group("course_group_id",@being_setting_course_ids)
poll_ids = [@poll.id] poll_ids = [@poll.id]
@poll_publish_count = get_user_permission_course(poll_ids,2).count @poll_publish_count = get_user_permission_course(poll_ids,2).count
## 需添加发送消息的接口,稍后添加
rescue Exception => e rescue Exception => e
uid_logger_error(e.message) uid_logger_error(e.message)
tip_exception("页面调用失败!") tip_exception("页面调用失败!")
@ -688,7 +688,7 @@ class PollsController < ApplicationController
begin begin
error_count = 0 # 判断循环里是否有已发布/已截止的,且时间更改了的分班。 error_count = 0 # 判断循环里是否有已发布/已截止的,且时间更改了的分班。
course_group_ids = @course.teacher_course_group_ids(current_user.id) #当前老师的班级id数组 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.id)
if poll_status == 1 && (course_group_ids - [0]).count > 0 # 问卷未发布且老师的分班大于1 才可以修改统一设置否则按poll默认的来处理 if poll_status == 1 && (course_group_ids - [0]).count > 0 # 问卷未发布且老师的分班大于1 才可以修改统一设置否则按poll默认的来处理
@ -951,7 +951,6 @@ class PollsController < ApplicationController
def poll_lists def poll_lists
ActiveRecord::Base.transaction do ActiveRecord::Base.transaction do
begin begin
logger.info("########___________@course.teacher_course_groups)________________####################{@course.teacher_course_groups.where(user_id:current_user.id).pluck(:course_group_id)}")
poll_ids = [@poll.id] poll_ids = [@poll.id]
@poll_list_status = @poll.get_poll_status(current_user.id) @poll_list_status = @poll.get_poll_status(current_user.id)
@poll_publish_count = get_user_permission_course(poll_ids,2).count @poll_publish_count = get_user_permission_course(poll_ids,2).count
@ -1213,12 +1212,13 @@ class PollsController < ApplicationController
def get_user_permission_course(poll_ids,status) #获取用户权限范围内的已发布/未发布 def get_user_permission_course(poll_ids,status) #获取用户权限范围内的已发布/未发布
poll_status = status.to_i poll_status = status.to_i
unpublish_group = [] unpublish_group = []
g_course_ids = @course.teacher_course_groups.get_user_groups(current_user.id).pluck(:course_group_id).reject(&:blank?).uniq # 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) #当前用户的分班权限为空,即具体全部的分班权限 # if g_course_ids.blank? || g_course_ids.include?(0) #当前用户的分班权限为空,即具体全部的分班权限
user_groups_id = @course.course_groups.pluck(:id) # user_groups_id = @course.course_groups.pluck(:id)
else # else
user_groups_id = g_course_ids # user_groups_id = g_course_ids
end # end
user_groups_id = @course.charge_group_ids(current_user)
all_polls = Poll.where(id:poll_ids) all_polls = Poll.where(id:poll_ids)
all_polls.each do |poll| all_polls.each do |poll|
if poll.present? if poll.present?

@ -47,10 +47,25 @@ class Message < ApplicationRecord
end end
end end
def self.bulk_move_to_other_board(message_ids, to_board_id, author_id) def self.bulk_move_to_other_board(message_ids, to_board_id)
message_ids.each do |id| to_board = Board.find(to_board_id)
message = Message.find id
message.update_attributes(board_id: to_board_id, author_id: author_id) if message.parent_id.nil? # TODO 暂时只支持跟节点移动 messages = Message.where(id: message_ids, parent_id: nil).select(:id, :board_id).to_a
return if messages.blank?
from_board = Board.find(messages.first.board_id)
root_ids = messages.map(&:id)
children = Message.where(parent_id: root_ids).select(:id).to_a
children_ids = children.map(&:id)
second_children = Message.where(parent_id: children_ids).select(:id).to_a
ids = root_ids.concat(children_ids).concat(second_children.map(&:id)).uniq
ActiveRecord::Base.transaction do
Message.where(id: ids, board_id: from_board.id).update_all(board_id: to_board.id)
to_board.increment!(:messages_count, ids.size)
from_board.increment!(:messages_count, - ids.size)
end end
end end

@ -54,7 +54,6 @@ class Poll < ApplicationRecord
def all_poll_users(user_id) def all_poll_users(user_id)
poll_users = self.poll_users poll_users = self.poll_users
group_ids = poll_published_ids(user_id) group_ids = poll_published_ids(user_id)
logger.info("##########_________group_ids______#########################{group_ids}")
if group_ids.present? if group_ids.present?
poll_users = poll_users.where(user_id: course.students.where(course_group_id: group_ids).pluck(:user_id)) poll_users = poll_users.where(user_id: course.students.where(course_group_id: group_ids).pluck(:user_id))
end end
@ -64,7 +63,6 @@ class Poll < ApplicationRecord
#当前用户已发布的班级id和试卷分组已发布的班级id的交集 #当前用户已发布的班级id和试卷分组已发布的班级id的交集
def poll_published_ids(user_id) def poll_published_ids(user_id)
current_user_groups = course.teacher_course_group_ids(user_id) current_user_groups = course.teacher_course_group_ids(user_id)
logger.info("##########_________current_user_groups______#########################{current_user_groups}")
if unified_setting if unified_setting
if course.none_group_count > 0 #有未分班的,则发布到未发布 if course.none_group_count > 0 #有未分班的,则发布到未发布
un_group_ids = [0] un_group_ids = [0]

@ -17,7 +17,7 @@ module Educoderplus
# the framework and any gems in your application. # the framework and any gems in your application.
# #
# #
config.educoder = config_for(:configuration) # config.educoder = config_for(:configuration)
config.active_record.default_timezone = :local config.active_record.default_timezone = :local
config.time_zone = 'Beijing' config.time_zone = 'Beijing'

Loading…
Cancel
Save