summaryrefslogtreecommitdiff
path: root/app
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
parentb826671766f2831439b5441683dd9019062bb4bd (diff)
added pagination for aggregators. costed me the whole day. crappy plugins ARGH! More work to do!
Diffstat (limited to 'app')
-rw-r--r--app/helpers/content_helper.rb4
-rw-r--r--app/models/page.rb30
-rw-r--r--app/views/custom/page_templates/public/no_date_and_author.html.erb4
-rw-r--r--app/views/custom/page_templates/public/standard_template.html.erb4
4 files changed, 30 insertions, 12 deletions
diff --git a/app/helpers/content_helper.rb b/app/helpers/content_helper.rb
index 5f6143b..6309c8b 100644
--- a/app/helpers/content_helper.rb
+++ b/app/helpers/content_helper.rb
@@ -77,9 +77,11 @@ module ContentHelper
77 # Takes the parameters from the aggregate? method and renders the collection 77 # Takes the parameters from the aggregate? method and renders the collection
78 # from Page.aggregate(options) with a given partial 78 # from Page.aggregate(options) with a given partial
79 def render_collection options 79 def render_collection options
80 @content_collection = Page.aggregate(options, params[:page])
81
80 render( 82 render(
81 :partial => options[:partial], 83 :partial => options[:partial],
82 :collection => Page.aggregate(options), 84 :collection => @content_collection,
83 :as => :page 85 :as => :page
84 ) 86 )
85 end 87 end
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", "")
diff --git a/app/views/custom/page_templates/public/no_date_and_author.html.erb b/app/views/custom/page_templates/public/no_date_and_author.html.erb
index 4eda744..254fe45 100644
--- a/app/views/custom/page_templates/public/no_date_and_author.html.erb
+++ b/app/views/custom/page_templates/public/no_date_and_author.html.erb
@@ -3,4 +3,6 @@
3 <hr class="subtitle" /> 3 <hr class="subtitle" />
4 <p><em><%= @page.abstract %></em></p> 4 <p><em><%= @page.abstract %></em></p>
5 <%= aggregate?(@page.body) %> 5 <%= aggregate?(@page.body) %>
6</div> \ No newline at end of file 6</div>
7
8<p><%= will_paginate(@content_collection) if @content_collection %></p> \ No newline at end of file
diff --git a/app/views/custom/page_templates/public/standard_template.html.erb b/app/views/custom/page_templates/public/standard_template.html.erb
index 4c21667..1822491 100644
--- a/app/views/custom/page_templates/public/standard_template.html.erb
+++ b/app/views/custom/page_templates/public/standard_template.html.erb
@@ -4,4 +4,6 @@
4 <hr class="subtitle" /> 4 <hr class="subtitle" />
5 <p><em><%= @page.abstract %></em></p> 5 <p><em><%= @page.abstract %></em></p>
6 <%= aggregate?(@page.body) %> 6 <%= aggregate?(@page.body) %>
7</div> \ No newline at end of file 7</div>
8
9<p><%= will_paginate(@content_collection) if @content_collection %></p> \ No newline at end of file