diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 969d2d366..1748c5a07 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -97,37 +97,83 @@ class UsersController < ApplicationController end # 用户消息 + # 说明: homework 发布作业;message:讨论区; news:新闻; poll:问卷;works_reviewers:作品评阅;works_reply:作品回复 + # issue:问题;journal:缺陷状态更新; forum:公共贴吧: user_feedback: 用户留言; new_reply:新闻回复(comment) def user_messages unless User.current.logged? render_403 return end # 当前用户查看消息,则设置消息为已读 - querys = @user.course_messages + course_querys = @user.course_messages + forge_querys = @user.forge_messages + user_querys = @user.user_feedback_messages + forum_querys = @user.memo_messages if User.current.id == @user.id - querys.update_all(:viewed => true) + course_querys.update_all(:viewed => true) + forge_querys.update_all(:viewed => true) + user_querys.update_all(:viewed => true) + forum_querys.update_all(:viewed => true) end - if @user.course_messages - if params[:type].nil? - @user_course_messages = @user.course_messages.reverse - @user_project_messges = @user.forge_messages.reverse - else - case params[:type] - when 'homework' - @user_course_messages = @user.course_messages.reverse.select{|x| x.course_message_type == "HomeworkCommon"} - #@user_course_messages = ForgeMessage.find_by_sql("select * from course_messages where user_id='#{@user.id}' and course_message_type = 'HomeworkCommon' order by created_at desc;") - when 'message' - @user_course_messages = @user.course_messages.reverse.select{|x| x.course_message_type == "Message"} - when 'news' - @user_course_messages = @user.course_messages.reverse.select{|x| x.course_message_type == "News"} - when 'poll' - @user_course_messages = @user.course_messages.reverse.select{|x| x.course_message_type == "Poll"} - end - end - respond_to do |format| - format.html{render :layout=>'base_users_new'} - format.api - end + @new_message_count = @user.forge_messages.count + @user.memo_messages.count + @user.course_messages.count + @user.user_feedback_messages.count + case params[:type] + when nil + @user_course_messages = CourseMessage.where("user_id =?",@user).order("created_at desc") + @user_forge_messages = ForgeMessage.where("user_id =?",@user).order("created_at desc") + @user_memo_messages = MemoMessage.where("user_id =?",@user).order("created_at desc") + @user_feedback_messages = UserFeedbackMessage.where("user_id =?",@user).order("created_at desc") + @user_course_messages_count = @user_course_messages.count + @user_forge_messages_count = @user_forge_messages.count + @user_memo_messages_count = @user_memo_messages.count + @user_feedback_messages_count = @user_feedback_messages.count + when 'homework' + @user_course_messages = CourseMessage.where("course_message_type =? and user_id =?", "HomeworkCommon", @user).order("created_at desc") + @user_course_messages_count = @user_course_messages.count + when 'course_message' + @user_course_messages = CourseMessage.where("course_message_type =? and user_id =?", "Message", @user).order("created_at desc") + @user_course_messages_count = @user_course_messages.count + when 'forge_message' + @user_forge_messages = ForgeMessage.where("forge_message_type =? and user_id =?", "Message", @user).order("created_at desc") + @user_forge_messages_count = @user_forge_messages.count + when 'course_news' + @user_course_messages = CourseMessage.where("course_message_type =? and user_id =?", "News", @user).order("created_at desc") + @user_course_messages_count = @user_course_messages.count + when 'forge_news' + @user_forge_messages = ForgeMessage.where("forge_message_type =? and user_id =?", "News", @user).order("created_at desc") + @user_forge_messages_count = @user_forge_messages.count + when 'course_news_reply' + @user_course_messages = CourseMessage.where("course_message_type =? and user_id =?", "Comment", @user).order("created_at desc") + @user_course_messages_count = @user_course_messages.count + when 'forge_news_reply' + @user_forge_messages = ForgeMessage.where("course_message_type =? and user_id =?", "Comment", @user).order("created_at desc") + @user_forge_messagess_count = @user_forge_messages.count + when 'poll' + @user_course_messages = CourseMessage.where("course_message_type =? and user_id =?", "Poll", @user).order("created_at desc") + @user_course_messages_count = @user_course_messages.count + when 'works_reviewers' + @user_course_messages = CourseMessage.where("course_message_type =? and user_id =?", "StudentWorksScore", @user).order("created_at desc") + @user_course_messages_count = @user_course_messages.count + when 'works_reply' + @user_course_messages = CourseMessage.where("course_message_type =? and user_id =?", "JournalsForMessage", @user).order("created_at desc") + @user_course_messages_count = @user_course_messages.count + when 'issue' + @user_forge_messages = ForgeMessage.where("forge_message_type =? and user_id =?", "Issue", @user).order("created_at desc") + @user_forge_messages_count = @user_forge_messages.count + when 'issue_update' # 缺陷状态更新、留言 + @user_forge_messages = ForgeMessage.where("forge_message_type =? and user_id =?", "Journal", @user).order("created_at desc") + @user_forge_messages_count = @user_forge_messages.count + when 'forum' + @user_memo_messages = MemoMessage.where("memo_type =? and user_id =?", "Memo", @user).order("created_at desc") + @user_memo_messages_count = @user_memo_messages.count + when 'user_feedback' + @user_feedback_messages = UserFeedbackMessage.where("journals_for_message_type =? and user_id =?", "Principal", @user).order("created_at desc") + @user_feedback_messages_count = @user_feedback_messages.count + else + render_404 + return + end + respond_to do |format| + format.html{render :layout=>'base_users_new'} end end diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb index 49865d335..48019e597 100644 --- a/app/helpers/users_helper.rb +++ b/app/helpers/users_helper.rb @@ -402,6 +402,14 @@ module UsersHelper return str.html_safe end + def get_issue_des_update(journal) + arr = details_to_strings(journal.details,true) + arr << journal.notes + str = '' + arr.each { |item| str = str+item } + return str + end + def get_activity_act_showname(activity) case activity.act_type when "HomeworkCommon" diff --git a/app/models/comment.rb b/app/models/comment.rb index a4842a23f..bb31eb894 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -21,6 +21,10 @@ class Comment < ActiveRecord::Base has_many_kindeditor_assets :assets, :dependent => :destroy has_many :ActivityNotifies,:as => :activity, :dependent => :destroy + # 课程/项目 消息 + has_many :course_messages, :class_name =>'CourseMessage', :as => :course_message, :dependent => :destroy + has_many :forge_messages, :class_name => 'ForgeMessage', :as => :forge_message, :dependent => :destroy + #end acts_as_event :datetime => :updated_on, :description => :comments, :type => 'news', @@ -31,7 +35,19 @@ class Comment < ActiveRecord::Base belongs_to :author, :class_name => 'User', :foreign_key => 'author_id' validates_presence_of :commented, :author, :comments safe_attributes 'comments' - after_create :send_mail + after_create :send_mail, :act_as_system_message + + def act_as_system_message + if self.commented.course + if self.author_id != self.commented.author_id + self.course_messages << CourseMessage.new(:user_id => self.commented.author_id, :course_id => self.commented.course.id, :viewed => false) + end + else # 项目相关 + if self.author_id != self.commented.author_id + self.forge_messages << ForgeMessage.new(:user_id => self.commented.author_id, :project_id => self.commented.project.id, :viewed => false) + end + end + end def send_mail if self.commented.is_a?(News) && Setting.notified_events.include?('news_comment_added') diff --git a/app/models/forum.rb b/app/models/forum.rb index 2af1abf9e..530639f81 100644 --- a/app/models/forum.rb +++ b/app/models/forum.rb @@ -39,6 +39,7 @@ class Forum < ActiveRecord::Base logger.debug "send mail for forum add." Mailer.run.forum_add(self) if Setting.notified_events.include?('forum_add') end + # Updates topic_count, memo_count and last_memo_id attributes for +board_id+ def self.reset_counters!(forum_id) forum_id = forum_id.to_i diff --git a/app/models/issue.rb b/app/models/issue.rb index 66627c00a..1724e3484 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -83,7 +83,7 @@ class Issue < ActiveRecord::Base # fq after_create :act_as_activity,:be_user_score_new_issue,:act_as_forge_activity, :act_as_forge_message - after_update :be_user_score + after_update :be_user_score, :act_as_forge_message_update after_destroy :down_user_score # after_create :be_user_score # end @@ -150,6 +150,15 @@ class Issue < ActiveRecord::Base :viewed => false) end end + + # 更新缺陷 + def act_as_forge_message_update + unless self.author_id == self.assigned_to_id + self.forge_messages << ForgeMessage.new(:user_id => self.assigned_to_id, + :project_id => self.project_id, + :viewed => false) + end + end # Returns a SQL conditions string used to find all issues visible by the specified user diff --git a/app/models/journal.rb b/app/models/journal.rb index c705b1a09..a5bea92af 100644 --- a/app/models/journal.rb +++ b/app/models/journal.rb @@ -171,9 +171,11 @@ class Journal < ActiveRecord::Base # 缺陷状态更改,消息提醒 def act_as_forge_message - self.forge_messages << ForgeMessage.new(:user_id => self.issue.author_id, - :project_id => self.issue.project_id, - :viewed => false) + if self.user_id != self.issue.author_id + self.forge_messages << ForgeMessage.new(:user_id => self.issue.author_id, + :project_id => self.issue.project_id, + :viewed => false) + end end # 更新用户分数 -by zjc diff --git a/app/models/journals_for_message.rb b/app/models/journals_for_message.rb index bcae58174..853376f6a 100644 --- a/app/models/journals_for_message.rb +++ b/app/models/journals_for_message.rb @@ -58,9 +58,12 @@ class JournalsForMessage < ActiveRecord::Base has_many :acts, :class_name => 'Activity', :as => :act, :dependent => :destroy # 课程动态 has_many :course_acts, :class_name => 'CourseActivity',:as =>:course_act ,:dependent => :destroy + # 消息关联 + has_many :course_messages, :class_name => 'CourseMessage',:as =>:course_message ,:dependent => :destroy + has_many :user_feedback_messages, :class_name => 'UserFeedbackMessage', :as =>:user_feeback_message, :dependent => :destroy validates :notes, presence: true, if: :is_homework_jour? - after_create :act_as_activity, :act_as_course_activity + after_create :act_as_activity, :act_as_course_activity, :act_as_course_message, :act_as_user_feedback_message after_create :reset_counters! after_destroy :reset_counters! after_save :be_user_score @@ -186,4 +189,54 @@ class JournalsForMessage < ActiveRecord::Base self.course_acts << CourseActivity.new(:user_id => self.user_id,:course_id => self.jour_id) end end + + # 课程作品留言消息通知 + def act_as_course_message + if self.jour_type == 'StudentWorksScore' + if self.user_id != self.jour.user_id + self.course_messages << CourseMessage.new(:user_id => self.jour.user_id,:course_id => self.jour.student_work.homework_common.course.id, :viewed => false) + end + end + end + + # 用户留言消息通知 + def act_as_user_feedback_message + # 主留言 + receivers = [] + if self.reply_id == 0 + if self.user_id != self.jour_id # 过滤自己给自己的留言消息 + receivers << self.jour + end + else # 留言回复 + reply_to = User.find(self.reply_id) + if self.user_id != self.parent.user_id + receivers << reply_to + if self.reply_id != self.parent.user_id + receivers << self.parent.user + end + else + receivers << reply_to + end + + # 添加留言回复人 + #reply_to = User.find(self.reply_id) + #if self.user_id != self.parent.user_id && self.user_id != self.parent.jour_id # 如果回帖人不是用户自己 + # receivers << self.parent.user + # if self.reply_id != self.parent.user_id + # receivers << reply_to + # end + #else # 用户自己回复别人的,别人收到消息通知 + # if self.user_id != self.reply_id # 过滤掉自己回复自己的 + # receivers << reply_to + # end + #end + end + if self.jour_type == 'Principal' + + receivers.each do |r| + self.user_feedback_messages << UserFeedbackMessage.new(:user_id => r.id, :journals_for_message_id => self.id, :journals_for_message_type => "Principal", :viewed => false) + end + + end + end end diff --git a/app/models/memo.rb b/app/models/memo.rb index e0abaa19f..f1f9029c1 100644 --- a/app/models/memo.rb +++ b/app/models/memo.rb @@ -16,6 +16,9 @@ class Memo < ActiveRecord::Base acts_as_attachable has_many :user_score_details, :class_name => 'UserScoreDetails',:as => :score_changeable_obj has_many :praise_tread, as: :praise_tread_object, dependent: :destroy + # 消息 + has_many :memo_messages, :class_name =>'MemoMessage', :dependent => :destroy + # end belongs_to :last_reply, :class_name => 'Memo', :foreign_key => 'last_reply_id' # acts_as_searchable :column => ['subject', 'content'], # #:include => { :forum => :p} @@ -44,7 +47,7 @@ class Memo < ActiveRecord::Base "parent_id", "replies_count" - after_create :add_author_as_watcher, :reset_counters!, :send_mail + after_create :add_author_as_watcher, :reset_counters!, :send_mail, :send_message # after_update :update_memos_forum after_destroy :reset_counters!,:delete_kindeditor_assets#,:down_user_score -- 公共区发帖暂不计入得分 # after_create :send_notification @@ -59,6 +62,32 @@ class Memo < ActiveRecord::Base Mailer.run.forum_message_added(self) if Setting.notified_events.include?('forum_message_added') end + # 公共贴吧消息记录 + # 原则:贴吧创始人;发帖人,wanglingchun(特殊用户) + def send_message + receivers = [] + u = User.find(6) + receivers << u + # 主贴 + if self.parent_id.nil? + if self.author_id != self.forum.creator_id # 发帖人不是吧主 + receivers << self.forum.creator + end + else # 回帖 + # 添加吧主 + if self.author_id != self.forum.creator_id + receivers << self.forum.creator + end + # 添加发帖人 + if self.forum.creator_id != self.parent.author_id + receivers << self.parent.author + end + end + receivers.each do |r| + self.memo_messages << MemoMessage.new(:user_id => r.id, :forum_id => self.forum_id, :memo_id => self.id, :memo_type => "Memo", :viewed => false) + end + end + def cannot_reply_to_locked_topic errors.add :base, l(:label_memo_locked) if root.locked? && self != root end diff --git a/app/models/memo_message.rb b/app/models/memo_message.rb new file mode 100644 index 000000000..051fac317 --- /dev/null +++ b/app/models/memo_message.rb @@ -0,0 +1,11 @@ +class MemoMessage < ActiveRecord::Base + attr_accessible :forum_id, :memo_id, :memo_type, :user_id, :viewed + + belongs_to :memo + belongs_to :user + + validates :user_id,presence: true + validates :forum_id,presence: true + validates :memo_id,presence: true + validates :memo_type, presence: true +end diff --git a/app/models/message.rb b/app/models/message.rb index aa62cd625..37129885f 100644 --- a/app/models/message.rb +++ b/app/models/message.rb @@ -35,8 +35,9 @@ class Message < ActiveRecord::Base # 课程动态 has_many :course_acts, :class_name => 'CourseActivity',:as =>:course_act ,:dependent => :destroy # end - # 课程消息 + # 课程/项目 消息 has_many :course_messages, :class_name =>'CourseMessage', :as => :course_message, :dependent => :destroy + has_many :forge_messages, :class_name => 'ForgeMessage', :as => :forge_message, :dependent => :destroy #end has_many :ActivityNotifies,:as => :activity, :dependent => :destroy @@ -73,7 +74,7 @@ class Message < ActiveRecord::Base after_update :update_messages_board after_destroy :reset_counters!,:down_user_score,:delete_kindeditor_assets - after_create :act_as_activity,:act_as_course_activity,:be_user_score,:act_as_forge_activity, :act_as_course_message, :send_mail + after_create :act_as_activity,:act_as_course_activity,:be_user_score,:act_as_forge_activity, :act_as_system_message, :send_mail #before_save :be_user_score scope :visible, lambda {|*args| @@ -198,58 +199,48 @@ class Message < ActiveRecord::Base end end - # 课程讨论区添加消息 + # 课程讨论区添加消息: # 老师发帖所有人都能收到消息 # 学生发帖,有人回复则给该学生消息,没回复则不给其它人发送消息 # 帖子被回复的可以收到消息通知 - def act_as_course_message + # 项目讨论区添加消息: + # 主贴项目成员都能收到 + # 回帖:帖子的发布人收到 + def act_as_system_message if self.course - if self.parent_id.nil? #主贴 + if self.parent_id.nil? # 主贴 self.course.members.each do |m| - if self.author.allowed_to?(:as_teacher, self.course) # 老师 - if m.user_id != self.author_id # 自己的帖子不给自己发送消息 - self.course_messages << CourseMessage.new(:user_id => m.user_id, :course_id => self.board.course_id, :viewed => false) - end + if self.author.allowed_to?(:as_teacher, self.course) && m.user_id != self.author_id # 老师 自己的帖子不给自己发送消息 + self.course_messages << CourseMessage.new(:user_id => m.user_id, :course_id => self.board.course_id, :viewed => false) end end else # 回帖 - #if self.author.allowed_to?(:as_teacher, self.course) # 老师 - self.course.members.each do |m| - if m.user_id == Message.find(self.parent_id).author_id && m.user_id != self.author_id # 只针对主贴回复,回复自己的帖子不发消息 - self.course_messages << CourseMessage.new(:user_id => m.user_id, :course_id => self.board.course_id, :viewed => false) - end + self.course.members.each do |m| + if m.user_id == Message.find(self.parent_id).author_id && m.user_id != self.author_id # 只针对主贴回复,回复自己的帖子不发消息 + self.course_messages << CourseMessage.new(:user_id => m.user_id, :course_id => self.board.course_id, :viewed => false) end - #end + end + end + else # 项目相关 + if self.parent_id.nil? # 主贴 + self.project.members.each do |m| + if m.user_id != self.author_id + self.forge_messages << ForgeMessage.new(:user_id => m.user_id, :project_id => self.board.project_id, :viewed => false) + end + end + else # 回帖 + self.project.members.each do |m| + if m.user_id == Message.find(self.parent_id).author_id && m.user_id != self.author_id # 只针对主贴回复,回复自己的帖子不发消息 + self.forge_messages << ForgeMessage.new(:user_id => m.user_id, :project_id => self.board.project_id, :viewed => false) + end + end end end - # if self.author.allowed_to?(:as_teacher, self.course) # 如果发帖人是老师 - # self.course.members.each do |m| - # if self.parent_id.nil? # 主贴 - # if m.user_id != self.author_id # 自己的帖子不给自己发送消息 - # self.course_messages << CourseMessage.new(:user_id => m.user_id, :course_id => self.board.course_id, :viewed => false) - # end - # else # 回帖只针对主贴发送消息 - # if m.user_id == Message.find(self.parent_id).author_id - # self.course_messages << CourseMessage.new(:user_id => self.parent_id, :course_id => self.board.course_id, :viewed => false) - # end - # end - # end - # else # 学生只针对主贴回复 - # unless self.parent_id.nil? - # self.course.members.each do |m| - # if m.user_id == Message.find(self.parent_id).author_id && m.user_id != self.author_id # 只针对主贴回复,回复自己的帖子不发消息 - # self.course_messages << CourseMessage.new(:user_id => m.user_id, :course_id => self.board.course_id, :viewed => false) - # end - # end - # end - # end - #end end #更新用户分数 -by zjc def be_user_score #新建message且无parent的为发帖 - if self.parent_id.nil? && !self.board.project.nil? UserScore.joint(:post_message, self.author,nil,self, { message_id: self.id }) update_memo_number(self.author,1) diff --git a/app/models/news.rb b/app/models/news.rb index 99d26d456..6e2725d1c 100644 --- a/app/models/news.rb +++ b/app/models/news.rb @@ -23,7 +23,7 @@ class News < ActiveRecord::Base #added by nwb belongs_to :course belongs_to :author, :class_name => 'User', :foreign_key => 'author_id' - has_many :comments, :as => :commented, :dependent => :delete_all, :order => "created_on" + has_many :comments, :as => :commented, :dependent => :destroy, :order => "created_on" # fq has_many :acts, :class_name => 'Activity', :as => :act, :dependent => :destroy # 被ForgeActivity虚拟关联 @@ -31,8 +31,9 @@ class News < ActiveRecord::Base # 课程动态 has_many :course_acts, :class_name => 'CourseActivity',:as =>:course_act ,:dependent => :destroy # end - # 课程消息 + # 课程/项目消息关联 has_many :course_messages, :class_name =>'CourseMessage', :as => :course_message, :dependent => :destroy + has_many :forge_messages, :class_name => 'ForgeMessage', :as => :forge_message, :dependent => :destroy #end has_many :ActivityNotifies,:as => :activity, :dependent => :destroy @@ -54,7 +55,7 @@ class News < ActiveRecord::Base :author_key => :author_id acts_as_watchable - after_create :act_as_activity,:act_as_forge_activity, :act_as_course_activity,:act_as_course_messge, :add_author_as_watcher, :send_mail + after_create :act_as_activity,:act_as_forge_activity, :act_as_course_activity,:act_as_system_message, :add_author_as_watcher, :send_mail after_destroy :delete_kindeditor_assets @@ -133,15 +134,23 @@ class News < ActiveRecord::Base end end - #课程通知 消息发送 + #课程/项目通知 消息发送 #消息发送原则:除了消息的发布者,课程的其它成员都能收到消息提醒 - def act_as_course_messge + def act_as_system_message if self.course self.course.members.each do |m| if m.user_id != self.author_id self.course_messages << CourseMessage.new(:user_id => m.user_id, :course_id => self.course_id, :viewed => false) end end + else + if !self.project.nil? + self.project.members.each do |m| + if m.user_id != self.author_id + self.forge_messages << ForgeMessage.new(:user_id => m.user_id, :project_id => self.project_id, :viewed => false) + end + end + end end end diff --git a/app/models/poll.rb b/app/models/poll.rb index 62f91380b..67bb9f5a8 100644 --- a/app/models/poll.rb +++ b/app/models/poll.rb @@ -13,7 +13,7 @@ class Poll < ActiveRecord::Base after_create :act_as_activity, :act_as_course_activity # 课程消息 has_many :course_messages, :class_name =>'CourseMessage', :as => :course_message, :dependent => :destroy - after_create :act_as_activity, :act_as_course_activity, :act_as_course_message + after_save :act_as_course_message, :act_as_activity, :act_as_course_activity acts_as_event :title => Proc.new {|o| "#{l(:label_course_poll)}: #{o.polls_name}" }, :description => :polls_description, @@ -46,10 +46,14 @@ class Poll < ActiveRecord::Base # 发布问卷,出了发布者外,其他人都能收到消息通知 def act_as_course_message if self.polls_type == "Course" - Course.find(self.polls_group_id).members.each do |m| - if m.user_id != self.user_id - self.course_messages << CourseMessage.new(:user_id => m.user_id, :course_id => self.polls_group_id, :viewed => false) + if self.polls_status == 2 #问卷是发布状态 + Course.find(self.polls_group_id).members.each do |m| + if m.user_id != self.user_id + self.course_messages << CourseMessage.new(:user_id => m.user_id, :course_id => self.polls_group_id, :viewed => false) + end end + elsif self.polls_status == 1 #问卷是新建状态 + self.course_messages.destroy_all end end end diff --git a/app/models/student_works_score.rb b/app/models/student_works_score.rb index 8fa14f8de..639722389 100644 --- a/app/models/student_works_score.rb +++ b/app/models/student_works_score.rb @@ -5,6 +5,17 @@ class StudentWorksScore < ActiveRecord::Base belongs_to :user belongs_to :student_work has_many :journals_for_messages, :as => :jour, :dependent => :destroy + has_many :course_messages, :class_name =>'CourseMessage', :as => :course_message, :dependent => :destroy acts_as_attachable + + after_create :act_as_course_message + + # 评阅作品消息提示 + def act_as_course_message + if self.student_work + receiver = self.student_work.user + self.course_messages << CourseMessage.new(:user_id => receiver.id, :course_id => self.student_work.homework_common.course.id, :viewed => false) + end + end end diff --git a/app/models/user.rb b/app/models/user.rb index 9f88ff53a..99604c798 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -127,10 +127,11 @@ class User < Principal has_many :messages, :foreign_key => 'author_id' has_one :user_score, :dependent => :destroy has_many :documents # 项目中关联的文档再次与人关联 -# 关联虚拟表 +# 关联消息表 has_many :forge_messages has_many :course_messages -# end + has_many :memo_messages + has_many :user_feedback_messages # 虚拟转换 has_many :new_jours, :as => :jour, :class_name => 'JournalsForMessage', :conditions => "status=1" @@ -255,7 +256,11 @@ class User < Principal # 新消息统计 def count_new_message - count = CourseMessage.where("user_id =? and viewed =?", User.current.id, 0).count + course_count = CourseMessage.where("user_id =? and viewed =?", User.current.id, 0).count + forge_count = ForgeMessage.where("user_id =? and viewed =?", User.current.id, 0).count + user_feedback_count = UserFeedbackMessage.where("user_id =? and viewed =?", User.current.id, 0).count + user_memo_count = MemoMessage.where("user_id =? and viewed =?", User.current.id, 0).count + messages_count = course_count + forge_count + user_feedback_count + user_memo_count end # 查询指派给我的缺陷记录 def issue_status_update diff --git a/app/models/user_feedback_message.rb b/app/models/user_feedback_message.rb new file mode 100644 index 000000000..98b53e973 --- /dev/null +++ b/app/models/user_feedback_message.rb @@ -0,0 +1,10 @@ +class UserFeedbackMessage < ActiveRecord::Base + attr_accessible :journals_for_message_id, :journals_for_message_type, :user_id, :viewed + + belongs_to :journals_for_message + belongs_to :user + + validates :user_id,presence: true + validates :journals_for_message_id,presence: true + validates :journals_for_message_type, presence: true +end diff --git a/app/views/users/user_messages.html.erb b/app/views/users/user_messages.html.erb index cf3e13ff9..c1b57aabb 100644 --- a/app/views/users/user_messages.html.erb +++ b/app/views/users/user_messages.html.erb @@ -1,33 +1,62 @@