forked from jacknudt/trustieforge
组织留言数据方法
This commit is contained in:
parent
a53e18dcc5
commit
f05d2131bd
|
@ -1,3 +1,4 @@
|
|||
# encoding: utf-8
|
||||
#####leave message fq
|
||||
class WordsController < ApplicationController
|
||||
|
||||
|
@ -40,23 +41,30 @@ class WordsController < ApplicationController
|
|||
end
|
||||
|
||||
def create_reply
|
||||
find_user
|
||||
@params = params
|
||||
parent_id = params[:reference_id]
|
||||
author_id = User.current.id
|
||||
reply_user_id = params[:reference_user_id]
|
||||
# reply_id = nil # 暂时不实现
|
||||
reply_id = nil # 暂时不实现
|
||||
content = params[:user_notes]
|
||||
@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,
|
||||
:m_parent_id => parent_id,
|
||||
:reply_id => reply_user_id,
|
||||
:notes => content,
|
||||
:is_readed => false
|
||||
)
|
||||
@params.merge!({flag:'====', parent_id: parent_id, author_id: author_id, reply_user_id: reply_user_id, content: content})
|
||||
options = {:user_id => author_id,
|
||||
:m_parent_id => parent_id,
|
||||
:m_reply_id => reply_id,
|
||||
:reply_id => reply_user_id,
|
||||
:notes => content,
|
||||
:is_readed => false}
|
||||
jfm = User.current.add_jour(nil, nil, nil, options)
|
||||
|
||||
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
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,47 +1,57 @@
|
|||
########fq
|
||||
module WordsHelper
|
||||
def message_list(object, state, user)
|
||||
unless state
|
||||
if object.size > 5
|
||||
object = object[-5, 5]
|
||||
end
|
||||
end
|
||||
object = object.reverse
|
||||
remove_allowed = (User.current.id == object.first.user_id)
|
||||
content = ''.html_safe
|
||||
lis = object.each do |t_object|
|
||||
s = ''.html_safe
|
||||
s << link_to(t_object.indice, {}, :class => "journal-link")
|
||||
s << avatar(t_object.user, :size => "16").to_s
|
||||
s << link_to_user(t_object.user, :class => 'user')
|
||||
time = time_tag(t_object.created_at)
|
||||
s << l(:field_add, :time => time).html_safe
|
||||
if !t_object.notes.blank?
|
||||
s << link_to(image_tag('comment.png'),
|
||||
{:controller => 'words', :action => 'new', :id => user, :journal_id => t_object},
|
||||
:remote => true,
|
||||
:method => 'post',
|
||||
:title => l(:button_quote))
|
||||
if remove_allowed || t_object.jour_id == User.current.id
|
||||
url = {:controller => 'words',
|
||||
:action => 'destroy',
|
||||
:object_id => t_object,
|
||||
:user_id => user}
|
||||
s << ' '
|
||||
s << link_to(image_tag('delete.png'), url,
|
||||
:remote => true, :method => 'delete', :class => "delete", :title => l(:button_delete))
|
||||
end
|
||||
end
|
||||
#time = '更新于' + time_tag(t_object.created_at) + '之前'
|
||||
|
||||
|
||||
# s << content_tag('div', time)
|
||||
|
||||
content << content_tag('li', s, :class => "user-#{t_object.jour_id}")
|
||||
content << textilizable(t_object.notes)
|
||||
end
|
||||
# content.present? ? content_tag('ul', content, :class => 'watchers') : content
|
||||
content
|
||||
end
|
||||
end
|
||||
########fq
|
||||
module WordsHelper
|
||||
def message_list(object, state, user)
|
||||
unless state
|
||||
if object.size > 5
|
||||
object = object[-5, 5]
|
||||
end
|
||||
end
|
||||
object = object.reverse
|
||||
remove_allowed = (User.current.id == object.first.user_id)
|
||||
content = ''.html_safe
|
||||
lis = object.each do |t_object|
|
||||
s = ''.html_safe
|
||||
s << link_to(t_object.indice, {}, :class => "journal-link")
|
||||
s << avatar(t_object.user, :size => "16").to_s
|
||||
s << link_to_user(t_object.user, :class => 'user')
|
||||
time = time_tag(t_object.created_at)
|
||||
s << l(:field_add, :time => time).html_safe
|
||||
if !t_object.notes.blank?
|
||||
s << link_to(image_tag('comment.png'),
|
||||
{:controller => 'words', :action => 'new', :id => user, :journal_id => t_object},
|
||||
:remote => true,
|
||||
:method => 'post',
|
||||
:title => l(:button_quote))
|
||||
if remove_allowed || t_object.jour_id == User.current.id
|
||||
url = {:controller => 'words',
|
||||
:action => 'destroy',
|
||||
:object_id => t_object,
|
||||
:user_id => user}
|
||||
s << ' '
|
||||
s << link_to(image_tag('delete.png'), url,
|
||||
:remote => true, :method => 'delete', :class => "delete", :title => l(:button_delete))
|
||||
end
|
||||
end
|
||||
#time = '更新于' + time_tag(t_object.created_at) + '之前'
|
||||
|
||||
|
||||
# s << content_tag('div', time)
|
||||
|
||||
content << content_tag('li', s, :class => "user-#{t_object.jour_id}")
|
||||
content << textilizable(t_object.notes)
|
||||
end
|
||||
# content.present? ? content_tag('ul', content, :class => 'watchers') : content
|
||||
content
|
||||
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
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
# fq
|
||||
# 数据库字段中带有m前缀和is_readed是二次开发添加,之前的字段基本复用
|
||||
# 注意reply_id 是提到人的id,不是留言id, Base中叫做ator
|
||||
# 注意reply_id 是提到人的id,不是留言id, Base中叫做 at_user
|
||||
class JournalsForMessage < ActiveRecord::Base
|
||||
include Redmine::SafeAttributes
|
||||
safe_attributes "jour_type", # 留言所属类型
|
||||
|
@ -17,7 +17,7 @@ class JournalsForMessage < ActiveRecord::Base
|
|||
|
||||
belongs_to :jour, :polymorphic => true
|
||||
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 :reply_for_journals, :dependent => :destroy
|
||||
|
@ -50,10 +50,11 @@ class JournalsForMessage < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def reset_counters!
|
||||
self.class.reset_counters!(id)
|
||||
self.class.reset_counters!(self)
|
||||
end
|
||||
def self.reset_counters! journals_for_messages_id
|
||||
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])
|
||||
def self.reset_counters! journals_for_messages
|
||||
# jfm_id = journals_for_messages.id.to_i
|
||||
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
|
||||
|
|
|
@ -164,8 +164,14 @@ class User < Principal
|
|||
|
||||
|
||||
###添加留言 fq
|
||||
def add_jour(user, notes, reference_user_id = 0)
|
||||
self.journals_for_messages << JournalsForMessage.new(:user_id => user.id, :notes => notes, :reply_id => reference_user_id, :status => true)
|
||||
def add_jour(user, notes, reference_user_id = 0, options = {})
|
||||
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
|
||||
|
||||
# 判断用户是否加入了竞赛中 fq
|
||||
|
|
Loading…
Reference in New Issue