diff options
Diffstat (limited to 'app/models/page.rb')
| -rw-r--r-- | app/models/page.rb | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/app/models/page.rb b/app/models/page.rb index 05abd438..5c93a93b 100644 --- a/app/models/page.rb +++ b/app/models/page.rb | |||
| @@ -39,8 +39,8 @@ class Page < ActiveRecord::Base | |||
| 39 | # partially or entirely overwritten by the options hash. Afterwards the merged | 39 | # partially or entirely overwritten by the options hash. Afterwards the merged |
| 40 | # parameters are used to query the DB for Pages matching these parameters. | 40 | # parameters are used to query the DB for Pages matching these parameters. |
| 41 | # The aggregation only takes published pages into account. | 41 | # The aggregation only takes published pages into account. |
| 42 | def self.aggregate options, page=1 | ||
| 43 | 42 | ||
| 43 | def self.aggregate options, page=1 | ||
| 44 | defaults = { | 44 | defaults = { |
| 45 | :tags => "", | 45 | :tags => "", |
| 46 | :limit => 25, | 46 | :limit => 25, |
| @@ -52,10 +52,18 @@ class Page < ActiveRecord::Base | |||
| 52 | 52 | ||
| 53 | scope = Page.heads | 53 | scope = Page.heads |
| 54 | unless options[:tags].blank? | 54 | unless options[:tags].blank? |
| 55 | scope = scope.tagged_with( | 55 | tag_names = options[:tags].gsub(/\s/, ",").split(",").map(&:strip).map(&:downcase).uniq.reject(&:blank?) |
| 56 | options[:tags].gsub(/\s/, ",").split(",").map(&:strip), | 56 | |
| 57 | :match_all => true | 57 | unless tag_names.empty? |
| 58 | ) | 58 | scope = scope |
| 59 | .joins("JOIN taggings ON taggings.taggable_id = pages.id | ||
| 60 | AND taggings.taggable_type = 'Page' | ||
| 61 | AND taggings.context = 'tags'") | ||
| 62 | .joins("JOIN tags ON tags.id = taggings.tag_id") | ||
| 63 | .where("LOWER(tags.name) IN (?)", tag_names) | ||
| 64 | .group("pages.id") | ||
| 65 | .having("COUNT(DISTINCT tags.id) = ?", tag_names.length) | ||
| 66 | end | ||
| 59 | end | 67 | end |
| 60 | 68 | ||
| 61 | scope.order("#{options[:order_by]} #{options[:order_direction]}") | 69 | scope.order("#{options[:order_by]} #{options[:order_direction]}") |
