@ -132,6 +132,7 @@ class User < Principal
has_many :course_messages
has_many :course_messages
has_many :memo_messages
has_many :memo_messages
has_many :user_feedback_messages
has_many :user_feedback_messages
has_one :onclick_time
# 虚拟转换
# 虚拟转换
has_many :new_jours , :as = > :jour , :class_name = > 'JournalsForMessage' , :conditions = > " status=1 "
has_many :new_jours , :as = > :jour , :class_name = > 'JournalsForMessage' , :conditions = > " status=1 "
@ -209,7 +210,7 @@ class User < Principal
before_save :update_hashed_password
before_save :update_hashed_password
before_destroy :remove_references_before_destroy
before_destroy :remove_references_before_destroy
# added by fq
# added by fq
after_create :act_as_activity
after_create :act_as_activity , :add_onclick_time
# end
# end
scope :in_group , lambda { | group |
scope :in_group , lambda { | group |
@ -257,10 +258,16 @@ class User < Principal
# 新消息统计
# 新消息统计
def count_new_message
def count_new_message
course_count = CourseMessage . where ( " user_id =? and viewed =? " , User . current . id , 0 ) . count
if OnclickTime . where ( " user_id =? " , User . current ) . first . nil?
forge_count = ForgeMessage . where ( " user_id =? and viewed =? " , User . current . id , 0 ) . count
message_new_time = OnclickTime . new
user_feedback_count = UserFeedbackMessage . where ( " user_id =? and viewed =? " , User . current . id , 0 ) . count
message_new_time . user_id = User . current . id
user_memo_count = MemoMessage . where ( " user_id =? and viewed =? " , User . current . id , 0 ) . count
message_new_time . onclick_time = User . current . last_login_on . nil? ? Time . now : User . current . last_login_on
message_new_time . save
end
course_count = CourseMessage . where ( " user_id =? and viewed =? and created_at >? " , User . current . id , 0 , User . current . onclick_time . onclick_time ) . count
forge_count = ForgeMessage . where ( " user_id =? and viewed =? and created_at >? " , User . current . id , 0 , User . current . onclick_time . onclick_time ) . count
user_feedback_count = UserFeedbackMessage . where ( " user_id =? and viewed =? and created_at >? " , User . current . id , 0 , User . current . onclick_time . onclick_time ) . count
user_memo_count = MemoMessage . where ( " user_id =? and viewed =? and created_at >? " , User . current . id , 0 , User . current . onclick_time . onclick_time ) . count
messages_count = course_count + forge_count + user_feedback_count + user_memo_count
messages_count = course_count + forge_count + user_feedback_count + user_memo_count
end
end
@ -994,6 +1001,10 @@ class User < Principal
self . acts << Activity . new ( :user_id = > self . id )
self . acts << Activity . new ( :user_id = > self . id )
end
end
def add_onclick_time
self . onclick_time << OnclickTime . new ( :user_id = > self . id , :onclick_time = > self . created_on )
end
# Removes references that are not handled by associations
# Removes references that are not handled by associations
# Things that are not deleted are reassociated with the anonymous user
# Things that are not deleted are reassociated with the anonymous user
def remove_references_before_destroy
def remove_references_before_destroy