diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 2862bcf11..72e9c1728 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -407,17 +407,11 @@ class CoursesController < ApplicationController @course_count = @courses_all.count @course_pages = Paginator.new @course_count, per_page_option, params['page'] - #gcm activity count - @course_activity_count=Hash.new - #count initialize @courses_all.each do |course| @course_activity_count[course.id]=0 end - #@course_activity_count=get_course_activity @courses_all,@course_activity_count - #gcm end - case params[:course_sort_type] when '0' @@ -425,34 +419,23 @@ class CoursesController < ApplicationController @s_type = 0 @courses = @courses.offset(@course_pages.offset).limit(@course_pages.per_page) - #gcm - @course_activity_count=get_course_activity @courses, @course_activity_count - #gcmend - + @course_activity_count=get_course_activity @courses, @course_activity_count when '1' @courses = @courses_all.order("course_ac_para desc") @s_type = 1 @courses = @courses.offset(@course_pages.offset).limit(@course_pages.per_page) - #gcm @course_activity_count=get_course_activity @courses, @course_activity_count - #gcmend - when '2' @courses = @courses_all.order("watchers_count desc") @s_type = 2 @courses = @courses.offset(@course_pages.offset).limit(@course_pages.per_page) - #gcm @course_activity_count=get_course_activity @courses, @course_activity_count - #gcmend - #gcm when '3' - #gcm @course_activity_count=get_course_activity @courses_all, @course_activity_count - #gcmend @courses=handle_course @courses_all, @course_activity_count @@ -463,10 +446,7 @@ class CoursesController < ApplicationController @courses = @courses_all.order("created_at desc") @courses = @courses.offset(@course_pages.offset).limit(@course_pages.per_page) - #gcm @course_activity_count=get_course_activity @courses, @course_activity_count - #gcmend - end respond_to do |format| @@ -607,10 +587,9 @@ class CoursesController < ApplicationController has = { "show_course_files" => true, - "show_messages" => true, + "show_course_messages" => true, "show_bids" => true, - "show_contests" => true, - "show_journals_for_messages" => true + "show_course_journals_for_messages" => true } @date_to ||= Date.today + 1 @date_from = @date_to - @days-1.years diff --git a/app/models/course_journals_for_message.rb b/app/models/course_journals_for_message.rb deleted file mode 100644 index 32bf8ffac..000000000 --- a/app/models/course_journals_for_message.rb +++ /dev/null @@ -1,109 +0,0 @@ -# nwb -# 课程与项目分离后的处理留言类 -class CourseJournalsForMessage < ActiveRecord::Base - self.table_name = "#{table_name_prefix}journals_for_messages#{table_name_suffix}" - include Redmine::SafeAttributes - safe_attributes "jour_type", # 留言所属类型 - "jour_id", # 留言所属类型的id - "notes", # 留言内容 - "reply_id", # 留言被回复留言者的用户id(用户a回复了用户b,这是b的id,用以查询谁给b留言了) - "status", # 留言是否被查看(弃用) - "user_id", # 留言者的id - "m_parent_id", # 留言信息的父留言id - "is_readed", # 留言是否已读 - "m_reply_count", # 留言的回复数量 - "m_reply_id" # 回复某留言的留言id(a留言回复了b留言,这是b留言的id) - acts_as_tree :foreign_key => 'm_parent_id', :counter_cache => :m_reply_count, :order => "#{JournalsForMessage.table_name}.created_on ASC" - - belongs_to :project, - :foreign_key => 'jour_id', - :conditions => "#{self.table_name}.jour_type = 'Project' " - belongs_to :course, - :foreign_key => 'jour_id', - :conditions => "#{self.table_name}.jour_type = 'Course' " - - belongs_to :jour, :polymorphic => true - belongs_to :user - belongs_to :homework_attach - belongs_to :at_user, :class_name => "User", :foreign_key => 'reply_id' - - acts_as_event :title => Proc.new {|o| "#{l(:label_my_message)}"}, - :datetime => Proc.new {|o| o.updated_on }, - :author => Proc.new {|o| o.user }, - :description => Proc.new{|o| o.notes }, - :type => Proc.new {|o| o.jour_type }, - :url => Proc.new {|o| - (o.jour.kind_of? Project) ? {:controller => 'projects', :action => 'feedback', :id => o.jour, :r => o.id, :anchor => "word_li_#{o.id}"} : {} - }#{:controller => 'documents', :action => 'show', :id => o.id}} - acts_as_activity_provider :author_key => :user_id, - :timestamp => "#{self.table_name}.updated_on", - :find_options => {:include => :course } - - - has_many :acts, :class_name => 'Activity', :as => :act, :dependent => :destroy - - validates :notes, presence: true - after_create :act_as_activity #huang - after_create :reset_counters! - after_destroy :reset_counters! - - # default_scope { where('m_parent_id IS NULL') } - - def self.create_by_user? user - if user.anonymous? - return false - else - return true - end - end - - def self.remove_by_user? user - if( self.user == user || - ( self.jour.kind_of?(User) && self.jour== user ) - ) - true - else - false - end - end - - def self.delete_message(message_id) - self.find(message_id).destroy - # self.destroy_all "id = #{message_id}" - end - - def reference_user - User.find(reply_id) - end - - def self.reference_message(user_id) - @user = User.find(user_id) - message = JournalsForMessage.find_by_sql("select * from journals_for_messages where reply_id = #{@user.id} - or (jour_type = 'Bid' and jour_id in (select id from bids where author_id = #{@user.id}))") - message - end - - - def act_as_activity - if self.jour_type == 'Principal' - unless self.user_id == self.jour.id && self.user_id != self.reply_id && self.reply_id != 0 - # self.acts << Activity.new(:user_id => self.user_id) - self.acts << Activity.new(:user_id => self.jour_id) - end - elsif self.jour_type == 'Project' - self.acts << Activity.new(:user_id => self.reply_id) - elsif self.jour_type == 'Course' - self.acts << Activity.new(:user_id => self.reply_id) - else - end - end - - def reset_counters! - self.class.reset_counters!(self) - end - def self.reset_counters! journals_for_messages - # jfm_id = journals_for_messages.id.to_i - count = find_all_by_m_parent_id(journals_for_messages.m_parent_id).count #(SELECT COUNT(*) FROM #{JournalsForMessage.table_name} WHERE m_parent_id = #{jfm_id} ) - update_all("m_reply_count = #{count.to_i}", ["id = ?", journals_for_messages.m_parent_id]) - end -end diff --git a/app/models/journals_for_message.rb b/app/models/journals_for_message.rb index ac7023678..082165f11 100644 --- a/app/models/journals_for_message.rb +++ b/app/models/journals_for_message.rb @@ -39,6 +39,11 @@ class JournalsForMessage < ActiveRecord::Base :timestamp => "#{self.table_name}.updated_on", :find_options => {:include => :project } + acts_as_activity_provider :type => 'course_journals_for_messages', + :author_key => :user_id, + :timestamp => "#{self.table_name}.updated_on", + :find_options => {:include => :course } + has_many :acts, :class_name => 'Activity', :as => :act, :dependent => :destroy diff --git a/app/models/message.rb b/app/models/message.rb index 952244d56..945f47c2f 100644 --- a/app/models/message.rb +++ b/app/models/message.rb @@ -47,6 +47,7 @@ class Message < ActiveRecord::Base acts_as_activity_provider :find_options => {:include => [{:board => :project}, :author]}, :author_key => :author_id acts_as_activity_provider :find_options => {:include => [{:board => :course}, :author]}, + :type => 'course_messages', :author_key => :author_id acts_as_watchable diff --git a/lib/redmine.rb b/lib/redmine.rb index 4550dd49e..9bd8547f0 100644 --- a/lib/redmine.rb +++ b/lib/redmine.rb @@ -438,8 +438,9 @@ Redmine::Activity.map do |activity| activity.register :journals_for_messages # end #added by nwb - #activity.register :course_journals_for_messages + activity.register :course_journals_for_messages , :class_name => 'JournalsForMessage' activity.register :course_news, :class_name => 'News' + activity.register :course_messages, :default => false, :class_name => 'Message' end Redmine::Search.map do |search|