You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

stores_controller.rb 5.2 kB

13 years ago
​
​
​
13 years ago
​
13 years ago
12 years ago
​
​
​
​
​
​
​
​
​
​
13 years ago
​
​
​
​
​
​
​
​
​
​
12 years ago
13 years ago
​
​
​
​
​
​
13 years ago
​
​
​
​
​
​
​
​
​
13 years ago
13 years ago
​
13 years ago
​
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
​
​
​
​
13 years ago
​
​
​
13 years ago
​
13 years ago
13 years ago
​
13 years ago
13 years ago
​
13 years ago
​
13 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
13 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. # encoding: utf-8
  2. # Trustie - education management software
  3. # Copyright (C) 2013-2014
  4. class StoresController < ApplicationController
  5. layout 'base_stores'
  6. def search
  7. name = params[:name] ||= ''
  8. (redirect_to stores_path, :notice => l(:label_sumbit_empty);return) if name.blank?
  9. result = find_public_attache name
  10. @searched_attach = paginateHelper result
  11. @result_all_count = result.count;
  12. end
  13. def find_public_attache keywords
  14. # StoresController#search 将每条文件都查出来,再次进行判断过滤。---> resultSet.to_a.map
  15. # 此时内容不多速度还可,但文件增长,每条判断多则进行3-4次表连接。
  16. # 现在还木有思路 药丸
  17. resultSet = Attachment.where("attachments.container_type IS NOT NULL AND filename LIKE :like ", like: "%#{keywords}%").
  18. reorder("created_on DESC")
  19. result = resultSet.to_a.dup
  20. resultSet.to_a.map { |res|
  21. if(res.container.nil? ||
  22. (res.container.class.to_s=="Project" && res.container.is_public == false) ||
  23. (res.container.has_attribute?(:project) && res.container.project.is_public == false) ||
  24. (res.container.class.to_s=="HomeworkAttach" && res.container.bid.reward_type == 3) ||
  25. false
  26. )
  27. result.delete(res)
  28. end
  29. }
  30. result
  31. end
  32. LIMIT = 12 unless const_defined?(:LIMIT)
  33. def index
  34. @projects_attach = project_classification(0).take(LIMIT)
  35. @courses_attach = project_classification(1).take(LIMIT)
  36. # @projects_attach = Attachment.includes(:project).where("projects.project_type=? AND projects.is_public = ?", 0, 1).
  37. # reorder("#{Attachment.table_name}.downloads DESC").
  38. # limit(LIMIT)
  39. # @courses_attach = Attachment.includes(:project).where("projects.project_type=? AND projects.is_public = ?", 1, 1).
  40. # reorder("#{Attachment.table_name}.downloads DESC").
  41. # limit(LIMIT)
  42. # 悲剧 下面竞赛里没文件
  43. # @homeworks_attach = Attachment.
  44. # joins("LEFT JOIN homework_attaches ON homework_attaches.id=attachments.container_id
  45. # LEFT JOIN bids ON homework_attaches.bid_id=bids.id").
  46. # where("container_type = 'HomeworkAttach' AND bids.reward_type <> 3").
  47. # reorder("downloads DESC").
  48. # limit(LIMIT)
  49. @homeworks_attach = join_tools_project Message, 0
  50. @memos_attach = Attachment.where("container_type = 'Memo'").
  51. reorder("downloads DESC").
  52. limit(LIMIT)
  53. @attach_array = Array.new
  54. @attach_array.push(@projects_attach, @courses_attach, @homeworks_attach, @memos_attach)
  55. @str_arr = [ l(:label_project_deposit),
  56. l(:label_course_practice),
  57. l(:label_borad_project), #l(:label_contest_innovate),
  58. l(:label_forum) ]
  59. end
  60. private
  61. def project_classification project_type=0
  62. # pro_attach = Attachment.joins("LEFT JOIN projects ON attachments.container_id = projects.id").
  63. # where("attachments.container_type='Project' AND projects.is_public=1 AND projects.project_type=#{project_type}").
  64. # reorder("downloads DESC").
  65. # limit(LIMIT)
  66. pro_attach = join_tools_project Project, project_type
  67. doc_attach = join_tools_project Document, project_type
  68. issue_attach = join_tools_project Issue, project_type
  69. mess_attach = []#join_tools_project Message, project_type
  70. news_attach = join_tools_project News, project_type
  71. vers_attach = join_tools_project Version, project_type
  72. wiki_attach = join_tools_project WikiPage, project_type
  73. tmp = pro_attach
  74. tmp = pro_attach+doc_attach+issue_attach+mess_attach+news_attach+vers_attach+wiki_attach
  75. tmp.sort { |a, b| b.downloads <=> a.downloads }
  76. end
  77. def join_tools_project tableName, project_type=0
  78. Attachment.joins(str_join_table(tableName)).
  79. where("attachments.container_type='#{tableName.to_s}' AND projects.is_public=1 AND projects.project_type=#{project_type}").
  80. reorder('downloads DESC').
  81. limit(LIMIT)
  82. end
  83. def str_join_table tableClass
  84. case tableClass.to_s
  85. when 'Project'
  86. "LEFT JOIN projects ON attachments.container_id = projects.id"
  87. when 'Document', 'Issue', 'Version', 'News' # 连接子表即有 project_id 字段,即两层连接
  88. "LEFT JOIN #{tableClass.table_name} ON attachments.container_id = #{tableClass.table_name}.id
  89. LEFT JOIN projects ON #{tableClass.table_name}.project_id = projects.id"
  90. when 'Message' # 三层连接
  91. "LEFT JOIN #{tableClass.table_name} ON attachments.container_id = #{tableClass.table_name}.id
  92. LEFT JOIN boards ON boards.id = #{tableClass.table_name}.board_id
  93. LEFT JOIN projects ON boards.project_id = projects.id"
  94. when 'WikiPage'# 三层连接
  95. "LEFT JOIN #{tableClass.table_name} ON attachments.container_id = #{tableClass.table_name}.id
  96. LEFT JOIN wikis ON wikis.id = #{tableClass.table_name}.wiki_id
  97. LEFT JOIN projects ON wikis.project_id = projects.id"
  98. else
  99. end
  100. end
  101. end

软件技术创新是当今国家整体创新能力的重要基础和发展引擎。近年来,大众参与的软件创新与创业活动已经成为网络时代软件开发和应用的新形态,正在快速改变着全球软件创新模式和软件产业格局。 ...