course_group
sw 11 years ago
commit f934824175

@ -371,6 +371,7 @@ class AttachmentsController < ApplicationController
@obj = c @obj = c
@save_flag = attach_copied_obj.save @save_flag = attach_copied_obj.save
@save_message = attach_copied_obj.errors.full_messages @save_message = attach_copied_obj.errors.full_messages
update_quotes attach_copied_obj
end end
respond_to do |format| respond_to do |format|
format.js format.js
@ -383,6 +384,20 @@ class AttachmentsController < ApplicationController
end end
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
private private
def find_project def find_project
@attachment = Attachment.find(params[:id]) @attachment = Attachment.find(params[:id])

@ -93,7 +93,7 @@ class FilesController < ApplicationController
if sort == "" if sort == ""
sort = "created_on DESC" sort = "created_on DESC"
end end
resultSet = Attachment.where("attachments.container_type IS NOT NULL AND filename LIKE :like ", like: "%#{keywords}%"). resultSet = Attachment.where("attachments.container_type IS NOT NULL AND attachments.copy_from IS NULL AND filename LIKE :like ", like: "%#{keywords}%").
reorder(sort) reorder(sort)
end end
@ -171,6 +171,8 @@ class FilesController < ApplicationController
attribute = "downloads" attribute = "downloads"
when "created_on" when "created_on"
attribute = "created_on" attribute = "created_on"
when "quotes"
attribute = "quotes"
end end
@sort = order_by[0] @sort = order_by[0]
@order = order_by[1] @order = order_by[1]
@ -391,14 +393,14 @@ class FilesController < ApplicationController
end end
end end
# show_attachments @containers show_attachments @containers
# @attachtype = params[:type].to_i @attachtype = params[:type].to_i
# @contenttype = params[:contentType].to_s @contenttype = params[:contentType].to_s
#
# respond_to do |format| respond_to do |format|
# format.js format.js
# format.html format.html
# end end
end end
end end

@ -76,6 +76,19 @@ module AttachmentsHelper
false false
end 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 private
def deletable? container, user=User.current def deletable? container, user=User.current

@ -114,16 +114,5 @@ module FilesHelper
end 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 end

@ -7,7 +7,7 @@ class Course < ActiveRecord::Base
STATUS_ARCHIVED = 9 STATUS_ARCHIVED = 9
attr_accessible :code, :extra, :name, :state, :tea_id, :time , :location, :state, :term, :password,:is_public,:description,:class_period, :open_student attr_accessible :code, :extra, :name, :state, :tea_id, :time , :location, :state, :term, :password,:is_public,:description,:class_period, :open_student
belongs_to :project, :class_name => 'Course', :foreign_key => :extra, primary_key: :identifier #belongs_to :project, :class_name => 'Course', :foreign_key => :extra, primary_key: :identifier
belongs_to :teacher, :class_name => 'User', :foreign_key => :tea_id # 定义一个方法teacher该方法通过tea_id来调用User表 belongs_to :teacher, :class_name => 'User', :foreign_key => :tea_id # 定义一个方法teacher该方法通过tea_id来调用User表
belongs_to :school, :class_name => 'School', :foreign_key => :school_id #定义一个方法school该方法通过school_id来调用School表 belongs_to :school, :class_name => 'School', :foreign_key => :school_id #定义一个方法school该方法通过school_id来调用School表
has_many :bid has_many :bid
@ -31,7 +31,7 @@ class Course < ActiveRecord::Base
acts_as_taggable acts_as_taggable
acts_as_nested_set :order => 'name', :dependent => :destroy acts_as_nested_set :order => 'name', :dependent => :destroy
acts_as_attachable :view_permission => :view_files, acts_as_attachable :view_permission => :view_course_files,
:delete_permission => :manage_files :delete_permission => :manage_files
validates_presence_of :password, :term,:name,:description validates_presence_of :password, :term,:name,:description

@ -4,12 +4,12 @@
<p class="f_r" style="color: #808080"> <p class="f_r" style="color: #808080">
<% if order == "asc" %> <% if order == "asc" %>
按&nbsp;<%= 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"} %>&nbsp;/&nbsp; 按&nbsp;<%= 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"} %>&nbsp;/&nbsp;
<%= 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"} %>&nbsp;<!-- /&nbsp; <%= 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"} %>&nbsp;/&nbsp;
<a href="#" class="f_b c_grey">引用次数</a>&nbsp;-->排序 <%= 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"} %>&nbsp;排序
<% else %> <% else %>
按&nbsp;<%= 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"} %>&nbsp;/&nbsp; 按&nbsp;<%= 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"} %>&nbsp;/&nbsp;
<%= 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"} %>&nbsp;<!-- /&nbsp; <%= 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"} %>&nbsp; /&nbsp;
<a href="#" class="f_b c_grey">引用次数</a>&nbsp;-->排序 <%= 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"} %>&nbsp;排序
<% end %> <% end %>
</p> </p>
</div> </div>
@ -40,7 +40,7 @@
<p class="f_l c_grey02 font">文件大小:<%= number_to_human_size(file.filesize) %></p> <p class="f_l c_grey02 font">文件大小:<%= number_to_human_size(file.filesize) %></p>
<%= link_to( l(:button_delete), attachment_path(file), <%= 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"%> :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"%>
<p class="f_r c_grey02" ><%= time_tag(file.created_on).html_safe %><%= l(:label_bids_published_ago) %>&nbsp;&nbsp;|&nbsp;&nbsp;下载<%= file.downloads %>&nbsp;&nbsp;|&nbsp;&nbsp;引用<%= get_qute_number file %> </p> <p class="f_r c_grey02" ><%= time_tag(file.created_on).html_safe %><%= l(:label_bids_published_ago) %>&nbsp;&nbsp;|&nbsp;&nbsp;下载<%= file.downloads %>&nbsp;&nbsp;|&nbsp;&nbsp;引用<%= file.quotes.nil? ? 0:file.quotes %> </p>
</div> </div>
<div class="cl"></div> <div class="cl"></div>
<div class="tag_h"> <div class="tag_h">

@ -0,0 +1,5 @@
class AddQutoesToAttachments < ActiveRecord::Migration
def change
add_column("attachments","quotes",:integer)
end
end

@ -11,7 +11,7 @@
# #
# It's strongly recommended to check this file into your version control system. # 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| create_table "activities", :force => true do |t|
t.integer "act_id", :null => false t.integer "act_id", :null => false
@ -53,6 +53,7 @@ ActiveRecord::Schema.define(:version => 20141127072548) do
t.integer "attachtype", :default => 1 t.integer "attachtype", :default => 1
t.integer "is_public", :default => 1 t.integer "is_public", :default => 1
t.integer "copy_from" t.integer "copy_from"
t.integer "quotes"
end end
add_index "attachments", ["author_id"], :name => "index_attachments_on_author_id" add_index "attachments", ["author_id"], :name => "index_attachments_on_author_id"

@ -46,6 +46,9 @@ module Redmine
if self.respond_to?(:project) if self.respond_to?(:project)
(respond_to?(:visible?) ? visible?(user) : true) && (respond_to?(:visible?) ? visible?(user) : true) &&
user.allowed_to?(self.class.attachable_options[:view_permission], self.project) user.allowed_to?(self.class.attachable_options[:view_permission], self.project)
elsif self.is_a?(Course)
(respond_to?(:visible?) ? visible?(user) : true) &&
user.allowed_to?(self.class.attachable_options[:view_permission], self)
else else
return true return true
end end

Loading…
Cancel
Save