Class: CamaleonCms::PostDefault

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

Overview

Camaleon CMS is a content management system

Copyright (C) 2015 by Owen Peredo Diaz
Email: [email protected]
This program is free software: you can redistribute it and/or modify   it under the terms of the GNU Affero General Public License as  published by the Free Software Foundation, either version 3 of the  License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,  but WITHOUT ANY WARRANTY; without even the implied warranty of  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the  GNU Affero General Public License (GPLv3) for more details.

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!, #get_field_groups, #get_field_object, #get_field_value, #get_field_values, #get_field_values_hash, #get_fields_object, #get_user_field_groups, #save_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_multiple_options, #set_option

Instance Attribute Details

#draft_idObject

Returns the value of attribute draft_id


15
16
17
# File 'app/models/camaleon_cms/post_default.rb', line 15

def draft_id
  @draft_id
end

Class Method Details

.find_by_slug(slug) ⇒ Object

find a content by slug (support multi language)


32
33
34
35
36
37
38
39
# File 'app/models/camaleon_cms/post_default.rb', line 32

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


47
48
49
50
51
52
53
# File 'app/models/camaleon_cms/post_default.rb', line 47

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


63
64
65
# File 'app/models/camaleon_cms/post_default.rb', line 63

def in_nav_menu_items
  CamaleonCms::NavMenuItem.joins(:metas).where("value LIKE ?","%\"object_id\":\"#{self.id}\"%").where("value LIKE ?","%\"type\":\"post\"%").readonly(false)
end

#parentObject

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


42
43
44
# File 'app/models/camaleon_cms/post_default.rb', line 42

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

#set_meta_from_form(data_metas) ⇒ Object

save meta values passed from form


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

def set_meta_from_form(data_metas)
  data_metas.each do |key, value|
    self.set_meta(key, value)
  end
end

#set_params(meta, field_options, post_data_keywords) ⇒ Object

Set the meta, field values and the post keywords here


68
69
70
71
72
# File 'app/models/camaleon_cms/post_default.rb', line 68

def set_params(meta, field_options, post_data_keywords)
  self.set_meta_from_form(meta)
  self.set_field_values(field_options)
  self.set_option("keywords", post_data_keywords)
end