Class: Page
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Page
- Defined in:
- app/models/page.rb
Instance Attribute Summary collapse
-
#no_publish_window ⇒ Object
Returns the value of attribute no_publish_window.
Class Method Summary collapse
- .breadcrumbs_for(user, url) ⇒ Object
- .default_layout ⇒ Object
- .should_be_found?(params) ⇒ Boolean
-
.viewable_by(user) ⇒ Object
Scopes.
- .with_url(request, params) ⇒ Object
Instance Method Summary collapse
- #controller_action ⇒ Object
- #controller_action=(c) ⇒ Object
- #css_status ⇒ Object
- #duplicate ⇒ Object
- #is_child_of?(page) ⇒ Boolean
- #is_parent_of?(page) ⇒ Boolean
- #is_viewable_by?(user) ⇒ Boolean
-
#lft=(x) ⇒ Object
Override the protected methods of awesome_nested_set so lft and rgt can be set.
- #move_children_to_parent ⇒ Object
- #no_publish_window_set? ⇒ Boolean
- #number_of_children ⇒ Object
- #published? ⇒ Boolean
- #rgt=(x) ⇒ Object
- #to_param ⇒ Object
Instance Attribute Details
#no_publish_window ⇒ Object
Returns the value of attribute no_publish_window.
44 45 46 |
# File 'app/models/page.rb', line 44 def no_publish_window @no_publish_window end |
Class Method Details
.breadcrumbs_for(user, url) ⇒ Object
166 167 168 169 |
# File 'app/models/page.rb', line 166 def (user, url) root = Page.published.viewable_by(user).find_by_url(url) root.nil? ? [] : root.self_and_ancestors end |
.default_layout ⇒ Object
171 172 173 |
# File 'app/models/page.rb', line 171 def default_layout PageEngine.layouts.first end |
.should_be_found?(params) ⇒ Boolean
162 163 164 |
# File 'app/models/page.rb', line 162 def should_be_found?(params) PageEngine.required_route_actions.include?(params[:action]) && !PageEngine.excluded_route_controllers.include?(params[:controller]) end |
.viewable_by(user) ⇒ Object
Scopes
177 178 179 180 181 182 183 184 185 186 187 188 |
# File 'app/models/page.rb', line 177 def viewable_by(user) if PageEngine.uses_roles? if user # This is a bit of a kludge until I can figure out how to get it to work properly in a single sql query includes(:page_roles).where("pages.id in (?) or (page_roles.required_role_id is null and page_roles.excluded_role_id is null)", PageRole.viewable_page_ids_for(user)) else includes(:page_roles).where('page_roles.required_role_id' => nil, 'page_roles.excluded_role_id' => nil) end else scoped end end |
.with_url(request, params) ⇒ Object
190 191 192 193 194 195 |
# File 'app/models/page.rb', line 190 def with_url(request, params) url = request.fullpath url.gsub!(/\?.*/, '') # Strip away anything after the ? as it's not needed where(["pages.permalink = ? or url = ? or (controller = ? and action = ?)", params[:permalink], url, params[:controller], params[:action]]) end |
Instance Method Details
#controller_action ⇒ Object
50 51 52 |
# File 'app/models/page.rb', line 50 def controller_action "#{controller}|#{action}" if controller && action end |
#controller_action=(c) ⇒ Object
54 55 56 57 58 59 60 61 62 63 |
# File 'app/models/page.rb', line 54 def controller_action=(c) if c.is_a?(String) controller_and_action = c.split('|') self.controller = controller_and_action.first self.action = controller_and_action.last else self.controller = nil self.action = nil end end |
#css_status ⇒ Object
146 147 148 149 |
# File 'app/models/page.rb', line 146 def css_status return "live" if self.published? status.downcase end |
#duplicate ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'app/models/page.rb', line 93 def duplicate page = Page.new(self.attributes) page.title += " (copy) #{Time.now.strftime('%Y%m%d_%H%M%S')}" page.permalink = page.permalink + "-copy-#{Time.now.strftime('%Y%m%d-%H%M%S')}" page.save page.move_to_right_of self # Duplicate each of the objects associated with the original # Page parts self.page_parts.each do |page_part| page.page_parts << page_part.duplicate end # Roles if PageEngine.uses_roles? page.required_roles = self.required_roles page.excluded_roles = self.excluded_roles end # Assets if PageEngine.class_exists?('Asset') self.attachables.each do |attachable| page.attachables << attachable.duplicate end end page end |
#is_child_of?(page) ⇒ Boolean
81 82 83 |
# File 'app/models/page.rb', line 81 def is_child_of? page self.parent_id == page.id ? true : false end |
#is_parent_of?(page) ⇒ Boolean
85 86 87 |
# File 'app/models/page.rb', line 85 def is_parent_of? page self.id == page.parent_id ? true : false end |
#is_viewable_by?(user) ⇒ Boolean
122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'app/models/page.rb', line 122 def is_viewable_by?(user) if PageEngine.uses_roles? if PageEngine.class_exists?('User') && user return true if self.roles.length == 0 self.role_ids.length != (self.role_ids - user.role_ids.uniq).length else self.roles.length == 0 end else true end end |
#lft=(x) ⇒ Object
Override the protected methods of awesome_nested_set so lft and rgt can be set
152 153 154 |
# File 'app/models/page.rb', line 152 def lft=(x) self[:lft] = x end |
#move_children_to_parent ⇒ Object
135 136 137 138 139 140 141 142 143 144 |
# File 'app/models/page.rb', line 135 def move_children_to_parent self.children.each do |child| if self.parent child.move_to_child_of self.parent else child.move_to_root end end self.reload end |
#no_publish_window_set? ⇒ Boolean
65 66 67 |
# File 'app/models/page.rb', line 65 def no_publish_window_set? self.publish_from.nil? && self.publish_to.nil? end |
#number_of_children ⇒ Object
89 90 91 |
# File 'app/models/page.rb', line 89 def number_of_children (self.rgt - self.lft - 1) / 2 end |
#published? ⇒ Boolean
69 70 71 72 73 74 75 |
# File 'app/models/page.rb', line 69 def published? if self.no_publish_window_set? self.status == "Published" else self.publish_from < DateTime.now && self.publish_to > DateTime.now && self.status == "Published" end end |
#rgt=(x) ⇒ Object
156 157 158 |
# File 'app/models/page.rb', line 156 def rgt=(x) self[:rgt] = x end |
#to_param ⇒ Object
77 78 79 |
# File 'app/models/page.rb', line 77 def to_param permalink end |