2013-08-08 17:01:56 +08:00
|
|
|
module PraiseTreadHelper
|
|
|
|
#added by william
|
|
|
|
def is_praise_or_tread(object,user_id)
|
2013-08-11 23:44:12 +08:00
|
|
|
@obj_type = object.class
|
2013-08-08 17:01:56 +08:00
|
|
|
@obj_id = object.id
|
2013-08-11 23:44:12 +08:00
|
|
|
@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}")
|
2013-08-08 17:01:56 +08:00
|
|
|
return @is_praise
|
|
|
|
end
|
|
|
|
#end
|
|
|
|
|
2013-08-12 20:18:10 +08:00
|
|
|
def get_praise_num(object)
|
2013-08-12 14:50:54 +08:00
|
|
|
@obj_type = object.class
|
2013-08-08 17:01:56 +08:00
|
|
|
@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)
|
2013-08-12 14:50:54 +08:00
|
|
|
else
|
|
|
|
return 0
|
2013-08-08 17:01:56 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|