diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index 25bb31cbb..2d0eb2b6c 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -371,15 +371,30 @@ class AttachmentsController < ApplicationController @obj = c @save_flag = attach_copied_obj.save @save_message = attach_copied_obj.errors.full_messages + update_quotes attach_copied_obj end respond_to do |format| format.js end - rescue NoMethodError - @save_flag = false - @save_message = [] << l(:label_course_empty_select) - respond_to do |format| - format.js + #rescue NoMethodError + # @save_flag = false + # @save_message = [] << l(:label_course_empty_select) + # respond_to do |format| + # format.js + # end + end + + def update_quotes attachment + if attachment.copy_from + attachments = Attachment.find_by_sql("select * from attachments where copy_from = #{attachment.copy_from} or id = #{attachment.copy_from}") + else + attachments = Attachment.find_by_sql("select * from attachments where copy_from = #{attachment.id} or id = #{attachment.copy_from}") + end + attachment.quotes = get_qute_number attachment + attachment.save + attachments.each do |att| + att.quotes = attachment.quotes + att.save end end diff --git a/app/controllers/files_controller.rb b/app/controllers/files_controller.rb index c20b5a0de..320c8fc93 100644 --- a/app/controllers/files_controller.rb +++ b/app/controllers/files_controller.rb @@ -171,6 +171,8 @@ class FilesController < ApplicationController attribute = "downloads" when "created_on" attribute = "created_on" + when "quotes" + attribute = "quotes" end @sort = order_by[0] @order = order_by[1] @@ -391,14 +393,14 @@ class FilesController < ApplicationController end end - # show_attachments @containers - # @attachtype = params[:type].to_i - # @contenttype = params[:contentType].to_s - # - # respond_to do |format| - # format.js - # format.html - # end + show_attachments @containers + @attachtype = params[:type].to_i + @contenttype = params[:contentType].to_s + + respond_to do |format| + format.js + format.html + end end end diff --git a/app/helpers/attachments_helper.rb b/app/helpers/attachments_helper.rb index 52002b028..50dd79a08 100644 --- a/app/helpers/attachments_helper.rb +++ b/app/helpers/attachments_helper.rb @@ -76,6 +76,19 @@ module AttachmentsHelper false end + def get_qute_number attachment + if attachment.copy_from + result = Attachment.find_by_sql("select count(*) as number from attachments where copy_from = #{attachment.copy_from}") + else + result = Attachment.find_by_sql("select count(*) as number from attachments where copy_from = #{attachment.id}") + end + if result.nil? || result.count <= 0 + return 0 + else + return result[0].number + end + end + private def deletable? container, user=User.current diff --git a/app/helpers/files_helper.rb b/app/helpers/files_helper.rb index e1aebefdc..5683b9a05 100644 --- a/app/helpers/files_helper.rb +++ b/app/helpers/files_helper.rb @@ -114,16 +114,5 @@ module FilesHelper end - def get_qute_number attachment - if attachment.copy_from - result = Attachment.find_by_sql("select count(*) as number from attachments where copy_from = #{attachment.copy_from}") - else - result = Attachment.find_by_sql("select count(*) as number from attachments where copy_from = #{attachment.id}") - end - if result.nil? || result.count <= 0 - return 0 - else - return result[0].number - end - end + end \ No newline at end of file diff --git a/app/views/files/_course_list.html.erb b/app/views/files/_course_list.html.erb index 02dc816b2..58fbcb2e9 100644 --- a/app/views/files/_course_list.html.erb +++ b/app/views/files/_course_list.html.erb @@ -4,12 +4,12 @@

<% if order == "asc" %> 按 <%= link_to "时间",params.merge(:sort=>"created_on:desc"),:class => "f_b c_grey",:remote => @is_remote %><%= render partial: 'arrow_show',locals: { sort: sort,order:order,current:"created_on"} %> /  - <%= link_to "下载次数",params.merge(:sort=>"downloads:desc"),:class => "f_b c_grey",:remote => @is_remote %><%= render partial: 'arrow_show',locals: { sort: sort,order:order,current:"downloads"} %> 排序 + <%= link_to "下载次数",params.merge(:sort=>"downloads:desc"),:class => "f_b c_grey",:remote => @is_remote %><%= render partial: 'arrow_show',locals: { sort: sort,order:order,current:"downloads"} %> /  + <%= link_to "引用次数",params.merge(:sort=>"quotes:desc"),:class => "f_b c_grey",:remote => @is_remote %><%= render partial: 'arrow_show',locals: { sort: sort,order:order,current:"quotes"} %> 排序 <% else %> 按 <%= link_to "时间",params.merge(:sort=>"created_on:asc"),:class => "f_b c_grey" ,:remote => @is_remote %><%= render partial: 'arrow_show',locals: { sort: sort,order:order,current:"created_on"} %> /  - <%= link_to "下载次数",params.merge(:sort=>"downloads:asc"),:class => "f_b c_grey",:remote => @is_remote %><%= render partial: 'arrow_show',locals: { sort: sort,order:order,current:"downloads"} %> 排序 + <%= link_to "下载次数",params.merge(:sort=>"downloads:asc"),:class => "f_b c_grey",:remote => @is_remote %><%= render partial: 'arrow_show',locals: { sort: sort,order:order,current:"downloads"} %>  /  + <%= link_to "引用次数",params.merge(:sort=>"quotes:asc"),:class => "f_b c_grey",:remote => @is_remote %><%= render partial: 'arrow_show',locals: { sort: sort,order:order,current:"quotes"} %> 排序 <% end %>

@@ -40,7 +40,7 @@

文件大小:<%= number_to_human_size(file.filesize) %>

<%= link_to( l(:button_delete), attachment_path(file), :data => {:confirm => l(:text_are_you_sure)}, :method => :delete,:class => "f_r re_de") if delete_allowed && file.container_id == @course.id && file.container_type == "Course"%> -

<%= time_tag(file.created_on).html_safe %><%= l(:label_bids_published_ago) %>  |  下载<%= file.downloads %>  |  引用<%= get_qute_number file %>

+

<%= time_tag(file.created_on).html_safe %><%= l(:label_bids_published_ago) %>  |  下载<%= file.downloads %>  |  引用<%= file.quotes.nil? ? 0:file.quotes %>

diff --git a/db/migrate/20141201085218_add_qutoes_to_attachments.rb b/db/migrate/20141201085218_add_qutoes_to_attachments.rb new file mode 100644 index 000000000..95a284ab6 --- /dev/null +++ b/db/migrate/20141201085218_add_qutoes_to_attachments.rb @@ -0,0 +1,5 @@ +class AddQutoesToAttachments < ActiveRecord::Migration + def change + add_column("attachments","quotes",:integer) + end +end diff --git a/db/schema.rb b/db/schema.rb index 4baec2343..883dd74c5 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20141127072548) do +ActiveRecord::Schema.define(:version => 20141201085218) do create_table "activities", :force => true do |t| t.integer "act_id", :null => false @@ -53,6 +53,7 @@ ActiveRecord::Schema.define(:version => 20141127072548) do t.integer "attachtype", :default => 1 t.integer "is_public", :default => 1 t.integer "copy_from" + t.integer "quotes" end add_index "attachments", ["author_id"], :name => "index_attachments_on_author_id"