Class: CamaleonCms::PostDefault

Inherits:
CamaleonRecord show all
Includes:
CustomFieldsRead, Metas
Defined in:
app/models/camaleon_cms/post_default.rb

Direct Known Subclasses

Post, Widget::Assigned

Constant Summary

Constants inherited from CamaleonRecord

CamaleonRecord::TRANSLATION_TAG_HIDE_MAP, CamaleonRecord::TRANSLATION_TAG_HIDE_REGEX, CamaleonRecord::TRANSLATION_TAG_HIDE_SENTINELS, CamaleonRecord::TRANSLATION_TAG_RESTORE_MAP, CamaleonRecord::TRANSLATION_TAG_RESTORE_REGEX

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

Methods inherited from CamaleonRecord

#ability, #cama_build_cache_key, #cama_fetch_cache, #cama_get_cache, #cama_remove_cache, cama_sanitize_translatable, #cama_set_cache, #can?, #current_site, #current_user, polymorphic_class_for, polymorphic_name, #reset_ability

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



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

def draft_id
  @draft_id
end

Class Method Details

.find_by_slug(slug) ⇒ Object

find a content by slug (support multi language)



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

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 = where("#{CamaleonCms::Post.table_name}.slug = ? OR #{CamaleonCms::Post.table_name}.slug LIKE ? ", slug,
              "%-->#{slug}<!--%")
  # end
  res.take
end

.find_sti_class(type_name) ⇒ Object

Controls Reading: Prepend 'CamaleonCms::' when pulling from DB "Widget::Assigned" -> "CamaleonCms::Widget::Assigned" "Post" -> "CamaleonCms::Post"



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'app/models/camaleon_cms/post_default.rb', line 27

def self.find_sti_class(type_name)
  full_class_name = type_name.start_with?('CamaleonCms::') ? type_name : "CamaleonCms::#{type_name}"
  klass = begin
    full_class_name.constantize
  rescue NameError
    nil
  end
  return klass if klass && klass <= base_class

  # `super` resolves fully-qualified external classes (plugin STI outside the
  # CamaleonCms namespace) and enforces ancestry; values it cannot place load as
  # the base class, as every row did before native STI.
  begin
    super
  rescue ActiveRecord::SubclassNotFound
    base_class
  end
end

.inherited(subclass) ⇒ Object



6
7
8
9
10
11
12
# File 'app/models/camaleon_cms/post_default.rb', line 6

def self.inherited(subclass)
  super

  subclass.class_eval do
    include CamaleonCms::CommonRelationships
  end
end

.sti_nameObject

Controls Writing: Strip 'CamaleonCms::' when saving to DB "CamaleonCms::Widget::Assigned" -> "Widget::Assigned" "CamaleonCms::Post" -> "Post"



20
21
22
# File 'app/models/camaleon_cms/post_default.rb', line 20

def self.sti_name
  name.sub(/^CamaleonCms::/, '')
end

Instance Method Details

#authorObject

return the author of this Content



84
85
86
87
88
# File 'app/models/camaleon_cms/post_default.rb', line 84

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

#in_nav_menu_itemsObject

return all menu items in which this post was assigned



91
92
93
# File 'app/models/camaleon_cms/post_default.rb', line 91

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

#set_params(meta, custom_fields, options) ⇒ Object

Set the meta-field values and the post keywords here



96
97
98
99
100
# File 'app/models/camaleon_cms/post_default.rb', line 96

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