Class: WebsiteSection
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- WebsiteSection
- Extended by:
- FriendlyId
- Includes:
- ErpTechSvcs::Utils::DefaultNestedSetMethods
- Defined in:
- app/models/website_section.rb
Direct Known Subclasses
Constant Summary collapse
- KNIT_KIT_ROOT =
Knitkit::Engine.root.to_s
- WEBSITE_SECTIONS_TEMP_LAYOUT_PATH =
"#{Knitkit::Engine.root.to_s}/app/views/knitkit/website_sections"- @@types =
['Page']
Class Method Summary collapse
Instance Method Summary collapse
- #articles ⇒ Object
- #build_section_hash ⇒ Object
- #child_by_path(path) ⇒ Object
- #create_layout ⇒ Object
- #display_in_menu? ⇒ Boolean
- #get_published_layout(active_publication) ⇒ Object
- #get_tags ⇒ Object
- #get_topics ⇒ Object
- #iid ⇒ Object
- #is_blog? ⇒ Boolean
- #is_document_section? ⇒ Boolean
- #is_section? ⇒ Boolean
- #is_secured? ⇒ Boolean
- #paths ⇒ Object
- #positioned_children ⇒ Object
- #render_base_layout? ⇒ Boolean
- #secure ⇒ Object
- #should_generate_new_friendly_id? ⇒ Boolean
- #type ⇒ Object
- #update_path! ⇒ Object
- #website ⇒ Object
Class Method Details
.register_type(type) ⇒ Object
35 36 37 38 |
# File 'app/models/website_section.rb', line 35 def register_type(type) @@types << type @@types.uniq! end |
Instance Method Details
#articles ⇒ Object
58 59 60 |
# File 'app/models/website_section.rb', line 58 def articles Article.find_by_section_id(self.id) end |
#build_section_hash ⇒ Object
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
# File 'app/models/website_section.rb', line 145 def build_section_hash section_hash = { :name => self.title, :has_layout => !self.layout.blank?, :type => self.class.to_s, :in_menu => self., :articles => [], :roles => self.roles.collect(&:internal_identifier), :path => self.path, :permalink => self.permalink, :internal_identifier => self.internal_identifier, :render_base_layout => self.render_base_layout, :position => self.position, :sections => self.children.each.map{|child| child.build_section_hash} } self.contents.each do |content| content_area = content.content_area_by_website_section(self) position = content.position_by_website_section(self) section_hash[:articles] << { :name => content.title, :tag_list => content.tag_list.join(', '), :content_area => content_area, :position => position, :display_title => content.display_title, :internal_identifier => content.internal_identifier } end section_hash end |
#child_by_path(path) ⇒ Object
79 80 81 |
# File 'app/models/website_section.rb', line 79 def child_by_path(path) self.descendants.detect{|child| child.path == path} end |
#create_layout ⇒ Object
103 104 105 106 |
# File 'app/models/website_section.rb', line 103 def create_layout self.layout = IO.read(File.join(WEBSITE_SECTIONS_TEMP_LAYOUT_PATH,"index.html.erb")) self.save end |
#display_in_menu? ⇒ Boolean
91 92 93 |
# File 'app/models/website_section.rb', line 91 def self. end |
#get_published_layout(active_publication) ⇒ Object
108 109 110 111 112 113 114 115 116 117 |
# File 'app/models/website_section.rb', line 108 def get_published_layout(active_publication) published_website_id = active_publication.id published_element = PublishedElement.includes([:published_website]).where('published_websites.id = ? and published_element_record_id = ? and published_element_record_type = ?', published_website_id, self.id, 'WebsiteSection').first unless published_element.nil? layout_content = WebsiteSection::Version.where('version = ? and website_section_id = ?', published_element.version, published_element.published_element_record_id).first.layout else layout_content = IO.read(File.join(WEBSITE_SECTIONS_TEMP_LAYOUT_PATH,"index.html.erb")) end layout_content end |
#get_tags ⇒ Object
119 120 121 |
# File 'app/models/website_section.rb', line 119 def get_topics end |
#get_topics ⇒ Object
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'app/models/website_section.rb', line 123 def get_topics # leaving this here for reference until we're sure the built in method tag_counts_on does what we need # sql = "SELECT tags.*, taggings.tags_count AS count FROM \"tags\" # JOIN (SELECT taggings.tag_id, COUNT(taggings.tag_id) AS tags_count FROM \"taggings\" # INNER JOIN contents ON contents.id = taggings.taggable_id AND contents.type = 'Article' # INNER JOIN website_section_contents ON contents.id=website_section_contents.content_id # WHERE (taggings.taggable_type = 'Content' AND taggings.context = 'tags') # AND website_section_contents.website_section_id=#{self.id} # GROUP BY taggings.tag_id HAVING COUNT(*) > 0 AND COUNT(taggings.tag_id) > 0) # AS taggings ON taggings.tag_id = tags.id # ORDER BY tags.name ASC" # ActsAsTaggableOn::Tag.find_by_sql(sql) self.contents.tag_counts_on(:tags).sort_by{|t| t.name } end |
#iid ⇒ Object
54 55 56 |
# File 'app/models/website_section.rb', line 54 def iid internal_identifier end |
#is_blog? ⇒ Boolean
41 42 43 |
# File 'app/models/website_section.rb', line 41 def is_blog? self.is_a?(Blog) || self.attributes['type'] == 'Blog' end |
#is_document_section? ⇒ Boolean
99 100 101 |
# File 'app/models/website_section.rb', line 99 def is_document_section? type == 'OnlineDocumentSection' end |
#is_section? ⇒ Boolean
87 88 89 |
# File 'app/models/website_section.rb', line 87 def is_section? ['Page', 'Blog'].include? type end |
#is_secured? ⇒ Boolean
95 96 97 |
# File 'app/models/website_section.rb', line 95 def is_secured? self.protected_with_capability?('view') end |
#paths ⇒ Object
74 75 76 77 |
# File 'app/models/website_section.rb', line 74 def paths all_paths = [self.path] all_paths | self.descendants.collect(&:path) end |
#positioned_children ⇒ Object
70 71 72 |
# File 'app/models/website_section.rb', line 70 def positioned_children children.sort_by{|child| [child.position]} end |
#render_base_layout? ⇒ Boolean
66 67 68 |
# File 'app/models/website_section.rb', line 66 def render_base_layout? render_base_layout end |
#secure ⇒ Object
45 46 47 48 49 50 51 52 |
# File 'app/models/website_section.rb', line 45 def secure capability = self.add_capability(:view) roles = ['admin', 'website_author', self.website.website_role_iid] roles.each do |role| role = SecurityRole.find_by_internal_identifier(role) role.add_capability(capability) end end |
#should_generate_new_friendly_id? ⇒ Boolean
9 10 11 |
# File 'app/models/website_section.rb', line 9 def should_generate_new_friendly_id? new_record? end |
#type ⇒ Object
83 84 85 |
# File 'app/models/website_section.rb', line 83 def type read_attribute(:type) || 'Page' end |
#update_path! ⇒ Object
139 140 141 142 143 |
# File 'app/models/website_section.rb', line 139 def update_path! new_path = build_path self.path = new_path unless self.path == new_path self.save end |
#website ⇒ Object
62 63 64 |
# File 'app/models/website_section.rb', line 62 def website website_id.nil? ? self.parent.website : Website.find(website_id) end |