|
|
|
@ -5,21 +5,26 @@ class PraiseTreadController < ApplicationController
|
|
|
|
|
|
|
|
|
|
def praise_plus
|
|
|
|
|
@obj = nil
|
|
|
|
|
# @is_in_list = nil
|
|
|
|
|
if @pt = PraiseTread.where("praise_tread_object_id=? and praise_tread_object_type=? and user_id=?",@obj_id,@obj_type.to_s,User.current.id).first
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
@activity = false
|
|
|
|
|
|
|
|
|
|
if request.get?
|
|
|
|
|
@obj_id = params[:obj_id]
|
|
|
|
|
@obj_type = params[:obj_type]
|
|
|
|
|
if !params[:user_activity_id].nil? && !params[:type].nil?
|
|
|
|
|
@user_activity_id = params[:user_activity_id]
|
|
|
|
|
@type = params[:type]
|
|
|
|
|
@activity = true
|
|
|
|
|
end
|
|
|
|
|
@obj_id = params[:obj_id]
|
|
|
|
|
@obj_type = params[:obj_type]
|
|
|
|
|
#@horizontal = params[:horizontal].downcase == "false" ? false:true
|
|
|
|
|
# @is_in_list = nil
|
|
|
|
|
@obj = find_object_by_type_and_id(@obj_type,@obj_id)
|
|
|
|
|
pts = PraiseTread.where("praise_tread_object_id=? and praise_tread_object_type=? and user_id=?",@obj_id,@obj_type.to_s,User.current.id)
|
|
|
|
|
unless pts.empty?
|
|
|
|
|
respond_to do |format|
|
|
|
|
|
format.js
|
|
|
|
|
end
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
#@horizontal = params[:horizontal].downcase == "false" ? false:true
|
|
|
|
|
if @obj.respond_to?("author_id")
|
|
|
|
|
author_id = @obj.author_id
|
|
|
|
|
elsif @obj.respond_to?("user_id")
|
|
|
|
@ -39,13 +44,24 @@ class PraiseTreadController < ApplicationController
|
|
|
|
|
@activity = false
|
|
|
|
|
if request.get?
|
|
|
|
|
#@obj = params[:obj] # 传的是对象,最后变成id了
|
|
|
|
|
@obj_id = params[:obj_id]
|
|
|
|
|
@obj_type = params[:obj_type]
|
|
|
|
|
#首先更新praise_tread 表 删除关注记录
|
|
|
|
|
#@pt = PraiseTread.find_by_user_id_and_praise_tread_object_id_and_praise_tread_object_type(User.current.id,@obj,"user")
|
|
|
|
|
@obj_id = params[:obj_id]
|
|
|
|
|
@obj_type = params[:obj_type]
|
|
|
|
|
if !params[:user_activity_id].nil? && !params[:type].nil?
|
|
|
|
|
@user_activity_id = params[:user_activity_id]
|
|
|
|
|
@type = params[:type]
|
|
|
|
|
@activity = true
|
|
|
|
|
end
|
|
|
|
|
@obj = find_object_by_type_and_id(@obj_type,@obj_id)
|
|
|
|
|
@pt = PraiseTread.where("praise_tread_object_id=? and praise_tread_object_type=? and user_id=?",@obj_id,@obj_type.to_s,User.current.id).first
|
|
|
|
|
if @pt.nil?
|
|
|
|
|
respond_to do |format|
|
|
|
|
|
format.js
|
|
|
|
|
end
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
@pt.delete if !@pt.nil?
|
|
|
|
|
|
|
|
|
|
#再更新praise_tread_cache表 使相应的记录减1 当为0时删除
|
|
|
|
|
@ptc = PraiseTreadCache.where("object_id=? and object_type=?",@obj_id,@obj_type.to_s).first
|
|
|
|
|
@ptc.minus(1) if !@ptc.nil?
|
|
|
|
@ -55,12 +71,6 @@ class PraiseTreadController < ApplicationController
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
#@obj = User.find_by_id(@obj)
|
|
|
|
|
@obj = find_object_by_type_and_id(@obj_type,@obj_id)
|
|
|
|
|
if !params[:user_activity_id].nil? && !params[:type].nil?
|
|
|
|
|
@user_activity_id = params[:user_activity_id]
|
|
|
|
|
@type = params[:type]
|
|
|
|
|
@activity = true
|
|
|
|
|
end
|
|
|
|
|
respond_to do |format|
|
|
|
|
|
format.js
|
|
|
|
|
end
|
|
|
|
@ -111,6 +121,12 @@ class PraiseTreadController < ApplicationController
|
|
|
|
|
@obj = HomeworkCommon.find_by_id(id)
|
|
|
|
|
when 'JournalsForMessage'
|
|
|
|
|
@obj = JournalsForMessage.find_by_id(id)
|
|
|
|
|
when 'News'
|
|
|
|
|
@obj = News.find_by_id(id)
|
|
|
|
|
when 'Comment'
|
|
|
|
|
@obj = Comment.find_by_id(id)
|
|
|
|
|
when 'Journal'
|
|
|
|
|
@obj = Journal.find_by_id(id)
|
|
|
|
|
end
|
|
|
|
|
return @obj
|
|
|
|
|
end
|
|
|
|
|