summaryrefslogtreecommitdiff
path: root/app/models/page.rb
blob: d5d888fdb0a371e548c9190c5233c6b8eccb8ba6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
class Page < ActiveRecord::Base
  
  belongs_to :node
  has_and_belongs_to_many :flags
  
  acts_as_list :column => :revision, :scope => :node_id
  
  named_scope :with_flags, lambda {|flag_names| 
    if (flags = Flag.find_all_by_name(flag_names)).empty?
      {}
    else
      {:include => :flags, :conditions => ['flags_pages.flag_id IN (?)', flags.map(&:id)] }
    end
  }
  
  
  
  # <aggregate 
  #   flags="updates pressemitteilungen"
  #   path="updates/2009"
  #   limit="20"
  #   order_by="published_at"
  #   order_direction="DESC"
  # />
  def self.aggregate options
    
    defaults = {
      :flags            => "",
      :path             => "",
      :limit            => 20,
      :order_by         => "id",
      :order_direction  => "ASC"
    }
    
    options = defaults.merge options
    
    pages = Page.all(
      :limit => options[:limit],
      :order => "#{options[:order_by]} #{options[:order_direction]}"
    )
  end
end