diff options
Diffstat (limited to 'app/models')
| -rw-r--r-- | app/models/flag.rb | 3 | ||||
| -rw-r--r-- | app/models/page.rb | 22 |
2 files changed, 14 insertions, 11 deletions
diff --git a/app/models/flag.rb b/app/models/flag.rb new file mode 100644 index 0000000..6d67377 --- /dev/null +++ b/app/models/flag.rb | |||
| @@ -0,0 +1,3 @@ | |||
| 1 | class Flag < ActiveRecord::Base | ||
| 2 | has_and_belongs_to_many :pages | ||
| 3 | end | ||
diff --git a/app/models/page.rb b/app/models/page.rb index 3d02e9f..d5d888f 100644 --- a/app/models/page.rb +++ b/app/models/page.rb | |||
| @@ -1,9 +1,19 @@ | |||
| 1 | class Page < ActiveRecord::Base | 1 | class Page < ActiveRecord::Base |
| 2 | 2 | ||
| 3 | belongs_to :node | 3 | belongs_to :node |
| 4 | has_and_belongs_to_many :flags | ||
| 4 | 5 | ||
| 5 | acts_as_list :column => :revision, :scope => :node_id | 6 | acts_as_list :column => :revision, :scope => :node_id |
| 6 | 7 | ||
| 8 | named_scope :with_flags, lambda {|flag_names| | ||
| 9 | if (flags = Flag.find_all_by_name(flag_names)).empty? | ||
| 10 | {} | ||
| 11 | else | ||
| 12 | {:include => :flags, :conditions => ['flags_pages.flag_id IN (?)', flags.map(&:id)] } | ||
| 13 | end | ||
| 14 | } | ||
| 15 | |||
| 16 | |||
| 7 | 17 | ||
| 8 | # <aggregate | 18 | # <aggregate |
| 9 | # flags="updates pressemitteilungen" | 19 | # flags="updates pressemitteilungen" |
| @@ -29,14 +39,4 @@ class Page < ActiveRecord::Base | |||
| 29 | :order => "#{options[:order_by]} #{options[:order_direction]}" | 39 | :order => "#{options[:order_by]} #{options[:order_direction]}" |
| 30 | ) | 40 | ) |
| 31 | end | 41 | end |
| 32 | end | 42 | end \ No newline at end of file |
| 33 | |||
| 34 | |||
| 35 | named_scope :flagged_as, lambda { |flags| | ||
| 36 | conditions = {} | ||
| 37 | flags.each do |flag| | ||
| 38 | conditions[flag] = true | ||
| 39 | end | ||
| 40 | |||
| 41 | { :conditions => conditions } | ||
| 42 | } \ No newline at end of file | ||
