|
|
@ -24,26 +24,53 @@ class FilesController < ApplicationController
|
|
|
|
|
|
|
|
|
|
|
|
get_category(@course, @course_second_category_id)
|
|
|
|
get_category(@course, @course_second_category_id)
|
|
|
|
@total_count = @attachments.size
|
|
|
|
@total_count = @attachments.size
|
|
|
|
@publish_count = @attachments.published.size
|
|
|
|
|
|
|
|
@unpublish_count = @total_count - @publish_count
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@attachments = @attachments.by_keywords(params[:search])
|
|
|
|
if @user.course_identity(@course) == 5
|
|
|
|
@attachments =
|
|
|
|
member = @course.course_members.find_by(user_id: current_user.id, is_active: 1)
|
|
|
|
case @user.course_identity(@course)
|
|
|
|
if member.try(:course_group_id).to_i == 0
|
|
|
|
when 5
|
|
|
|
@attachments = @attachments.published.unified_setting
|
|
|
|
@attachments.published
|
|
|
|
|
|
|
|
when 6, 7
|
|
|
|
|
|
|
|
@attachments.publiced.published
|
|
|
|
|
|
|
|
else
|
|
|
|
else
|
|
|
|
@attachments
|
|
|
|
not_atta_ids = @course.attachment_group_settings.none_published.where("course_group_id = #{member.try(:course_group_id)}").pluck(:attachment_id)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@attachments = @attachments.where.not(id: not_atta_ids).published
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
elsif @user.course_identity(@course) > 5
|
|
|
|
|
|
|
|
@attachments = @attachments.publiced.published
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@publish_count = @attachments.published.size
|
|
|
|
|
|
|
|
@unpublish_count = @total_count - @publish_count
|
|
|
|
|
|
|
|
@attachments = @attachments.by_keywords(params[:search])
|
|
|
|
|
|
|
|
|
|
|
|
@attachments = @attachments.page(@page).per(@page_size)
|
|
|
|
@attachments = @attachments.page(@page).per(@page_size)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def bulk_publish
|
|
|
|
def bulk_publish
|
|
|
|
return normal_status(403, "您没有权限进行操作") if current_user.course_identity(@course) >= 5
|
|
|
|
return normal_status(403, "您没有权限进行操作") if current_user.course_identity(@course) >= 5
|
|
|
|
@course.attachments.by_ids(@attachment_ids).unpublish.update_all(is_publish: 1, publish_time: Time.now)
|
|
|
|
tip_exception("请至少选择一个分班") if params[:group_ids].blank? && @course.course_groups.size != 0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
attachments = @course.attachments.by_ids(@attachment_ids)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ActiveRecord::Base.transaction do
|
|
|
|
|
|
|
|
# 有分班设置时
|
|
|
|
|
|
|
|
if @course.course_group_module? && @course.course_groups_count != 0 && params[:group_ids]
|
|
|
|
|
|
|
|
group_ids = params[:group_ids]&.reject(&:blank?)
|
|
|
|
|
|
|
|
charge_group_ids = @course.charge_group_ids(current_user)
|
|
|
|
|
|
|
|
publish_groups = charge_group_ids & group_ids if group_ids
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
attachments.each do |atta|
|
|
|
|
|
|
|
|
if atta.published? && !atta.unified_setting || !atta.published?
|
|
|
|
|
|
|
|
create_atta_group_settings atta
|
|
|
|
|
|
|
|
atta.update_all(unified_setting: 0) if atta.unified_setting
|
|
|
|
|
|
|
|
none_publish_settings = atta.attachment_group_settings.where(course_group_id: publish_groups).none_published
|
|
|
|
|
|
|
|
none_publish_settings.update_all(publish_time: Time.now)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 未发布的资源更新状态
|
|
|
|
|
|
|
|
attachments.where(is_publish: 0).update_all(is_publish: 1, publish_time: Time.now)
|
|
|
|
|
|
|
|
end
|
|
|
|
render_ok
|
|
|
|
render_ok
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
@ -153,6 +180,10 @@ class FilesController < ApplicationController
|
|
|
|
attachment.is_publish = @atta_is_publish
|
|
|
|
attachment.is_publish = @atta_is_publish
|
|
|
|
attachment.delay_publish = @atta_delay_publish
|
|
|
|
attachment.delay_publish = @atta_delay_publish
|
|
|
|
attachment.publish_time = @atta_publish_time
|
|
|
|
attachment.publish_time = @atta_publish_time
|
|
|
|
|
|
|
|
attachment.unified_setting = @unified_setting
|
|
|
|
|
|
|
|
if @unified_setting == 0
|
|
|
|
|
|
|
|
attachment_group_setting attachment, params[:group_settings]
|
|
|
|
|
|
|
|
end
|
|
|
|
# attachment.set_publish_time(publish_time) if is_unified_setting
|
|
|
|
# attachment.set_publish_time(publish_time) if is_unified_setting
|
|
|
|
# attachment.set_course_group_publish_time(@course, course_group_publish_times) if @course.course_groups.size > 0 && !is_unified_setting && publish_time.blank?
|
|
|
|
# attachment.set_course_group_publish_time(@course, course_group_publish_times) if @course.course_groups.size > 0 && !is_unified_setting && publish_time.blank?
|
|
|
|
attachment.save!
|
|
|
|
attachment.save!
|
|
|
@ -195,6 +226,10 @@ class FilesController < ApplicationController
|
|
|
|
attach_copied_obj.is_publish = @atta_is_publish
|
|
|
|
attach_copied_obj.is_publish = @atta_is_publish
|
|
|
|
attach_copied_obj.delay_publish = @atta_delay_publish
|
|
|
|
attach_copied_obj.delay_publish = @atta_delay_publish
|
|
|
|
attach_copied_obj.publish_time = @atta_publish_time
|
|
|
|
attach_copied_obj.publish_time = @atta_publish_time
|
|
|
|
|
|
|
|
attach_copied_obj.unified_setting = @unified_setting
|
|
|
|
|
|
|
|
if @unified_setting == 0
|
|
|
|
|
|
|
|
attachment_group_setting attach_copied_obj, params[:group_settings]
|
|
|
|
|
|
|
|
end
|
|
|
|
attach_copied_obj.course_second_category_id = course_second_category_id
|
|
|
|
attach_copied_obj.course_second_category_id = course_second_category_id
|
|
|
|
attach_copied_obj.copy_from = ori.copy_from.nil? ? ori.id : ori.copy_from
|
|
|
|
attach_copied_obj.copy_from = ori.copy_from.nil? ? ori.id : ori.copy_from
|
|
|
|
if attach_copied_obj.attachtype == nil
|
|
|
|
if attach_copied_obj.attachtype == nil
|
|
|
@ -234,6 +269,12 @@ class FilesController < ApplicationController
|
|
|
|
@old_attachment.is_publish = @atta_is_publish
|
|
|
|
@old_attachment.is_publish = @atta_is_publish
|
|
|
|
@old_attachment.delay_publish = @atta_delay_publish
|
|
|
|
@old_attachment.delay_publish = @atta_delay_publish
|
|
|
|
@old_attachment.publish_time = @atta_publish_time
|
|
|
|
@old_attachment.publish_time = @atta_publish_time
|
|
|
|
|
|
|
|
@old_attachment.unified_setting = @unified_setting
|
|
|
|
|
|
|
|
if @unified_setting == 0
|
|
|
|
|
|
|
|
attachment_group_setting @old_attachment, params[:group_settings]
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
@old_attachment.attachment_group_settings.destroy_all
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
if params[:description] && !params[:description].strip.blank? && params[:description] != @old_attachment.description
|
|
|
|
if params[:description] && !params[:description].strip.blank? && params[:description] != @old_attachment.description
|
|
|
|
@old_attachment.description = params[:description]
|
|
|
|
@old_attachment.description = params[:description]
|
|
|
@ -319,9 +360,40 @@ class FilesController < ApplicationController
|
|
|
|
|
|
|
|
|
|
|
|
def publish_params
|
|
|
|
def publish_params
|
|
|
|
tip_exception("缺少发布参数") if params[:delay_publish].blank?
|
|
|
|
tip_exception("缺少发布参数") if params[:delay_publish].blank?
|
|
|
|
tip_exception("缺少延期发布的时间参数") if params[:delay_publish].to_i == 1 && params[:publish_time].blank?
|
|
|
|
@unified_setting = 1
|
|
|
|
@atta_is_publish = params[:delay_publish].to_i == 1 && params[:publish_time].to_time > Time.now ? 0 : 1
|
|
|
|
if params[:delay_publish].to_i == 1 && @course.course_group_module? && @course.course_groups_count != 0
|
|
|
|
|
|
|
|
tip_exception("分班发布设置不能为空") if params[:group_settings].blank?
|
|
|
|
|
|
|
|
min_publish_time = params[:group_settings].pluck(:publish_time).reject(&:blank?).min
|
|
|
|
|
|
|
|
max_publish_time = params[:group_settings].pluck(:publish_time).reject(&:blank?).max
|
|
|
|
|
|
|
|
tip_exception("分班发布设置不能为空") if min_publish_time.blank?
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 分班设置中的时间一样且包含所有分班 则按统一设置处理,否则是非统一设置
|
|
|
|
|
|
|
|
@unified_setting = 0 unless min_publish_time == max_publish_time && params[:group_settings].pluck(:group_id).flatten.sort == @course.course_groups.pluck(:id).sort
|
|
|
|
|
|
|
|
elsif params[:delay_publish].to_i == 1
|
|
|
|
|
|
|
|
tip_exception("缺少延期发布的时间参数") if params[:publish_time].blank?
|
|
|
|
|
|
|
|
min_publish_time = params[:publish_time]
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
@atta_is_publish = params[:delay_publish].to_i == 1 && min_publish_time.to_time > Time.now ? 0 : 1
|
|
|
|
@atta_delay_publish = params[:delay_publish].to_i
|
|
|
|
@atta_delay_publish = params[:delay_publish].to_i
|
|
|
|
@atta_publish_time = params[:delay_publish].to_i == 1 && params[:publish_time] ? params[:publish_time] : Time.now
|
|
|
|
@atta_publish_time = params[:delay_publish].to_i == 1 ? min_publish_time : Time.now
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def create_atta_group_settings atta
|
|
|
|
|
|
|
|
if atta.attachment_group_settings.size != @course.course_groups.size
|
|
|
|
|
|
|
|
@course.course_groups.where.not(id: atta.attachment_group_settings.pluck(:course_group_id)).each do |group|
|
|
|
|
|
|
|
|
atta.attachment_group_settings << AttachmentGroupSetting.new(course_group_id: group.id, course_id: @course.id,
|
|
|
|
|
|
|
|
publish_time: atta.publish_time)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def attachment_group_setting attachment, group_setting
|
|
|
|
|
|
|
|
create_atta_group_settings attachment
|
|
|
|
|
|
|
|
group_setting.each do |setting|
|
|
|
|
|
|
|
|
tip_exception("分班id不能为空") if setting[:group_id].length == 0
|
|
|
|
|
|
|
|
tip_exception("发布时间不能为空") if setting[:publish_time].blank?
|
|
|
|
|
|
|
|
AttachmentGroupSetting.where(attachment_id: attachment.id, course_group_id: setting[:group_id]).
|
|
|
|
|
|
|
|
update_all(publish_time: setting[:publish_time])
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|