socialforge/app/helpers/praise_tread_helper.rb

30 lines
880 B
Ruby
Raw Normal View History

module PraiseTreadHelper
#added by william
def is_praise_or_tread(object,user_id)
@obj_type = object.class
@obj_id = object.id
@is_praise = PraiseTread.find_by_sql("select praise_or_tread from praise_treads where user_id=#{user_id} and " +
"praise_tread_object_type='#{@obj_type}' and praise_tread_object_id=#{@obj_id}")
return @is_praise
end
#end
2013-08-12 20:18:10 +08:00
def get_praise_num(object)
@obj_type = object.class
@obj_id = object.id
@record = PraiseTreadCache.find_by_object_id_and_object_type(@obj_id,@obj_type)
if @record
2013-08-12 20:18:10 +08:00
# case flag
# when 1
# return @record.praise_num.nil? ? 0 : @record.praise_num
# when 0
# return @record.tread_num.nil? ? 0 : @record.tread_num
# end
return (@record.praise_num.to_i-@record.tread_num.to_i)
else
return 0
end
end
end