班级资源的复制

This commit is contained in:
cxt 2017-09-01 17:21:02 +08:00
parent a8c166ae52
commit 841b180bea
11 changed files with 80 additions and 13 deletions

View File

@ -70,6 +70,16 @@ class AttachmentsController < ApplicationController
file.downcase.end_with?(".pdf")
end
def batch_setting
@course = Course.find params[:course_id]
@attachments = @course.attachments
@limit = 10
@attachment_count = @attachments.count
@attachment_pages = Paginator.new @attachment_count, @limit, params['page'] || 1
@offset ||= @attachment_pages.offset
@attachments = paginateHelper @attachments,10
end
def direct_download
@attachment.increment_download
file_type = detect_content_type(@attachment)

View File

@ -737,6 +737,26 @@ class CoursesController < ApplicationController
def create
cs = CoursesService.new
@course = cs.create_course(params,User.current)[:course]
attachments = Attachment.where(:container_type => 'Course', :container_id => @course.syllabus.courses.map(&:id))
attachments.each do |attachment|
if Attachment.where(:container_type => 'Course', :container_id => @course.id, :filename => attachment.filename).count == 0
attach_copied_obj = attachment.copy
attach_copied_obj.tag_list.add(attachment.tag_list) # tag关联
attach_copied_obj.container = @course
attach_copied_obj.created_on = attachment.created_on
attach_copied_obj.author_id = attachment.author_id
attach_copied_obj.copy_from = attachment.copy_from.nil? ? attachment.id : attachment.copy_from
attach_copied_obj.is_publish = 1
#attach_copied_obj.publish_time = Time.now + 30.days
if attach_copied_obj.attachtype == nil
attach_copied_obj.attachtype = 4
end
attach_copied_obj.save
update_quotes attach_copied_obj
end
end
if params[:copy_course]
copy_course = Course.find params[:copy_course].to_i
@course.is_copy = params[:copy_course].to_i

View File

@ -226,11 +226,10 @@ class FilesController < ApplicationController
if sort == ""
sort = "created_on DESC"
end
course_ids = "(" + course.syllabus.courses.map(&:id).join(",") + ")"
if keywords != "%%"
resultSet = Attachment.where("attachments.container_type = 'Course' And attachments.container_id in #{course_ids} AND filename LIKE :like ", like: "%#{keywords}%").reorder(sort)
resultSet = Attachment.where("attachments.container_type = 'Course' And attachments.container_id = '#{course.id}' AND filename LIKE :like ", like: "%#{keywords}%").reorder(sort)
else
resultSet = Attachment.where("attachments.container_type = 'Course' And attachments.container_id in #{course_ids} "). reorder(sort)
resultSet = Attachment.where("attachments.container_type = 'Course' And attachments.container_id = '#{course.id}' "). reorder(sort)
end
#resultSet = Attachment.find_by_sql("SELECT `attachments`.* FROM `attachments` LEFT OUTER JOIN `homework_attaches` ON `attachments`.container_type = 'HomeworkAttach' AND `attachments`.container_id = `homework_attaches`.id LEFT OUTER JOIN `homework_for_courses` ON `homework_attaches`.bid_id = `homework_for_courses`.bid_id LEFT OUTER JOIN `homework_for_courses` AS H_C ON `attachments`.container_type = 'Bid' AND `attachments`.container_id = H_C.bid_id WHERE (`homework_for_courses`.course_id = 117 OR H_C.course_id = 117 OR (`attachments`.container_type = 'Course' AND `attachments`.container_id = 117)) AND `attachments`.filename LIKE '%#{keywords}%'").reorder("created_on DESC")
end
@ -386,7 +385,7 @@ class FilesController < ApplicationController
sort = "#{Attachment.table_name}.created_on desc"
end
@containers = @course.syllabus.courses.includes(:attachments).reorder(sort)
@containers = [ Course.includes(:attachments).reorder(sort).find(@course.id)]
show_attachments @containers
get_attachment_for_tip(@all_attachments)

View File

