项目模块消息添加

讨论区结构优化
This commit is contained in:
huang 2015-08-18 10:31:40 +08:00
parent 71f6927145
commit 4bc0e0eb69
5 changed files with 73 additions and 66 deletions

View File

@ -107,26 +107,29 @@ class UsersController < ApplicationController
# if User.current.id == @user.id
# querys.update_all(:viewed => true)
# end
case params[:type]
when nil
@user_course_messages = @user.course_messages.reverse
@user_forge_messages = @user.forge_messages.reverse
when 'homework'
@user_course_messages = CourseMessage.where("course_message_type =? and user_id =?", "HomeworkCommon", @user).order("created_at desc")
when 'message'
@user_course_messages = CourseMessage.where("course_message_type =? and user_id =?", "Message", @user).order("created_at desc")
# @user_course_messages = CourseMessage.where(:course_message_type => "Message", :user_id => @user).reverse
when 'news'
@user_course_messages = CourseMessage.where("course_message_type =? and user_id =?", "News", @user).order("created_at desc")
when 'poll'
@user_course_messages = CourseMessage.where("course_message_type =? and user_id =?", "Poll", @user).order("created_at desc")
when 'issue'
@user_forge_messages = ForgeMessage.where("forge_message_type =? and user_id =?", "Issue", @user).order("created_at desc")
end
respond_to do |format|
format.html{render :layout=>'base_users_new'}
end
@new_message_count = ForgeMessage.all.count
case params[:type]
when nil
@user_course_messages = @user.course_messages.reverse
@user_forge_messages = @user.forge_messages.reverse
when 'homework'
@user_course_messages = CourseMessage.where("course_message_type =? and user_id =?", "HomeworkCommon", @user).order("created_at desc")
@user_forge_messages = nil
when 'message'
@user_course_messages = CourseMessage.where("course_message_type =? and user_id =?", "Message", @user).order("created_at desc")
@user_forge_messages = ForgeMessage.where("forge_message_type =? and user_id =?", "Message", @user).order("created_at desc")
when 'news'
@user_course_messages = CourseMessage.where("course_message_type =? and user_id =?", "News", @user).order("created_at desc")
@user_forge_messages = ForgeMessage.where("forge_message_type =? and user_id =?", "News", @user).order("created_at desc")
when 'poll'
@user_course_messages = CourseMessage.where("course_message_type =? and user_id =?", "Poll", @user).order("created_at desc")
when 'issue'
@user_forge_messages = ForgeMessage.where("forge_message_type =? and user_id =?", "Issue", @user).order("created_at desc")
@user_course_messages = nil
end
respond_to do |format|
format.html{render :layout=>'base_users_new'}
end
end
def user_projects_index

View File

@ -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,49 @@ 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)
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)

View File

@ -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

View File

@ -20,7 +20,8 @@
</div>
<div>
<% if !@user_course_messages.blank? %>
<% if @new_message_count >0 %>
<% unless @user_course_messages.nil? %>
<% @user_course_messages.each do |ucm| %>
<% if ucm.course_message_type == "News" %>
<ul class="homepageNewsList fl">
@ -71,13 +72,15 @@
<% end %>
<div class="cl"></div>
<% end %>
<% end %>
<!--项目消息-->
<% elsif !@user_forge_messages.blank? %>
<% unless @user_forge_messages.nil? %>
<% @user_forge_messages.each do |ufm| %>
<% if ufm.forge_message_type == "Issue" %>
22222
<% end %>
<% end %>
<% end %>
<% else %>
<div class="flash notice">暂无消息!</div>
<% end %>

View File

@ -6,7 +6,7 @@ div,img,tr,td,table{ border:0;}
table,tr,td{border:0;cellspacing:0; cellpadding:0;}
ol,ul,li{ list-style-type:none}
a:link,a:visited{color:#7f7f7f;text-decoration:none;}
a:hover,a:active{color:#000;}
a:hover,a:active{color:#15bccf;}
/*img{max-width: 100%;}*/
/*常用*/