From 71e7d2c8725ce8ed98f1693e8ea2c70fe417286e Mon Sep 17 00:00:00 2001 From: z9hang Date: Thu, 27 Nov 2014 17:17:33 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=85=A8=E7=AB=99=E6=90=9C?= =?UTF-8?q?=E7=B4=A2=E7=BB=93=E6=9E=9C=E6=98=BE=E7=A4=BA=E7=AD=96=E7=95=A5?= =?UTF-8?q?=EF=BC=9A=E7=A7=81=E6=9C=89=E8=B5=84=E6=BA=90=E5=B1=9E=E4=BA=8E?= =?UTF-8?q?=E5=BD=93=E5=89=8D=E8=AF=BE=E7=A8=8B=EF=BC=8C=E4=B8=94=E5=BD=93?= =?UTF-8?q?=E5=89=8D=E7=94=A8=E6=88=B7=E4=B8=BA=E5=BD=93=E5=89=8D=E8=AF=BE?= =?UTF-8?q?=E7=A8=8B=E7=9A=84=E6=88=90=E5=91=98=E6=97=B6=E5=8F=AF=E8=A7=81?= =?UTF-8?q?=EF=BC=8C=E5=85=B6=E4=BB=96=E6=83=85=E5=86=B5=E7=A7=81=E6=9C=89?= =?UTF-8?q?=E8=B5=84=E6=BA=90=E4=B8=8D=E5=8F=AF=E8=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/files_controller.rb | 5 +++-- app/helpers/files_helper.rb | 21 +++++++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/app/controllers/files_controller.rb b/app/controllers/files_controller.rb index aa1c158e0..ac228e0d4 100644 --- a/app/controllers/files_controller.rb +++ b/app/controllers/files_controller.rb @@ -51,7 +51,7 @@ class FilesController < ApplicationController #(redirect_to stores_url, :notice => l(:label_sumbit_empty);return) if params[:name].blank? if params[:insite] @result = find_public_attache q - @result = visable_attachemnts @result + @result = visable_attachemnts_insite @result,@course @searched_attach = paginateHelper @result,10 else @result = find_course_attache q,@course @@ -66,8 +66,9 @@ class FilesController < ApplicationController end def find_course_attache keywords,course - resultSet = Attachment.where("attachments.container_type = 'Course' And attachments.container_id = '#{course.id}' AND filename LIKE :like ", like: "%#{keywords}%"). + resultSet = Attachment.where("(attachments.container_type = 'Course'And attachments.container_id = '#{course.id}') OR (attachments.container_type = 'HomeworkAttach' AND ) AND filename LIKE :like ", like: "%#{keywords}%"). reorder("created_on DESC") + #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 def find_public_attache keywords diff --git a/app/helpers/files_helper.rb b/app/helpers/files_helper.rb index c3a6a7b3e..253ce34a5 100644 --- a/app/helpers/files_helper.rb +++ b/app/helpers/files_helper.rb @@ -93,6 +93,27 @@ module FilesHelper result end + def visable_attachemnts_incourse attachments + result = [] + attachments.each do |attachment| + if attachment.is_public? || (attachment.author.member_of_course?(Course.find(attachment.container_id)))|| attachment.author_id == User.current.id + result << attachment + end + end + result + end + + def visable_attachemnts_insite attachments,course + result = [] + attachments.each do |attachment| + if attachment.is_public? || (attachment.container_type == "Course" && attachment.container_id == course.id && attachment.author.member_of_course?(Course.find(attachment.container_id)))|| attachment.author_id == User.current.id + result << attachment + end + end + result + end + + def get_qute_number attachment if attachment.copy_from result = Attachment.find_by_sql("select count(*) as number from attachments where copy_from = #{attachment.copy_from}")