Class: SimpleForum::Post

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/simple_forum/post.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.per_pageObject



42
43
44
# File 'app/models/simple_forum/post.rb', line 42

def self.per_page
  15
end

Instance Method Details

#deletable_by?(user, is_moderator = false) ⇒ Boolean

Returns:

  • (Boolean)


62
63
64
65
66
67
68
# File 'app/models/simple_forum/post.rb', line 62

def deletable_by?(user, is_moderator=false)
  return false if new_record?
  return false if is_deleted?
  is_moderator = forum.is_moderator?(user) if is_moderator.nil?
  return true if is_moderator
  created_at > SimpleForum.minutes_for_delete_post.minutes.ago && user == self.user
end

#editable_by?(user, is_moderator = false) ⇒ Boolean

Returns:

  • (Boolean)


54
55
56
57
58
59
60
# File 'app/models/simple_forum/post.rb', line 54

def editable_by?(user, is_moderator=false)
  return false if new_record?
  return false if is_deleted?
  is_moderator = forum.is_moderator?(user) if is_moderator.nil?
  return true if is_moderator
  created_at > SimpleForum.minutes_for_edit_post.minutes.ago && user == self.user
end

#is_deletedObject Also known as: is_deleted?



70
71
72
# File 'app/models/simple_forum/post.rb', line 70

def is_deleted
  !!deleted_at
end

#is_editedObject Also known as: is_edited?



76
77
78
# File 'app/models/simple_forum/post.rb', line 76

def is_edited
  !!edited_at
end

#mark_as_deleted_by(user) ⇒ Object



82
83
84
85
86
87
# File 'app/models/simple_forum/post.rb', line 82

def mark_as_deleted_by(user)
  return false unless deletable_by?(user, nil)
  self.deleted_at = Time.now
  self.deleted_by = user
  self.save
end

#on_pageObject



37
38
39
40
# File 'app/models/simple_forum/post.rb', line 37

def on_page
  before_count = topic.posts.where(["#{SimpleForum::Post.quoted_table_name}.created_at<?", created_at]).size
  [((before_count + 1).to_f / SimpleForum::Post.per_page).ceil.to_i, 1].max
end

#outputObject



46
47
48
# File 'app/models/simple_forum/post.rb', line 46

def output
  body.to_s.bbcode_to_html
end

#output_without_tagsObject



50
51
52
# File 'app/models/simple_forum/post.rb', line 50

def output_without_tags
  HTML::FullSanitizer.new.sanitize(output.gsub(/\<fieldset\>\<legend\>.*\<\/legend\>\<blockquote\>(.|\n)*\<\/blockquote\>/, ''))
end

#topic_must_not_be_closedObject



33
34
35
# File 'app/models/simple_forum/post.rb', line 33

def topic_must_not_be_closed
  errors.add(:base, I18n.t('simple_forum.errors.topic_is_close', :default => "Topic is closed.")) if topic && topic.is_closed?
end