summaryrefslogtreecommitdiff
path: root/app/models
diff options
context:
space:
mode:
authorhukl <contact@smyck.org>2009-08-15 22:29:57 +0200
committerhukl <contact@smyck.org>2009-08-15 22:29:57 +0200
commitb8717e4fe005a8df13a4983943184881f87d97be (patch)
treea67620b7da0def661ae00571593def8bad4fc7c8 /app/models
parentb826671766f2831439b5441683dd9019062bb4bd (diff)
added pagination for aggregators. costed me the whole day. crappy plugins ARGH! More work to do!
Diffstat (limited to 'app/models')
-rw-r--r--app/models/page.rb30
1 files changed, 21 insertions, 9 deletions
diff --git a/app/models/page.rb b/app/models/page.rb
index 0a978ab..ef92d4e 100644
--- a/app/models/page.rb
+++ b/app/models/page.rb
@@ -45,8 +45,8 @@ class Page < ActiveRecord::Base
45 # partially or entirely overwritten by the options hash. Afterwards the merged 45 # partially or entirely overwritten by the options hash. Afterwards the merged
46 # parameters are used to query the DB for Pages matching these parameters. 46 # parameters are used to query the DB for Pages matching these parameters.
47 # The aggregation only takes published pages into account. 47 # The aggregation only takes published pages into account.
48 def self.aggregate options 48 def self.aggregate options, page=1
49 49
50 defaults = { 50 defaults = {
51 :tags => "", 51 :tags => "",
52 :limit => 20, 52 :limit => 20,
@@ -56,17 +56,29 @@ class Page < ActiveRecord::Base
56 56
57 options = defaults.merge options 57 options = defaults.merge options
58 58
59 pages = Page.find_all_tagged_with( 59 pages = Page.heads.paged_find_tagged_with(
60 options[:tags].gsub(/\s/, ", "), 60 options[:tags].gsub(/\s/, ", "),
61 :match_all => true, 61 :page => page,
62 :order => "#{options[:order_by]} #{options[:order_direction]}", 62 :per_page => 23,
63 :include => [:node, :globalize_translations], 63 :include => [:globalize_translations],
64 :conditions => ["nodes.head_id = pages.id"], 64 :order => "#{options[:order_by]} #{options[:order_direction]}"
65 :limit => options[:limit]
66 ) 65 )
67 66
68 end 67 end
69 68
69 def self.paged_find_tagged_with(tags, args = {})
70 if tags.blank?
71 paginate args
72 else
73 options = find_options_for_find_tagged_with(tags, :match_all => true)
74 options.merge!(args)
75 # FIXME The select {} looks really bad !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
76 # The default count query generated by paginate includes COUNT(DISTINCT Posts.*) which errors, at least on mysql
77 # Below we override the default select statement used to perform the count so that it becomes COUNT(DISTINCT Posts.id)
78 paginate(options.merge(:count => { :select => options[:select].gsub('*', 'id') }))
79 end
80 end
81
70 def self.custom_templates 82 def self.custom_templates
71 files = Dir.entries(FULL_PUBLIC_TEMPLATE_PATH).select do |x| 83 files = Dir.entries(FULL_PUBLIC_TEMPLATE_PATH).select do |x|
72 x if x.gsub!(".html.erb", "") 84 x if x.gsub!(".html.erb", "")