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
|
module ClassMethods
|
||||||
def with_tags(tags=[])
|
def with_tags(tags=[])
|
||||||
tags = [tags].flatten.uniq
|
tags = [tags].flatten.uniq
|
||||||
result = []
|
|
||||||
if tags.blank?
|
if tags.blank?
|
||||||
self.all
|
self.all
|
||||||
else
|
else
|
||||||
self.all.each do |taggable|
|
taggings = Tagging.where(:tag_id.in=>tags).map{|item| item.taggable_id}
|
||||||
result << taggable if (taggable.taggings.map{|t| t.tag.id.to_s } & tags).size > 0
|
self.where(:id.in=>taggings)
|
||||||
end
|
|
||||||
self.where(:id.in=>result.map{|taggable| taggable.id})
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def filter_by_tags(tags=[])
|
def filter_by_tags(tags=[])
|
||||||
tags = OrbitHelper.page_tags if tags.blank?
|
tags = OrbitHelper.page_tags if tags.blank?
|
||||||
tags = [tags].flatten.uniq
|
tags = [tags].flatten.uniq
|
||||||
result = []
|
|
||||||
|
|
||||||
if tags.blank? or (tags.include?("all") rescue false)
|
if tags.blank? or (tags.include?("all") rescue false)
|
||||||
self.all
|
self.all
|
||||||
else
|
else
|
||||||
self.all.each do |taggable|
|
taggings = Tagging.where(:tag_id.in=>tags).map{|item| item.taggable_id}
|
||||||
result << taggable if (taggable.taggings.map{|t| t.tag.id.to_s } & tags).size > 0
|
self.where(:id.in=>taggings)
|
||||||
end
|
|
||||||
self.where(:id.in=>result.map{|taggable| taggable.id})
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue