Class: DocumentedContent
- Inherits:
-
Content
- Object
- ActiveRecord::Base
- Content
- DocumentedContent
show all
- Defined in:
- app/models/documented_content.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Content
#assign_attribute_on_save, #content_area_by_website_section, do_search, find_by_section_id, find_by_section_id_filtered_by_id, find_published_by_section_with_tag, #find_website_sections_by_site_id, #get_comments, #is_published?, #position, #position_by_website_section, #should_generate_new_friendly_id?, #update_content_area_and_position_by_section
Class Method Details
.build_search_results(results) ⇒ Object
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
# File 'app/models/documented_content.rb', line 59
def self.build_search_results(results)
results_array = []
results.each do |content|
section = DocumentedItem.find_by_documented_content_id(content.id).online_document_section
results_hash = {}
results_hash[:internal_identifier] = section.internal_identifier
if section.attributes['type'] == 'Blog'
results_hash[:link] = section.path + '/' + content.permalink
results_hash[:title] = content.title
else
results_hash[:link] = section.path
results_hash[:title] = section.title
end
results_hash[:section] = section
results_hash[:content] = content
results_array << results_hash
end
results_array
end
|
.find_published_by_section(active_publication, website_section) ⇒ Object
17
18
19
20
21
22
23
24
25
26
27
|
# File 'app/models/documented_content.rb', line 17
def self.find_published_by_section(active_publication, website_section)
published_content = []
documented_item = DocumentedItem.where(["online_document_section_id = ?", website_section.id]).first
if documented_item
documented_content = DocumentedContent.find(documented_item.documented_content_id)
content = get_published_version(active_publication, documented_content)
published_content << content unless content.nil?
end
published_content.first
end
|
.search(options = {}) ⇒ Object
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
# File 'app/models/documented_content.rb', line 29
def self.search(options = {})
predicate = self.joins('inner join documented_items on documented_items.documented_content_id = contents.id')
.joins('inner join website_sections on website_sections.id = documented_items.online_document_section_id')
if options[:section_unique_name]
predicate = predicate.where("website_sections.internal_identifier = ?", options[:section_unique_name])
end
if options[:parent_id]
predicate = predicate.where("website_sections.id" => WebsiteSection.find(options[:parent_id]).descendants.collect(&:id))
end
if options[:content_type]
predicate = predicate.where("website_sections.type = ?", options[:content_type])
end
if options[:website_id]
predicate = predicate.where("website_sections.website_id = ?", options[:website_id])
end
predicate = predicate.where("(UPPER(contents.title) LIKE UPPER('%#{options[:query]}%')
OR UPPER(contents.excerpt_html) LIKE UPPER('%#{options[:query]}%')
OR UPPER(contents.body_html) LIKE UPPER('%#{options[:query]}%') )").order("contents.created_at DESC")
if options[:page]
predicate.paginate(:page => options[:page], :per_page => options[:per_page])
else
predicate.all
end
end
|
Instance Method Details
#check_internal_identifier ⇒ Object
9
10
11
|
# File 'app/models/documented_content.rb', line 9
def check_internal_identifier
self.internal_identifier = self.permalink if self.internal_identifier.blank?
end
|
#content_hash ⇒ Object
13
14
15
|
# File 'app/models/documented_content.rb', line 13
def content_hash
{:id => self.id, :title => self.title, :body_html => self.body_html}
end
|
#to_param ⇒ Object
5
6
7
|
# File 'app/models/documented_content.rb', line 5
def to_param
permalink
end
|