Class: CamaleonCms::Post

Inherits:
PostDefault
  • Object
show all
Includes:
CategoriesTagsForPosts
Defined in:
app/models/camaleon_cms/post.rb

Instance Attribute Summary collapse

Attributes inherited from PostDefault

#draft_id

Instance Method Summary collapse

Methods included from CategoriesTagsForPosts

#assign_category, #assign_tags, #manage_categories?, #manage_tags?, #unassign_category, #unassign_tags, #update_categories, #update_extra_data, #update_tags

Methods inherited from PostDefault

#author, find_by_slug, #in_nav_menu_items, #parent, #set_params

Methods included from CustomFieldsRead

#add_custom_field_group, #add_custom_field_to_default_group, #get_field_groups, #get_field_object, #get_field_value, #get_field_values, #get_field_values_hash, #get_fields_grouped, #get_fields_object, #get_user_field_groups, #save_field_value, #set_field_value, #set_field_values, #update_field_value

Methods included from Metas

#delete_meta, #delete_option, #fix_save_metas_options_no_changed, #get_meta, #get_option, #options, #save_metas_options, #save_metas_options_skip, #set_meta, #set_metas, #set_option, #set_options

Instance Attribute Details

#show_title_with_parentObject

Returns the value of attribute show_title_with_parent.



59
60
61
# File 'app/models/camaleon_cms/post.rb', line 59

def show_title_with_parent
  @show_title_with_parent
end

Instance Method Details

#can_commented?Boolean

check if the post can be commented sample: @post.can_commented? return Boolean (true/false)

Returns:

  • (Boolean)


152
153
154
# File 'app/models/camaleon_cms/post.rb', line 152

def can_commented?
  manage_comments? && get_meta('has_comments').to_s == "1"
end

#decorator_classObject



239
240
241
# File 'app/models/camaleon_cms/post.rb', line 239

def decorator_class
  (self.post_type.get_option('cama_post_decorator_class', 'CamaleonCms::PostDecorator') rescue 'CamaleonCms::PostDecorator').constantize
end

#draft?Boolean

check if this is in draft status

Returns:

  • (Boolean)


99
100
101
# File 'app/models/camaleon_cms/post.rb', line 99

def draft?
  status == 'draft'
end

#full_childrenObject

return all children elements for current post (page hierarchy)



75
76
77
78
79
80
81
# File 'app/models/camaleon_cms/post.rb', line 75

def full_children
  cama_fetch_cache("full_children_#{self.id}") do
    res = self.children.to_a
    res.each{|c|  res += c.full_children }
    res
  end
end

#get_layout(posttype = nil) ⇒ Object

return the layout assigned to this post post_type: post type owner of this post



207
208
209
210
# File 'app/models/camaleon_cms/post.rb', line 207

def get_layout(posttype = nil)
  return get_option("default_layout") if !manage_layout?(posttype)
  get_meta('layout', get_option("default_layout") || (posttype || self.post_type).get_option('default_layout', nil))
end

#get_post_type_depreObject

return the post type of this post (DEPRECATED)



84
85
86
# File 'app/models/camaleon_cms/post.rb', line 84

def get_post_type_depre
  post_types.reorder(nil).first
end

#get_template(posttype = nil) ⇒ Object

return the template assigned to this post verify default template defined in post type post_type: post type owner of this post



215
216
217
218
# File 'app/models/camaleon_cms/post.rb', line 215

def get_template(posttype = nil)
  return get_option("default_template") if !manage_template?(posttype)
  get_meta('template', get_option("default_template") || (posttype || self.post_type).get_option('default_template', nil))
end

#increment_visits!Object

increment the counter of visitors



221
222
223
# File 'app/models/camaleon_cms/post.rb', line 221

def increment_visits!
  set_meta("visits", total_visits+1)
end

#manage_comments?(posttype = nil) ⇒ Boolean

check if current post can manage comments return boolean

Returns:

  • (Boolean)


145
146
147
# File 'app/models/camaleon_cms/post.rb', line 145

def manage_comments?(posttype = nil)
  get_option('has_comments', (posttype || self.post_type).get_option('has_comments', false))
end

#manage_content?(posttype = nil) ⇒ Boolean

check if current post can manage content return boolean

Returns:

  • (Boolean)


110
111
112
# File 'app/models/camaleon_cms/post.rb', line 110

def manage_content?(posttype = nil)
  get_option('has_content', (posttype || self.post_type).get_option('has_content', true))
end

#manage_keywords?(posttype = nil) ⇒ Boolean

check if current post can manage keywords return boolean

Returns:

  • (Boolean)


133
134
135
# File 'app/models/camaleon_cms/post.rb', line 133

def manage_keywords?(posttype = nil)
  get_option('has_keywords', (posttype || self.post_type).get_option('has_keywords', true))
