This repository has been archived on 2024-03-16. You can view files and clone it, but cannot push or open issues or pull requests.
orbit-4-1/app/models/page.rb

40 lines
1.0 KiB
Ruby
Raw Normal View History

2010-01-04 07:52:30 +00:00
class Page
include MongoMapper::Document
2010-01-11 09:09:50 +00:00
key :name, String, :required => true, :index => true
key :parent_page_name, String, :required => true, :index => true
2010-01-08 07:32:44 +00:00
2010-01-11 09:09:50 +00:00
key_i18n :title, String, :required => true
2010-01-08 07:32:44 +00:00
key_i18n :content, String
2010-01-04 07:52:30 +00:00
2010-01-11 09:09:50 +00:00
key :layout_name, String, :required => true
2010-01-04 07:52:30 +00:00
key :external_link, String
2010-01-11 09:09:50 +00:00
key :position, Integer, :required => true
key :is_published, Boolean, :required => true, :default => true, :index => true
2009-05-07 17:54:33 +00:00
2010-01-08 10:36:36 +00:00
key :component_name, String
2009-05-22 06:43:52 +00:00
before_validation :setup_default_value
2010-01-04 07:52:30 +00:00
def self.find_by_name(page_name)
Page.find(:first, :conditions => { :name => page_name, :is_published => true })
end
2010-01-11 09:09:50 +00:00
def layout
Layout.find_by_name(self.layout_name)
2009-05-07 17:54:33 +00:00
end
2010-01-11 09:09:50 +00:00
protected
2009-05-22 06:43:52 +00:00
def setup_default_value
2009-05-22 06:51:32 +00:00
if self.position.blank?
2010-01-04 07:52:30 +00:00
max_page = Page.find(:last, :order => 'position')
2009-05-22 06:43:52 +00:00
self.position = (max_page)? max_page.position.to_i + 1 : 1
end
2010-01-08 10:36:36 +00:00
if self.parent_page_name.blank?
self.parent_page_name = "root"
2009-05-22 06:43:52 +00:00
end
end
end