Merge branch 'master' of gitlab.tp.rulingcom.com:saurabh/orbit4-5 into gravity

This commit is contained in:
Harry Bomrah 2014-12-08 19:02:34 +08:00
commit bbb6bad20b
1 changed files with 4 additions and 11 deletions

View File

@ -10,29 +10,22 @@ module OrbitTag
module ClassMethods
def with_tags(tags=[])
tags = [tags].flatten.uniq
result = []
if tags.blank?
self.all
else
self.all.each do |taggable|
result << taggable if (taggable.taggings.map{|t| t.tag.id.to_s } & tags).size > 0
end
self.where(:id.in=>result.map{|taggable| taggable.id})
taggings = Tagging.where(:tag_id.in=>tags).map{|item| item.taggable_id}
self.where(:id.in=>taggings)
end
end
def filter_by_tags(tags=[])
tags = OrbitHelper.page_tags if tags.blank?
tags = [tags].flatten.uniq
result = []
if tags.blank? or (tags.include?("all") rescue false)
self.all
else
self.all.each do |taggable|
result << taggable if (taggable.taggings.map{|t| t.tag.id.to_s } & tags).size > 0
end
self.where(:id.in=>result.map{|taggable| taggable.id})
taggings = Tagging.where(:tag_id.in=>tags).map{|item| item.taggable_id}
self.where(:id.in=>taggings)
end
end