end

#manage_layout?(posttype = nil) ⇒ Boolean

return boolean

Returns:

  • (Boolean)


115
116
117
# File 'app/models/camaleon_cms/post.rb', line 115

def manage_layout?(posttype = nil)
  get_option('has_layout', (posttype || self.post_type).get_option('has_layout', false))
end

#manage_picture?(posttype = nil) ⇒ Boolean

check if current post can manage picture return boolean

Returns:

  • (Boolean)


139
140
141
# File 'app/models/camaleon_cms/post.rb', line 139

def manage_picture?(posttype = nil)
  get_option('has_picture', (posttype || self.post_type).get_option('has_picture', true))
end

#manage_summary?(posttype = nil) ⇒ Boolean

check if current post can manage summary return boolean

Returns:

  • (Boolean)


127
128
129
# File 'app/models/camaleon_cms/post.rb', line 127

def manage_summary?(posttype = nil)
  get_option('has_summary', (posttype || self.post_type).get_option('has_summary', true))
end

#manage_template?(posttype = nil) ⇒ Boolean

check if current post can manage template return boolean

Returns:

  • (Boolean)


121
122
123
# File 'app/models/camaleon_cms/post.rb', line 121

def manage_template?(posttype = nil)
  get_option('has_template', (posttype || self.post_type).get_option('has_template', true))
end

#parentsObject

return all parents for current page hierarchy ordered bottom to top



62
63
64
65
66
67
68
69
70
71
72
# File 'app/models/camaleon_cms/post.rb', line 62

def parents
  cama_fetch_cache("parents_#{self.id}") do
    res = []
    p = self.parent
    while p.present?
      res << p
      p = p.parent
    end
    res
  end
end

#pending?Boolean

check if this is in pending status

Returns:

  • (Boolean)


94
95
96
# File 'app/models/camaleon_cms/post.rb', line 94

def pending?
  status == 'pending'
end

#published?Boolean

check if this post was published

Returns:

  • (Boolean)


89
90
91
# File 'app/models/camaleon_cms/post.rb', line 89

def published?
  status == 'published'
end

#set_layout(layout_name) ⇒ Object

save the layout name to be used on render this post layout_name: String layout name: my_layout.html.erb => ‘my_layout’



201
202
203
# File 'app/models/camaleon_cms/post.rb', line 201

def set_layout(layout_name)
  set_meta("layout", layout_name)
end

#set_position(new_order_position) ⇒ Object

put a new order position for this post new_order_position: (Integer) position number return nil



183
184
185
# File 'app/models/camaleon_cms/post.rb', line 183

def set_position(new_order_position)
  self.update_column("post_order", new_order_position)
end

#set_setting(key, val) ⇒ Object

define post configuration for current post possible key values (String):

has_content, boolean (default true)
has_summary, boolean (default true)
has_keywords, boolean (default true)
has_picture, boolean (default true)
has_template, boolean (default false)
has_comments, boolean (default false)
default_layout:  (string) (default layout) # this is still used if post type was inactivated layout and overwritten by dropdown in post view
default_template:  (string) (default template) # this is still used if post type was inactivated template and overwritten by dropdown in post view
has_layout:  (boolean) (default false)
skip_fields:  (array) (default empty) array of custom field keys to avoid for this post, sample: ["subtitle", "icon"]

val: value for the setting



169
170
171
# File 'app/models/camaleon_cms/post.rb', line 169

def set_setting(key, val)
  set_option(key, val)
end

#set_settings(settings = {}) ⇒ Object

assign multiple settings



174
175
176
177
178
# File 'app/models/camaleon_cms/post.rb', line 174

def set_settings(settings = {})
  settings.each do |key, val|
    set_setting(key, val)
  end
end

#set_summary(summary) ⇒ Object

save the summary for current post summary: Text String without html



189
190
191
# File 'app/models/camaleon_cms/post.rb', line 189

def set_summary(summary)
  set_meta("summary", summary)
end

#set_thumb(thumb_url) ⇒ Object

save the thumbnail url for current post thumb_url: String url



195
196
197
# File 'app/models/camaleon_cms/post.rb', line 195

def set_thumb(thumb_url)
  set_meta("thumb", thumb_url)
end

#total_commentsObject

return the quantity of comments for this post TODO comments count



232
233
234
# File 'app/models/camaleon_cms/post.rb', line 232

def total_comments
  self.get_meta("comments_count", 0).to_i
end

#total_visitsObject

return the quantity of visits for this post



226
227
228
# File 'app/models/camaleon_cms/post.rb', line 226

def total_visits
  get_meta("visits", 0).to_i
end

#trash?Boolean

check if this is in trash status

Returns:

  • (Boolean)


104
105
106
# File 'app/models/camaleon_cms/post.rb', line 104

def trash?
  status == 'trash'
end