Sha256: 2ac82d9847c6ed9a03fa6bfb1bab8a4db097d4e2f8be92319c5b353a345a128d

Contents?: true

Size: 1.62 KB

Versions: 23

Compression:

Stored size: 1.62 KB

Contents

class CamaleonCms::PostComment < ActiveRecord::Base
  include CamaleonCms::Metas
  self.table_name = "#{PluginRoutes.static_system_info["db_prefix"]}comments"
  # attr_accessible :user_id, :post_id, :content, :author, :author_email, :author_url, :author_IP, :approved, :agent, :agent, :typee, :comment_parent, :is_anonymous
  attr_accessor :is_anonymous

  #default_scope order('comments.created_at ASC')
  #approved: approved | pending | spam

  cama_define_common_relationships('PostComment')
  has_many :children, class_name: "CamaleonCms::PostComment", foreign_key: :comment_parent, dependent: :destroy
  belongs_to :post, class_name: "CamaleonCms::Post", foreign_key: :post_id
  belongs_to :parent, class_name: "CamaleonCms::PostComment", foreign_key: :comment_parent
  belongs_to :user, class_name: CamaManager.get_user_class_name, foreign_key: :user_id

  default_scope {order("#{CamaleonCms::PostComment.table_name}.created_at DESC")}

  scope :main, -> { where(:comment_parent => nil) }
  scope :comment_parent, -> { where(:comment_parent => 'is not null') }
  scope :approveds, -> { where(:approved => 'approved') }

  validates :content, :presence => true
  validates_presence_of :author, :author_email, if: Proc.new { |c| c.is_anonymous.present? }
  after_create :update_counter
  after_destroy :update_counter

  # return the owner of this comment
  def comment_user
    self.user
  end

  # check if this comments is already approved
  def is_approved?
    self.approved == 'approved'
  end

  private
  # update comment counter
  def update_counter
    p = self.post
    p.set_meta("comments_count", p.comments.count) if p.present?
  end

end

Version data entries

23 entries across 23 versions & 2 rubygems

Version Path
camaleon_cms-2.5.3.1 app/models/camaleon_cms/post_comment.rb
camaleon_cms-2.5.3 app/models/camaleon_cms/post_comment.rb
camaleon_cms-2.5.2 app/models/camaleon_cms/post_comment.rb
camaleon_cms_rails6-2.5.0 app/models/camaleon_cms/post_comment.rb
camaleon_cms-2.5.1 app/models/camaleon_cms/post_comment.rb
camaleon_cms-2.5.0 app/models/camaleon_cms/post_comment.rb
camaleon_cms-2.4.6.9 app/models/camaleon_cms/post_comment.rb
camaleon_cms-2.4.6.8 app/models/camaleon_cms/post_comment.rb
camaleon_cms-2.4.6.7 app/models/camaleon_cms/post_comment.rb
camaleon_cms-2.4.6.6 app/models/camaleon_cms/post_comment.rb
camaleon_cms-2.4.6.5 app/models/camaleon_cms/post_comment.rb
camaleon_cms-2.4.6.4 app/models/camaleon_cms/post_comment.rb
camaleon_cms-2.4.6.3 app/models/camaleon_cms/post_comment.rb
camaleon_cms-2.4.6.2 app/models/camaleon_cms/post_comment.rb
camaleon_cms-2.4.6.1 app/models/camaleon_cms/post_comment.rb
camaleon_cms-2.4.6.0 app/models/camaleon_cms/post_comment.rb
camaleon_cms-2.4.5.14 app/models/camaleon_cms/post_comment.rb
camaleon_cms-2.4.5.13 app/models/camaleon_cms/post_comment.rb
camaleon_cms-2.4.5.12 app/models/camaleon_cms/post_comment.rb
camaleon_cms-2.4.5.11 app/models/camaleon_cms/post_comment.rb