Class: Skyline::Page
Defined Under Namespace
Classes: Data
Class Method Summary
collapse
Instance Method Summary
collapse
#add_index, #evaluate_if_option, #hash_searchable_fields, #remove_from_index, #solr_id, #solr_typecast
Methods inherited from Article
#data_class, #depublish, #depublishable?, #destroy, #editable_by?, #enable_locking?, #enable_multiple_variants?, #enable_publishing?, #preview_wrapper_page, #previewable?, publishable?, #published?, #renderable?, #renderable_scope, #right_prefix, #rollbackable?, #set_default_variant, #set_default_variant!, #site, #sites, #title, to_param
Class Method Details
.find_by_url(url_parts, root = nil) ⇒ Object
135
136
137
138
139
140
141
142
143
|
# File 'app/models/skyline/page.rb', line 135
def find_by_url(url_parts, root = nil)
root ||= self.root
return nil unless root
return [root, []] if url_parts.empty?
if child = root.children.find_by_url_part(url_parts.first)
return self.find_by_url(url_parts[1..-1], child)
end
return [root, url_parts]
end
|
.group_by_parent_id ⇒ Object
returns an Array of hashes
Returns
- <Array>
-
Array of hashes grouped by parent_id
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
# File 'app/models/skyline/page.rb', line 73
def group_by_parent_id
out = {}
pages = self.connection.select_all("
SELECT page.id,
page.parent_id,
data.navigation_title as navigation_title,
data.title as title,
page.locked,
page.published_publication_id,
page.default_variant_id,
published_publication.variant_id AS published_publication_variant_id,
published_publication.version AS published_publication_version,
default_variant.version AS default_variant_version
FROM #{self.table_name} AS page
LEFT JOIN skyline_page_data AS data ON data.id=page.default_variant_data_id
LEFT JOIN skyline_article_versions AS published_publication ON published_publication.id=page.published_publication_id
LEFT JOIN skyline_article_versions AS default_variant ON default_variant.id=default_variant_id
WHERE page.type='Skyline::Page'
ORDER BY page.position")
pages.each do |o|
class << o
def id; self["id"].to_i; end
def parent_id; self["parent_id"].blank? ? nil : self["parent_id"].to_i; end
def title
if self["navigation_title"].blank?
self["title"].blank? ? "n/a" : self["title"]
else
self["navigation_title"]
end
end
def published?; self["published_publication_id"].present?; end
def identical_to_publication?
self["published_publication_variant_id"] == self["default_variant_id"] && self["published_publication_version"] == self["default_variant_version"]
end
end
out[o.parent_id] ||= []
out[o.parent_id] << o
end
out
end
|
build menu of certain level
Parameters
- level<Integer>
-
level of the menu that has to be returned
- nesting<Array>
-
the nesting of page starting with the root node
Returns
- <Array>
-
an array of pages to display in the menu
127
128
129
130
131
132
133
|
# File 'app/models/skyline/page.rb', line 127
def (level = 1, nesting = nil)
= []
<< {:page => self.root, :children => []} if level == 1 && self.root.in_navigation?
nesting ||= [self.root]
+= nesting[level-1]. if nesting[level-1]
end
|
.reorder(pages) ⇒ Object
145
146
147
148
149
150
|
# File 'app/models/skyline/page.rb', line 145
def reorder(pages)
return unless pages.kind_of?(Array)
pages.each_with_index do |parent_id, position|
self.connection.execute("UPDATE #{self.table_name} SET position=#{position.to_i} WHERE id=#{parent_id.to_i}")
end
end
|
.right_prefix ⇒ Object
65
66
67
|
# File 'app/models/skyline/page.rb', line 65
def right_prefix
"page"
end
|
.root ⇒ Object
116
117
118
|
# File 'app/models/skyline/page.rb', line 116
def root
self.find_by_parent_id(nil)
end
|
Instance Method Details
#create_new!(position) ⇒ Object
create a new page on position
Parameters
- position<Symbol>
-
Can either be :below, :above or :in
Returns
- <Page>
-
The new page
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
|
# File 'app/models/skyline/page.rb', line 200
def create_new!(position)
page = Skyline::Page.new
self.class.transaction do
case position
when :below
page.parent = self.parent
page.position = self.position + 1
self.class.connection.execute("UPDATE #{self.class.table_name} SET position=position+1 WHERE #{self.parent ? "parent_id=#{self.parent.id}" : 'parent_id IS NULL'} AND position>#{self.position}")
when :above
page.parent = self.parent
page.position = self.position
self.class.connection.execute("UPDATE #{self.class.table_name} SET position=position+1 WHERE #{self.parent ? "parent_id=#{self.parent.id}" : 'parent_id IS NULL'} AND position>=#{self.position}")
when :in
page.parent = self
end
page.sites << self.site
page.save
end
page
end
|
#destroyable? ⇒ Boolean
185
186
187
|
# File 'app/models/skyline/page.rb', line 185
def destroyable?
!self.persistent? && self.children.empty? && self.published_publication == nil
end
|
#keep_history? ⇒ Boolean
189
190
191
|
# File 'app/models/skyline/page.rb', line 189
def keep_history?
Skyline::Configuration.enable_publication_history
end
|
181
182
183
|
# File 'app/models/skyline/page.rb', line 181
def
self.children.collect{|child| {:page => child, :children => child.} if child.published_publication_data.andand.in_navigation?}.compact
end
|
#move_behind=(parent_id) ⇒ Object
223
224
225
226
|
# File 'app/models/skyline/page.rb', line 223
def move_behind=(parent_id)
@do_move_behind = true
@move_behind = parent_id
end
|
#nesting ⇒ Object
157
158
159
|
# File 'app/models/skyline/page.rb', line 157
def nesting
self.root? ? [self] : self.parent.nesting + [self]
end
|
#parents ⇒ Object
162
163
164
|
# File 'app/models/skyline/page.rb', line 162
def parents
self.nesting.dup[0..-2]
end
|
#path ⇒ Object
Returns the path (url excluding current url_path), with trailing / for the root page: nil pages directly in the root: / other pages, ie: /a/b/c/
170
171
172
173
174
|
# File 'app/models/skyline/page.rb', line 170
def path
return nil if self.root?
path = "/" + self.parents[1..-1].collect{|page| page.url_part}.join("/") + "/"
path.squeeze("/")
end
|
#root? ⇒ Boolean
153
154
155
|
# File 'app/models/skyline/page.rb', line 153
def root?
!self.parent
end
|
#url ⇒ Object
176
177
178
179
|
# File 'app/models/skyline/page.rb', line 176
def url
return "/" if self.root?
self.path + self.url_part
end
|