Class: Section
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Section
- Defined in:
- app/models/section.rb
Overview
This model is used to represent a website section. It has specified acts_as_content_node from Acts::ContentNode::ClassMethods.
Specification
Attributes
-
title - The title of the section.
-
description - The description of the section.
-
frontpage_node - The node that is the frontpage of this Section. Can be blank.
Preconditions
-
Requires the presence of title.
-
Requires frontpage_node to be nil if the Section has a frontpage.
-
Requires frontpage_node of the Section to be a descendant of the Section.
-
Requires frontpage_node to not be a Section with a frontpage_node.
Child/parent type constraints
* A Section accepts nodes of any type.
* A Section can be inserted into nodes of any accepting type.
Direct Known Subclasses
Class Method Summary (collapse)
-
+ (Object) max_number_of_columns
Returns the maximum number of sidebox (content box) columns that are allowed for this content type.
-
+ (Object) owms_type
Returns the OWMS type.
Instance Method Summary (collapse)
-
- (Object) accessible_children_for(user, exclude_content_types = ['Image','Attachment'])
Returns the children content nodes of this section for the given user.
-
- (Object) content_tokens
Returns the description as the token for indexing.
-
- (Object) frontpage
Returns the frontpage if one is present.
-
- (Boolean) has_frontpage?
Returns true if the section has a frontpage.
-
- (Object) last_updated_at(user)
Returns the last update date, as seen from the perspective of the given user.
-
- (Object) set_frontpage!(node)
Sets the frontpage to the given node.
Class Method Details
+ (Object) max_number_of_columns
Returns the maximum number of sidebox (content box) columns that are allowed for this content type.
73 74 75 |
# File 'app/models/section.rb', line 73 def self.max_number_of_columns 4 end |
+ (Object) owms_type
Returns the OWMS type.
104 105 106 |
# File 'app/models/section.rb', line 104 def self.owms_type I18n.t('owms.overview_page') end |
Instance Method Details
- (Object) accessible_children_for(user, exclude_content_types = ['Image','Attachment'])
Returns the children content nodes of this section for the given user. By default images and attachments are excluded.
99 100 101 |
# File 'app/models/section.rb', line 99 def accessible_children_for(user, exclude_content_types = ['Image','Attachment']) node.accessible_content_children(:for => user, :exclude_content_type => exclude_content_types) end |
- (Object) content_tokens
Returns the description as the token for indexing.
78 79 80 |
# File 'app/models/section.rb', line 78 def content_tokens description end |
- (Object) frontpage
Returns the frontpage if one is present.
88 89 90 |
# File 'app/models/section.rb', line 88 def frontpage has_frontpage? ? self.frontpage_node.content : nil end |
- (Boolean) has_frontpage?
Returns true if the section has a frontpage.
83 84 85 |
# File 'app/models/section.rb', line 83 def has_frontpage? !self.frontpage_node.nil? end |
- (Object) last_updated_at(user)
Returns the last update date, as seen from the perspective of the given user.
63 64 65 66 67 68 69 70 |
# File 'app/models/section.rb', line 63 def last_updated_at(user) conditions = [ "NOT nodes.content_type IN (?)", [ 'Image', 'Attachment' ] ] descendant_conditions = self.node.descendant_conditions conditions.first << " AND " << descendant_conditions.shift conditions.concat(descendant_conditions) child = Node.find_accessible(:first, :for => user, :select => 'nodes.updated_at', :order => 'nodes.updated_at DESC', :conditions => conditions) child ? child.updated_at : self.updated_at end |
- (Object) set_frontpage!(node)
Sets the frontpage to the given node.
93 94 95 |
# File 'app/models/section.rb', line 93 def set_frontpage!(node) self.update_attributes(:frontpage_node => node) end |