forked from saurabh/orbit4-5
Merge branch 'master' of gitlab.tp.rulingcom.com:saurabh/orbit4-5 into gravity
This commit is contained in:
commit
bbb6bad20b
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in New Issue