Class: Content
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Content
show all
- Defined in:
- app/models/content.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.do_search(options = {}) ⇒ Object
39
40
41
42
43
44
45
46
47
48
49
|
# File 'app/models/content.rb', line 39
def self.do_search(options = {})
@results = Content.search(options)
@search_results = build_search_results(@results)
@page_results = WillPaginate::Collection.create(options[:page], options[:per_page], @results.total_entries) do ||
.replace(@search_results)
end
return @page_results
end
|
.find_by_section_id(website_section_id) ⇒ Object
51
52
53
|
# File 'app/models/content.rb', line 51
def self.find_by_section_id( website_section_id )
Content.joins(:website_section_contents).where('website_section_id = ?', website_section_id).order("website_section_contents.position ASC, website_section_contents.created_at DESC").all
end
|
.find_by_section_id_filtered_by_id(website_section_id, id_filter_list) ⇒ Object
55
56
57
|
# File 'app/models/content.rb', line 55
def self.find_by_section_id_filtered_by_id( website_section_id, id_filter_list )
Content.joins(:website_section_contents).where("website_section_id = ? AND contents.id IN (#{id_filter_list.join(',')})", website_section_id).all
end
|
.find_published_by_section(active_publication, website_section) ⇒ Object
59
60
61
62
63
64
65
66
67
68
|
# File 'app/models/content.rb', line 59
def self.find_published_by_section(active_publication, website_section)
published_content = []
contents = self.find_by_section_id( website_section.id )
contents.each do |content|
content = get_published_version(active_publication, content)
published_content << content unless content.nil?
end
published_content
end
|
.find_published_by_section_with_tag(active_publication, website_section, tag) ⇒ Object
70
71
72
73
74
75
76
77
78
79
80
|
# File 'app/models/content.rb', line 70
def self.find_published_by_section_with_tag(active_publication, website_section, tag)
published_content = []
id_filter_list = self.tagged_with(tag.name).collect{|t| t.id }
contents = self.find_by_section_id_filtered_by_id( website_section.id, id_filter_list )
contents.each do |content|
content = get_published_version(active_publication, content)
published_content << content unless content.nil?
end
published_content
end
|
.search(options = {}) ⇒ Object
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'app/models/content.rb', line 19
def self.search(options = {})
if options[:section_unique_name].nil? or options[:section_unique_name].empty?
section_scope = ''
else
section_scope = "website_sections.internal_identifier = '#{options[:section_unique_name]}' AND"
end
if options[:content_type].nil? or options[:content_type].empty?
content_type_scope = ''
else
content_type_scope = "website_sections.type = '#{options[:content_type]}' AND"
end
Content.includes([:website_sections]).where("#{content_type_scope} #{section_scope}
website_sections.website_id = #{options[:website_id]} AND
(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").paginate(:page => options[:page], :per_page => options[:per_page])
end
|
Instance Method Details
#assign_attribute_on_save ⇒ Object
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
|
# File 'app/models/content.rb', line 120
def assign_attribute_on_save
super
Article.find_by_internal_identifier(self.internal_identifier) ? attribute_type_description = "updated_by_role" : attribute_type_description = "created_by_role"
if attribute_type_description == "created_by_role"
user = self.created_by
else
user = User.find(self.versions.sort_by {|version| version.version}.reverse[0].created_by_id)
end
if user
self.destroy_values_of_type attribute_type_description
attribute_type = AttributeType.find_by_internal_identifier(attribute_type_description)
attribute_type = AttributeType.create(:description => attribute_type_description, :data_type => "Text") unless attribute_type
user.roles.each do |role|
new_value = AttributeValue.new(:value => role.internal_identifier)
attribute_type.attribute_values << new_value
self.attribute_values << new_value
new_value.save
end
end
end
|
#content_area_by_website_section(section) ⇒ Object
104
105
106
107
108
109
110
|
# File 'app/models/content.rb', line 104
def content_area_by_website_section(section)
content_area = nil
unless WebsiteSectionContent.where('content_id = ? and website_section_id = ?',self.id, section.id).first.nil?
content_area = WebsiteSectionContent.where('content_id = ? and website_section_id = ?',self.id, section.id).first.content_area
end
content_area
end
|
#find_website_sections_by_site_id(website_id) ⇒ Object
82
83
84
|
# File 'app/models/content.rb', line 82
def find_website_sections_by_site_id( website_id )
self.website_sections.where('website_id = ?',website_id).all
end
|
91
92
93
|
# File 'app/models/content.rb', line 91
def (limit)
self..recent.limit(limit).all
end
|
#is_published? ⇒ Boolean
147
148
149
|
# File 'app/models/content.rb', line 147
def is_published?
!PublishedElement.where('published_element_record_id = ? and published_element_record_type = ? and published_elements.version = ?', self.id, 'Content', self.version).first.nil?
end
|
#position(website_section_id) ⇒ Object
86
87
88
89
|
# File 'app/models/content.rb', line 86
def position( website_section_id )
position = self.website_section_contents.find_by_website_section_id(website_section_id).position
position
end
|
#position_by_website_section(section) ⇒ Object
112
113
114
115
116
117
118
|
# File 'app/models/content.rb', line 112
def position_by_website_section(section)
position = nil
unless WebsiteSectionContent.where('content_id = ? and website_section_id = ?',self.id, section.id).first.nil?
position = WebsiteSectionContent.where('content_id = ? and website_section_id = ?',self.id, section.id).first.position
end
position
end
|
#update_content_area_and_position_by_section(section, content_area, position) ⇒ Object
95
96
97
98
99
100
101
102
|
# File 'app/models/content.rb', line 95
def update_content_area_and_position_by_section(section, content_area, position)
website_section_content = WebsiteSectionContent.where('content_id = ? and website_section_id = ?',self.id, section.id).first
unless website_section_content.nil?
website_section_content.content_area = content_area
website_section_content.position = position
website_section_content.save
end
end
|