组织留言数据方法

This commit is contained in:
yanxd 2013-12-25 15:40:34 +08:00
parent a53e18dcc5
commit f05d2131bd
4 changed files with 89 additions and 64 deletions

View File

@ -1,3 +1,4 @@
# encoding: utf-8
#####leave message fq #####leave message fq
class WordsController < ApplicationController class WordsController < ApplicationController
@ -40,23 +41,30 @@ class WordsController < ApplicationController
end end
def create_reply def create_reply
find_user
@params = params @params = params
parent_id = params[:reference_id] parent_id = params[:reference_id]
author_id = User.current.id author_id = User.current.id
reply_user_id = params[:reference_user_id] reply_user_id = params[:reference_user_id]
# reply_id = nil # 暂时不实现 reply_id = nil # 暂时不实现
content = params[:user_notes] content = params[:user_notes]
@params.merge({flag:'====', parent_id: parent_id, author_id: author_id, reply_user_id: reply_user_id, content: content}) @params.merge!({flag:'====', parent_id: parent_id, author_id: author_id, reply_user_id: reply_user_id, content: content})
JournalsForMessage.new( :user_id => author_id, options = {:user_id => author_id,
:m_parent_id => parent_id, :m_parent_id => parent_id,
:reply_id => reply_user_id, :m_reply_id => reply_id,
:notes => content, :reply_id => reply_user_id,
:is_readed => false :notes => content,
) :is_readed => false}
jfm = User.current.add_jour(nil, nil, nil, options)
respond_to do |format| respond_to do |format|
format.html {render 'test/index'} format.html {
if jfm.errors.empty?
flash.notice = l(:label_feedback_success)
else
flash.errors = l(:label_feedback_fail)
end
render 'test/index'
}
format.js format.js
end end
end end

View File

@ -43,5 +43,15 @@ module WordsHelper
# content.present? ? content_tag('ul', content, :class => 'watchers') : content # content.present? ? content_tag('ul', content, :class => 'watchers') : content
content content
end end
def fetch_user_leaveWord_reply leaveWordObj
if leaveWordObj.kind_of? JournalsForMessage
leaveWordObj.children
elsif leaveWordObj.kind_of? Fixnum
JournalsForMessage.find(leaveWordObj).children
else
[]
end
end
end end

View File

@ -1,6 +1,6 @@
# fq # fq
# 数据库字段中带有m前缀和is_readed是二次开发添加之前的字段基本复用 # 数据库字段中带有m前缀和is_readed是二次开发添加之前的字段基本复用
# 注意reply_id 是提到人的id不是留言id, Base中叫做ator # 注意reply_id 是提到人的id不是留言id, Base中叫做 at_user
class JournalsForMessage < ActiveRecord::Base class JournalsForMessage < ActiveRecord::Base
include Redmine::SafeAttributes include Redmine::SafeAttributes
safe_attributes "jour_type", # 留言所属类型 safe_attributes "jour_type", # 留言所属类型
@ -17,7 +17,7 @@ class JournalsForMessage < ActiveRecord::Base
belongs_to :jour, :polymorphic => true belongs_to :jour, :polymorphic => true
belongs_to :user belongs_to :user
belongs_to :ator, :class_name => "User", :foreign_key => 'reply_id' belongs_to :at_user, :class_name => "User", :foreign_key => 'reply_id'
has_many :acts, :class_name => 'Activity', :as => :act, :dependent => :destroy has_many :acts, :class_name => 'Activity', :as => :act, :dependent => :destroy
has_many :reply_for_journals, :dependent => :destroy has_many :reply_for_journals, :dependent => :destroy
@ -50,10 +50,11 @@ class JournalsForMessage < ActiveRecord::Base
end end
def reset_counters! def reset_counters!
self.class.reset_counters!(id) self.class.reset_counters!(self)
end end
def self.reset_counters! journals_for_messages_id def self.reset_counters! journals_for_messages
jfm_id = journals_for_messages_id.to_i # jfm_id = journals_for_messages.id.to_i
update_all("m_reply_count = (SELECT COUNT(*) FROM #{JournalsForMssages.table_name} WHERE m_parent_id = #{jfm_id} )", ["id = ?", jfm_id]) 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
end end

View File

@ -164,8 +164,14 @@ class User < Principal
###添加留言 fq ###添加留言 fq
def add_jour(user, notes, reference_user_id = 0) def add_jour(user, notes, reference_user_id = 0, options = {})
self.journals_for_messages << JournalsForMessage.new(:user_id => user.id, :notes => notes, :reply_id => reference_user_id, :status => true) if options.count == 0
self.journals_for_messages << JournalsForMessage.new(:user_id => user.id, :notes => notes, :reply_id => reference_user_id, :status => true)
else
jfm = self.journals_for_messages.build(options)
jfm.save
jfm
end
end end
# 判断用户是否加入了竞赛中 fq # 判断用户是否加入了竞赛中 fq