@ -22,22 +22,55 @@ class FilesController < ApplicationController
menu_item :files
before_filter :find_project_by_project_id #, :except => [:getattachtype]
before_filter :authorize , :except = > [ :getattachtype ]
before_filter :authorize , :except = > [ :getattachtype , :quote_resource_show , :search ]
helper :sort
include SortHelper
helper :project_score
def show_attachments obj
all_attachments = [ ]
@ all_attachments = [ ]
obj . each do | container |
all_attachments += container . attachments
@ all_attachments += container . attachments
end
@limit = 10
@feedback_count = all_attachments. count
@feedback_count = @ all_attachments. count
@feedback_pages = Paginator . new @feedback_count , @limit , params [ 'page' ]
@offset || = @feedback_pages . offset
@curse_attachments = all_attachments [ @offset , @limit ]
@curse_attachments_all = @all_attachments [ @offset , @limit ]
@curse_attachments = paginateHelper @all_attachments , 10
end
def search
begin
@is_remote = true
q = " % #{ params [ :name ] . strip } % "
#(redirect_to stores_url, :notice => l(:label_sumbit_empty);return) if params[:name].blank?
if params [ :insite ]
@result = find_public_attache q
@searched_attach = paginateHelper @result , 10
else
@result = find_course_attache q , @course
@searched_attach = paginateHelper @result , 10
end
rescue Exception = > e
#render 'stores'
redirect_to stores_url
end
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 } % " ) .
reorder ( " created_on DESC " )
end
def find_public_attache keywords
# StoresController#search 将每条文件都查出来,再次进行判断过滤。---> resultSet.to_a.map
# 此时内容不多速度还可, 但文件增长, 每条判断多则进行3-4次表连接。
# 现在还木有思路 药丸
resultSet = Attachment . where ( " attachments.container_type IS NOT NULL AND filename LIKE :like " , like : " % #{ keywords } % " ) .
reorder ( " created_on DESC " )
end
def index
@ -48,7 +81,9 @@ class FilesController < ApplicationController
'size' = > " #{ Attachment . table_name } .filesize " ,
'downloads' = > " #{ Attachment . table_name } .downloads "
sort = " "
@sort = " "
@order = " "
@is_remote = false
if params [ :project_id ]
@isproject = true
@ -113,7 +148,8 @@ class FilesController < ApplicationController
when " created_on "
attribute = " created_on "
end
@sort = order_by [ 0 ]
@order = order_by [ 1 ]
if order_by . count == 1
sort += " #{ Attachment . table_name } . #{ attribute } asc "
elsif order_by . count == 2
@ -134,6 +170,10 @@ class FilesController < ApplicationController
end
def quote_resource_show
@file = Attachment . find ( params [ :id ] )
end
def new
@versions = @project . versions . sort
@course_tag = @project . project_type
@ -265,6 +305,7 @@ class FilesController < ApplicationController
'size' = > " #{ Attachment . table_name } .filesize " ,
'downloads' = > " #{ Attachment . table_name } .downloads "
sort = ''
if params [ :sort ]
params [ :sort ] . split ( " , " ) . each do | sort_type |
order_by = sort_type . split ( " : " )