socialforge/app/controllers/stores_controller.rb

79 lines
3.0 KiB
Ruby
Raw Normal View History

2014-01-15 17:28:53 +08:00
# encoding: utf-8
# Trustie - education management software
# Copyright (C) 2013-2014
class StoresController < ApplicationController
layout 'base_stores'
2014-01-14 15:01:11 +08:00
def search
2014-01-14 17:21:27 +08:00
name = params[:name] ||= ''
2014-01-15 20:06:49 +08:00
redirect_to stores_path, :notice => l(:field_course_un) if name.blank?
2014-01-14 20:48:43 +08:00
# 按文件名搜索
2014-01-15 10:40:37 +08:00
result = Attachment.where("attachments.container_type IS NOT NULL AND filename LIKE '%" + name + "%' ").
reorder("created_on DESC")
result = result.to_a
2014-01-15 20:06:49 +08:00
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
}
2014-01-15 14:28:36 +08:00
@searched_attach = paginateHelper result
2014-01-14 15:01:11 +08:00
end
LIMIT = 12 unless const_defined?(:LIMIT)
def index
@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
@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'").
2014-01-15 20:06:49 +08:00
reorder("downloads DESC").
2014-01-13 16:24:13 +08:00
limit(LIMIT)
@memos_attach = Attachment.where("container_type = 'Memo'").
2014-01-15 20:06:49 +08:00
reorder("downloads DESC").
2014-01-13 16:24:13 +08:00
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-14 15:41:56 +08:00
@str_arr = [ l(:label_project_deposit),
l(:label_course_practice),
l(:label_contest_innovate),
l(:label_forum) ]
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-14 20:48:43 +08:00
doc_attach = join_tools_project Document, project_type
issue_attach = join_tools_project Issue, project_type
2014-01-15 20:38:58 +08:00
mess_attach = []
2014-01-14 20:48:43 +08:00
news_attach = join_tools_project News"news", project_type
vers_attach = join_tools_project Version"versions", project_type
2014-01-15 20:38:58 +08:00
wiki_attach = []
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
2014-01-14 20:48:43 +08:00
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"
2014-01-13 16:34:24 +08:00
str
end
end