79 lines
3.0 KiB
Ruby
79 lines
3.0 KiB
Ruby
# encoding: utf-8
|
|
# Trustie - education management software
|
|
# Copyright (C) 2013-2014
|
|
class StoresController < ApplicationController
|
|
layout 'base_stores'
|
|
|
|
def search
|
|
name = params[:name] ||= ''
|
|
redirect_to stores_path, :notice => l(:field_course_un) if name.blank?
|
|
# 按文件名搜索
|
|
result = Attachment.where("attachments.container_type IS NOT NULL AND filename LIKE '%" + name + "%' ").
|
|
reorder("created_on DESC")
|
|
result = result.to_a
|
|
result.map { |res|
|
|
if(res.container.nil? ||
|
|
(res.container.class.to_s.eql?("Project") && res.container.is_public == false) ||
|
|
(res.container.class.to_s.eql?("HomeworkAttach") && res.container.bid.reward_type == 3) ||
|
|
false
|
|
)
|
|
result.delete(res)
|
|
end
|
|
}
|
|
@searched_attach = paginateHelper result
|
|
end
|
|
|
|
LIMIT = 12 unless const_defined?(:LIMIT)
|
|
def index
|
|
@projects_attach = Attachment.includes(:project).where("projects.project_type=? AND projects.is_public = ?", 0, 1).
|
|
reorder("#{Attachment.table_name}.downloads DESC").
|
|
limit(LIMIT)
|
|
|
|
@courses_attach = Attachment.includes(:project).where("projects.project_type=? AND projects.is_public = ?", 1, 1).
|
|
reorder("#{Attachment.table_name}.downloads DESC").
|
|
limit(LIMIT)
|
|
@homeworks_attach = Attachment.where("container_type = 'HomeworkAttach'").
|
|
reorder("downloads DESC").
|
|
limit(LIMIT)
|
|
@memos_attach = Attachment.where("container_type = 'Memo'").
|
|
reorder("downloads DESC").
|
|
limit(LIMIT)
|
|
@attach_array = Array.new
|
|
@attach_array.push(@projects_attach, @courses_attach, @homeworks_attach, @memos_attach)
|
|
@str_arr = [ l(:label_project_deposit),
|
|
l(:label_course_practice),
|
|
l(:label_contest_innovate),
|
|
l(:label_forum) ]
|
|
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}").
|
|
reorder("downloads DESC").
|
|
limit(LIMIT)
|
|
doc_attach = join_tools_project Document, project_type
|
|
issue_attach = join_tools_project Issue, project_type
|
|
mess_attach = []
|
|
news_attach = join_tools_project News"news", project_type
|
|
vers_attach = join_tools_project Version"versions", project_type
|
|
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}").
|
|
reorder('downloads DESC').
|
|
limit(LIMIT)
|
|
end
|
|
|
|
def str_join_table tableClass
|
|
str = "LEFT JOIN #{tableClass.table_name} ON attachments.container_id = #{tableClass.table_name}.id
|
|
LEFT JOIN projects ON #{tableClass.table_name}.project_id = projects.id"
|
|
str
|
|
end
|
|
end
|