From fccbbe6e2b36d886db5a6f75d99cbd5265c2edca Mon Sep 17 00:00:00 2001 From: lizanle <491823689@qq.com> Date: Thu, 31 Dec 2015 14:52:50 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8D=E5=85=81=E8=AE=B8=E9=87=8D=E5=A4=8D?= =?UTF-8?q?=E5=8F=91=E9=80=81=E3=80=82=E4=BD=86=E6=98=AF=E5=8F=91=E9=80=81?= =?UTF-8?q?=E8=BF=87=E7=A8=8B=E4=B8=8D=E4=BC=9A=E7=BB=99=E4=BA=88=E6=8F=90?= =?UTF-8?q?=E7=A4=BA=E3=80=82=E5=A6=82=E6=9E=9C=E8=AF=BE=E7=A8=8B=E6=88=96?= =?UTF-8?q?=E8=80=85=E9=A1=B9=E7=9B=AE=E6=88=96=E8=80=85=E7=BB=84=E7=BB=87?= =?UTF-8?q?=E5=B7=B2=E7=BB=8F=E6=9C=89=E4=BA=86=E8=AF=A5=E8=B5=84=E6=BA=90?= =?UTF-8?q?=EF=BC=8C=E9=82=A3=E4=B9=88=E8=AF=A5=E8=B5=84=E6=BA=90=E7=9A=84?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=97=B6=E9=97=B4=E4=BC=9A=E5=8F=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/users_controller.rb | 79 +++++++++++++++++++++++++---- 1 file changed, 70 insertions(+), 9 deletions(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index eb2ae3d57..56722aa30 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -1489,6 +1489,16 @@ class UsersController < ApplicationController unless course_ids.nil? course_ids.each do |id| next if ori.blank? + @exist = false + Course.find(id).attachments.each do |att| #如果课程中包含该资源 + if att.id == ori.id || (!att.copy_from.nil? && !ori.copy_from.nil? && att.copy_from == ori.copy_from) || att.copy_from == ori.id || att.id == ori.copy_from + att.created_on = Time.now + att.save + @exist = true + break + end + end + next if @exist attach_copied_obj = ori.copy attach_copied_obj.tag_list.add(ori.tag_list) # tag关联 attach_copied_obj.container = Course.find(id) @@ -1515,6 +1525,16 @@ class UsersController < ApplicationController unless course_ids.nil? course_ids.each do |id| next if ori.blank? + @exist = false + Course.find(id).attachments.each do |att| #如果课程中包含该资源 + if att.id == ori.id || (!att.copy_from.nil? && !ori.copy_from.nil? && att.copy_from == ori.copy_from) || att.copy_from == ori.id || att.id == ori.copy_from + att.created_on = Time.now + att.save + @exist = true + break + end + end + next if @exist attach_copied_obj = ori.copy attach_copied_obj.tag_list.add(ori.tag_list) # tag关联 attach_copied_obj.container = Course.find(id) @@ -1563,6 +1583,16 @@ class UsersController < ApplicationController unless project_ids.nil? project_ids.each do |project_id| next if ori.blank? + @exist = false + Project.find(project_id).attachments.each do |att| #如果课程中包含该资源 + if att.id == ori.id || (!att.copy_from.nil? && !ori.copy_from.nil? && att.copy_from == ori.copy_from) || att.copy_from == ori.id || att.id == ori.copy_from + att.created_on = Time.now + att.save + @exist = true + break + end + end + next if @exist attach_copied_obj = ori.copy attach_copied_obj.tag_list.add(ori.tag_list) # tag关联 attach_copied_obj.container = Project.find(project_id) @@ -1588,6 +1618,16 @@ class UsersController < ApplicationController unless project_ids.nil? project_ids.each do |project_id| next if ori.blank? + @exist = false + Project.find(project_id).attachments.each do |att| #如果课程中包含该资源 + if att.id == ori.id || (!att.copy_from.nil? && !ori.copy_from.nil? && att.copy_from == ori.copy_from) || att.copy_from == ori.id || att.id == ori.copy_from + att.created_on = Time.now + att.save + @exist = true + break + end + end + next if @exist attach_copied_obj = ori.copy attach_copied_obj.tag_list.add(ori.tag_list) # tag关联 attach_copied_obj.container = Project.find(project_id) @@ -1633,16 +1673,27 @@ class UsersController < ApplicationController ori = Attachment.find_by_id(send_id) unless subfield_id.nil? attach_copied_obj = ori.copy - attach_copied_obj.tag_list.add(ori.tag_list) # tag关联 - attach_copied_obj.container = OrgSubfield.find(subfield_id) - attach_copied_obj.created_on = Time.now - attach_copied_obj.author_id = User.current.id - attach_copied_obj.is_public = 0 - attach_copied_obj.copy_from = ori.copy_from.nil? ? ori.id : ori.copy_from #发送要添加copy_from - if attach_copied_obj.attachtype == nil - attach_copied_obj.attachtype = 1 + @exist = false + OrgSubfield.find(subfield_id).attachments.each do |att| #如果课程中包含该资源 + if att.id == ori.id || (!att.copy_from.nil? && !ori.copy_from.nil? && att.copy_from == ori.copy_from) || att.copy_from == ori.id || att.id == ori.copy_from + att.created_on = Time.now + att.save + @exist = true + break + end + end + if @exist == false #如果不存在该资源 + attach_copied_obj.tag_list.add(ori.tag_list) # tag关联 + attach_copied_obj.container = OrgSubfield.find(subfield_id) + attach_copied_obj.created_on = Time.now + attach_copied_obj.author_id = User.current.id + attach_copied_obj.is_public = 0 + attach_copied_obj.copy_from = ori.copy_from.nil? ? ori.id : ori.copy_from #发送要添加copy_from + if attach_copied_obj.attachtype == nil + attach_copied_obj.attachtype = 1 + end + attach_copied_obj.save end - attach_copied_obj.save end elsif params[:send_ids].present? send_ids = params[:send_ids].split(" ") @@ -1655,6 +1706,16 @@ class UsersController < ApplicationController ori = Attachment.find_by_id(send_id) unless subfield_id.nil? next if ori.blank? + @exist = false + OrgSubfield.find(subfield_id).attachments.each do |att| #如果课程中包含该资源 + if att.id == ori.id || (!att.copy_from.nil? && !ori.copy_from.nil? && att.copy_from == ori.copy_from) || att.copy_from == ori.id || att.id == ori.copy_from + att.created_on = Time.now + att.save + @exist = true + break + end + end + next if @exist attach_copied_obj = ori.copy attach_copied_obj.tag_list.add(ori.tag_list) # tag关联 attach_copied_obj.container = OrgSubfield.find(subfield_id)