bigdir/app/controllers/stores_controller.rb

54 lines
2.2 KiB
Ruby

# 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
LIMIT = 20 unless const_defined?(:LIMIT)
def index
@projects_attach = project_classification(0).take(LIMIT)
@courses_attach = project_classification(1).take(LIMIT)
# @projects_attach = Attachment.includes(:projects).where("projects.project_type=?", 0).
# 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)
@memos_attach = Attachment.where("container_type = 'Memo'").
reorder("created_on DESC").
limit(LIMIT)
@attach_array = Array.new
@attach_array.push(@projects_attach, @courses_attach, @homeworks_attach, @memos_attach)
end
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}")
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
pro_attach+doc_attach+issue_attach+mess_attach+news_attach+vers_attach+wiki_attach
end
def join_tools_project tableName, project_type=0
Attachment.joins(str_join_table(tableName)).where("projects.project_type=#{project_type}")
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
end