作品被评阅

作品被回复
消息通知
This commit is contained in:
huang 2015-08-18 15:27:16 +08:00
parent 4bc0e0eb69
commit 6b55474623
4 changed files with 28 additions and 2 deletions

View File

@ -97,6 +97,8 @@ class UsersController < ApplicationController
end
# 用户消息
# 说明: homework 发布作业message讨论区 news新闻 poll问卷works_reviewers作品评阅
# issue问题
def user_messages
unless User.current.logged?
render_403
@ -123,6 +125,8 @@ class UsersController < ApplicationController
@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 'works_reviewers'
@user_course_messages = CourseMessage.where("course_message_type =? and user_id =?", "StudentWorksScore", @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

View File

@ -58,9 +58,11 @@ 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
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
after_create :reset_counters!
after_destroy :reset_counters!
after_save :be_user_score
@ -186,4 +188,13 @@ 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)
end
end
end
end

View File

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

View File

@ -22,7 +22,7 @@
<div>
<% if @new_message_count >0 %>
<% unless @user_course_messages.nil? %>
<% @user_course_messages.each do |ucm| %>
<% @user_course_messages.each do |ucm| %>
<% if ucm.course_message_type == "News" %>
<ul class="homepageNewsList fl">
<li class="homepageNewsPortrait fl"><a href="javascript:void(0);"><%= image_tag(url_to_avatar(ucm.course_message.author), :width => "30", :height => "30") %></a></li>