Class: CamaleonCms::PostDefault

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
CustomFieldsRead, Metas
Defined in:
app/models/camaleon_cms/post_default.rb

Direct Known Subclasses

Post, Widget::Assigned

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#draft_idObject

attr_accessible :user_id, :title, :slug, :content, :content_filtered, :status, :visibility, :visibility_value, :post_order, :post_type_key, :taxonomy_id, :published_at, :post_parent, :post_order, :is_feature


7
8
9
# File 'app/models/camaleon_cms/post_default.rb', line 7

def draft_id
  @draft_id
end

Class Method Details

.find_by_slug(slug) ⇒ Object

find a content by slug (support multi language)


26
27
28
29
30
31
32
33
# File 'app/models/camaleon_cms/post_default.rb', line 26

def self.find_by_slug(slug)
  #if current_site.present? && current_site.get_meta("languages_site", []).count <= 1
  #  res = self.where(slug: slug)
  #else
  res = self.where("#{CamaleonCms::Post.table_name}.slug = ? OR #{CamaleonCms::Post.table_name}.slug LIKE ? ", slug, "%-->#{slug}<!--%")
  #end
  res.reorder("").first
end

Instance Method Details

#authorObject

return the author of this Content


41
42
43
44
45
46
47
# File 'app/models/camaleon_cms/post_default.rb', line 41

def author
  begin
    CamaleonCms::User.find(self.user_id)
  rescue
    CamaleonCms::User.admin_scope.first
  end
end

#in_nav_menu_itemsObject

return all menu items in which this post was assigned


50
51
52
# File 'app/models/camaleon_cms/post_default.rb', line 50

def in_nav_menu_items
  CamaleonCms::NavMenuItem.where(url: self.id, kind: 'post')
end

#parentObject

return the parent of a post (support for sub contents or tree of posts)


36
37
38
# File 'app/models/camaleon_cms/post_default.rb', line 36

def parent
  CamaleonCms::Post.where(id: self.post_parent).first
end

#set_params(meta, custom_fields, options) ⇒ Object

Set the meta, field values and the post keywords here


55
56
57
58
59
# File 'app/models/camaleon_cms/post_default.rb', line 55

def set_params(meta, custom_fields, options)
  self.set_metas(meta)
  self.set_field_values(custom_fields)
  self.set_options(options)
end