diff --git a/app/controllers/files_controller.rb b/app/controllers/files_controller.rb index 3d541fd61..f8b4578eb 100644 --- a/app/controllers/files_controller.rb +++ b/app/controllers/files_controller.rb @@ -57,36 +57,45 @@ class FilesController < ApplicationController elsif params[:course_id] @isproject = false + sort = "" if params[:sort] - if params[:sort].include?":" - @orderBy = params[:sort].split(":")[0] - @orderType = params[:sort].split(":")[1].split(",")[0] - else - @orderBy = params[:sort].split(",")[0] - @orderType = "asc" + params[:sort].split(",").each do |sort_type| + order_by = sort_type.split(":") + + case order_by[0] + when "filename" + attribute = "filename" + when "size" + attribute = "filesize" + when "attach_type" + attribute = "attachtype" + when "content_type" + attribute = "created_on" + when "field_file_dense" + attribute = "is_public" + when "downloads" + attribute = "downloads" + when "created_on" + attribute = "created_on" + end + + if order_by.count == 1 + sort += "#{Attachment.table_name}.#{attribute} desc " + elsif order_by.count == 2 + sort += "#{Attachment.table_name}.#{attribute} #{order_by[1]} " + end + if sort_type != params[:sort].split(",").last + sort += "," + end end end - - if @orderBy=="size" - @orderBy="filesize" - elsif @orderBy=="field_file_dense" - @orderBy="is_public" - elsif @orderBy=="attach_type" - @orderBy="attachtype" - elsif @orderBy=="content_type" - @orderBy="attachtype" - end - - if @orderBy - @containers = [ Course.includes(:attachments).reorder("#{Attachment.table_name}.#{@orderBy} #{@orderType}").find(@course.id)] - else - @containers = [ Course.includes(:attachments).reorder("#{Attachment.table_name}.created_on desc").find(@course.id)] - end + @containers = [ Course.includes(:attachments).reorder(sort).find(@course.id)] show_attachments @containers render :layout => 'base_courses' end + end def new