@ -3068,8 +3068,8 @@ module ApplicationHelper
#获取课程资源的TAG云
def get_course_tag_list course
all_attachments = Attachment.where(:container_type => 'Course', :container_id => course.syllabus.courses.map(&:id)).select{|attachment| attachment.is_public? ||
(attachment.container_type == "Course" && syllabus_course_member(User.current, Course.find(attachment.container_id)))||
all_attachments = course.attachments.select{|attachment| attachment.is_public? ||
(attachment.container_type == "Course" && User.current.member_of_course?(course))||
attachment.author_id == User.current.id
}
tag_list = attachment_tag_list all_attachments

View File

@ -812,9 +812,8 @@ module CoursesHelper
def visable_attachemnts_incourse course
return[] unless course
result = []
attachments = Attachment.where(:container_type => 'Course', :container_id => course.syllabus.courses.map(&:id))
attachments.each do |attachment|
if attachment.is_public? && attachment.is_publish == 1 || User.current == attachment.author || syllabus_course_teacher(User.current, Course.find(attachment.container_id)) || (syllabus_course_member(User.current, Course.find(attachment.container_id)) && attachment.is_publish == 1) || User.current.admin?
course.attachments.each do |attachment|
if attachment.is_public? && attachment.is_publish == 1 || User.current == attachment.author || User.current.allowed_to?(:as_teacher,course) || (User.current.member_of_course?(course) && attachment.is_publish == 1) || User.current.admin?
result << attachment
end
end

View File

@ -140,8 +140,8 @@ module FilesHelper
if (attachment.is_public? && attachment.container_type != "Course") ||
(attachment.is_public? && attachment.container_type == "Course" && attachment.is_publish == 1)||
(attachment.container_type == "Project" && User.current.member_of?(attachment.project)) ||
(attachment.container_type == "Course" && syllabus_course_teacher(User.current, Course.find(attachment.container_id)))||
(attachment.container_type == "Course" && syllabus_course_member(User.current, Course.find(attachment.container_id)) && attachment.is_publish == 1)||
(attachment.container_type == "Course" && User.current.allowed_to?(:as_teacher,Course.find(attachment.container_id)))||
(attachment.container_type == "Course" && User.current.member_of_course?(Course.find(attachment.container_id)) && attachment.is_publish == 1)||
attachment.author_id == User.current.id ||
(attachment.container_type == "OrgSubfield" and User.current.member_of_org?(attachment.container.organization))
result << attachment

View File

@ -103,7 +103,8 @@
<%= submit_tag "班内搜索", :class => "blueBtn mr5 fl",:name => "incourse",:id => "incourse" %>
<%#= submit_tag "全站搜索", :class => "blueBtn mr5 fl",:name => "insite",:id => "insite" %>
<% if is_course_teacher(User.current,@course) || (@course.publish_resource==1 && User.current.member_of_course?(@course) ) %>
<input class="blueBtn fr mr5" value="上传资源" onclick="course_files_upload();">
<%= link_to("批量设置", batch_setting_attachments_path(:course_id => @course.id), :class => "blue-btn fr mr5", :remote => true) %>
<a href="javascript:void(0);" class="blueBtn fr mr5" onclick="course_files_upload();">上传资源</a>
<%= link_to("导入资源", import_resources_user_path(User.current, :type => 6, :course_id => @course.id), :class => "blue-btn fr mr5", :remote => true) %>
<% end %>
<% end %>

View File

@ -1239,6 +1239,7 @@ RedmineApp::Application.routes.draw do
match "update_file_dense", :via => [:post]
match "renderTag" , :via => [:get, :post]
match 'delete_softapplications', :via => [:get, :post]
get 'batch_setting'
end
end
resources :groups do

View File

@ -0,0 +1,37 @@
class AddAttachmentsToCourses < ActiveRecord::Migration
def change
Course.where(:id => CourseActivity.where("updated_at > '2017-06-01 00:00:00'").map(&:course_id).uniq).each do |course|
attachments = Attachment.where(:container_type => 'Course', :container_id => course.syllabus.courses.map(&:id))
attachments.each do |attachment|
if Attachment.where(:container_type => 'Course', :container_id => course.id, :filename => attachment.filename).count == 0
attach_copied_obj = attachment.copy
attach_copied_obj.tag_list.add(attachment.tag_list) # tag关联
attach_copied_obj.container = course
attach_copied_obj.created_on = attachment.created_on
attach_copied_obj.author_id = attachment.author_id
attach_copied_obj.copy_from = attachment.copy_from.nil? ? attachment.id : attachment.copy_from
attach_copied_obj.is_publish = 1
#attach_copied_obj.publish_time = Time.now + 30.days
if attach_copied_obj.attachtype == nil
attach_copied_obj.attachtype = 4
end
attach_copied_obj.save
quo_attachments = Attachment.find_by_sql("select * from attachments where copy_from = #{attach_copied_obj.copy_from} or id = #{attach_copied_obj.copy_from}")
result = Attachment.find_by_sql("select count(*) as number from attachments where copy_from = #{attach_copied_obj.copy_from}")
if result.nil? || result.count <= 0
count = 0
else
count = result[0].number
end
attach_copied_obj.quotes = count
attach_copied_obj.save
quo_attachments.each do |att|
att.quotes = attach_copied_obj.quotes
att.save
end
#update_quotes attach_copied_obj
end
end
end
end
end

View File

@ -224,7 +224,7 @@ function submit_new_course()
{
if(regex_syllabus_option('new')&&regex_course_name('new')&&regex_course_class_period('new')&&regex_time_term('new'))
{
$("#new_course").submit();
$(".new_course").submit();
}
}