2014-01-10 09:18:09 +08:00
|
|
|
# Trustie - education management software
|
|
|
|
# Copyright (C) 2013-2014
|
|
|
|
class StoresController < ApplicationController
|
|
|
|
layout 'base_stores'
|
|
|
|
# menu_item :overview
|
|
|
|
# menu_item :roadmap, :only => :roadmap
|
|
|
|
# menu_item :settings, :only => :settings
|
|
|
|
|
|
|
|
# include ActsAsTaggableOn::TagsHelper
|
2014-01-13 16:24:13 +08:00
|
|
|
LIMIT = 20 unless const_defined?(:LIMIT)
|
2014-01-10 09:18:09 +08:00
|
|
|
def index
|
2014-01-13 21:24:01 +08:00
|
|
|
# @projects_attach = project_classification(0).take(LIMIT)
|
|
|
|
# @courses_attach = project_classification(1).take(LIMIT)
|
2014-01-14 10:24:13 +08:00
|
|
|
@projects_attach = Attachment.includes(:project).where("projects.project_type=? AND projects.is_public = ?", 0, 1).
|
2014-01-13 21:24:01 +08:00
|
|
|
reorder("#{Attachment.table_name}.downloads DESC").
|
|
|
|
limit(LIMIT)
|
2014-01-13 16:34:24 +08:00
|
|
|
|
2014-01-14 10:24:13 +08:00
|
|
|
@courses_attach = Attachment.includes(:project).where("projects.project_type=? AND projects.is_public = ?", 1, 1).
|
2014-01-13 21:24:01 +08:00
|
|
|
reorder("#{Attachment.table_name}.downloads DESC").
|
|
|
|
limit(LIMIT)
|
2014-01-13 16:24:13 +08:00
|
|
|
@homeworks_attach = Attachment.where("container_type = 'HomeworkAttach'").
|
|
|
|
reorder("created_on DESC").
|
|
|
|
limit(LIMIT)
|
|
|
|
@memos_attach = Attachment.where("container_type = 'Memo'").
|
|
|
|
reorder("created_on DESC").
|
|
|
|
limit(LIMIT)
|
2014-01-13 20:26:40 +08:00
|
|
|
@attach_array = Array.new
|
|
|
|
@attach_array.push(@projects_attach, @courses_attach, @homeworks_attach, @memos_attach)
|
2014-01-10 09:18:09 +08:00
|
|
|
end
|
2014-01-11 09:08:15 +08:00
|
|
|
|
2014-01-13 16:34:24 +08:00
|
|
|
private
|
2014-01-13 20:26:40 +08:00
|
|
|
|
2014-01-13 16:34:24 +08:00
|
|
|
def project_classification project_type=0
|
2014-01-13 21:24:01 +08:00
|
|
|
pro_attach = Attachment.joins("LEFT JOIN projects ON attachments.container_id = projects.id").
|
2014-01-13 21:02:45 +08:00
|
|
|
where("projects.project_type=#{project_type}").
|
2014-01-13 21:24:01 +08:00
|
|
|
reorder("downloads DESC").
|
2014-01-13 21:02:45 +08:00
|
|
|
limit(LIMIT)
|
2014-01-13 21:24:01 +08:00
|
|
|
doc_attach = join_tools_project "documents", project_type
|
|
|
|
issue_attach = join_tools_project "issues", project_type
|
|
|
|
mess_attach = []#join_tools_project "messages", project_type
|
|
|
|
news_attach = join_tools_project "news", project_type
|
|
|
|
vers_attach = join_tools_project "versions", project_type
|
|
|
|
wiki_attach = []#join_tools_project "wiki_pages", project_type
|
2014-01-13 20:26:40 +08:00
|
|
|
|
2014-01-13 21:02:45 +08:00
|
|
|
tmp = pro_attach+doc_attach+issue_attach+mess_attach+news_attach+vers_attach+wiki_attach
|
|
|
|
tmp.sort { |a, b| b.downloads <=> a.downloads }
|
2014-01-13 20:26:40 +08:00
|
|
|
end
|
|
|
|
def join_tools_project tableName, project_type=0
|
2014-01-13 21:02:45 +08:00
|
|
|
Attachment.joins(str_join_table(tableName)).
|
|
|
|
where("projects.project_type=#{project_type}").
|
|
|
|
reorder('downloads DESC').
|
|
|
|
limit(LIMIT)
|
2014-01-13 16:34:24 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def str_join_table tableName
|
|
|
|
str = "LEFT JOIN #{tableName} ON attachments.container_id = #{tableName}.id
|
|
|
|
LEFT JOIN projects ON #{tableName}.project_id = projects.id"
|
|
|
|
str
|
|
|
|
end
|
2014-01-10 09:18:09 +08:00
|
|
|
end
|