downloads desc
This commit is contained in:
parent
d0d36186df
commit
95e77464ad
|
@ -15,9 +15,9 @@ class StoresController < ApplicationController
|
|||
# reorder("#{Attachment.table_name}.created_on DESC").
|
||||
# limit(LIMIT)
|
||||
|
||||
# @courses_attach = Attachment.includes(:projects).where("projects.project_type=?", 1).
|
||||
# reorder("#{Attachment.table_name}.created_on DESC").
|
||||
# limit(LIMIT)
|
||||
# @courses_attach = Attachment.includes(:projects).where("projects.project_type=?", 1).
|
||||
# reorder("#{Attachment.table_name}.created_on DESC").
|
||||
# limit(LIMIT)
|
||||
@homeworks_attach = Attachment.where("container_type = 'HomeworkAttach'").
|
||||
reorder("created_on DESC").
|
||||
limit(LIMIT)
|
||||
|
@ -31,7 +31,10 @@ class StoresController < ApplicationController
|
|||
private
|
||||
|
||||
def project_classification project_type=0
|
||||
pro_attach = Attachment.joins("LEFT JOIN projects ON attachments.container_id = projects.id").where("projects.project_type=#{project_type}")
|
||||
pro_attach = Attachment.joins("LEFT JOIN projects ON attachments.container_id = projects.id").
|
||||
where("projects.project_type=#{project_type}").
|
||||
reorder("downloads").
|
||||
limit(LIMIT)
|
||||
doc_attach = join_tools_project "documents", project_type
|
||||
issue_attach = join_tools_project "issues", project_type
|
||||
mess_attach = []#join_tools_project "messages", project_type
|
||||
|
@ -39,10 +42,14 @@ class StoresController < ApplicationController
|
|||
vers_attach = join_tools_project "versions", project_type
|
||||
wiki_attach = []#join_tools_project "wiki_pages", project_type
|
||||
|
||||
pro_attach+doc_attach+issue_attach+mess_attach+news_attach+vers_attach+wiki_attach
|
||||
tmp = pro_attach+doc_attach+issue_attach+mess_attach+news_attach+vers_attach+wiki_attach
|
||||
tmp.sort { |a, b| b.downloads <=> a.downloads }
|
||||
end
|
||||
def join_tools_project tableName, project_type=0
|
||||
Attachment.joins(str_join_table(tableName)).where("projects.project_type=#{project_type}")
|
||||
Attachment.joins(str_join_table(tableName)).
|
||||
where("projects.project_type=#{project_type}").
|
||||
reorder('downloads DESC').
|
||||
limit(LIMIT)
|
||||
end
|
||||
|
||||
def str_join_table tableName
|
||||
|
|
|
@ -20,7 +20,7 @@ require "fileutils"
|
|||
|
||||
class Attachment < ActiveRecord::Base
|
||||
belongs_to :container, :polymorphic => true
|
||||
belongs_to :projects, foreign_key: 'container_id', conditions: "attachments.container_type = 'Project'"
|
||||
belongs_to :project, foreign_key: 'container_id', conditions: "attachments.container_type = 'Project'"
|
||||
belongs_to :author, :class_name => "User", :foreign_key => "author_id"
|
||||
|
||||
validates_presence_of :filename, :author
|
||||
|
|
Loading…
Reference in New Issue