Class: Comment
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Comment
- Includes:
- RubyLess, Zena::Use::QueryComment::ModelMethods
- Defined in:
- app/models/comment.rb
Overview
Comments can be added on a per discussion basis. There can be replies to other comments in the same discussion. Comments are signed by the user commenting. Public comments belong to the user anon (see #User) and must have the ‘athor_name’ field set.
If anonymous is moderated (User#moderated?), all public comments are set to ‘prop’ and are not directly seen on the site.
Instance Method Summary collapse
-
#author ⇒ Object
Who wrote the comment (author’s Node model).
- #author_name ⇒ Object
-
#can_write? ⇒ Boolean
TODO: test.
- #node ⇒ Object
- #parent ⇒ Object
-
#publish ⇒ Object
Publish the comment (set it’s status to
pub
) TODO: test. -
#remove ⇒ Object
Remove the comment (set it’s status to
rem
). - #replies(opt = {}) ⇒ Object
-
#user ⇒ Object
Who wrote the comment (author’s User model).
-
#zip ⇒ Object
needed by zafu for ajaxy stuff.
Methods included from Zena::Use::QueryComment::ModelMethods
Instance Method Details
#author ⇒ Object
Who wrote the comment (author’s Node model)
36 37 38 |
# File 'app/models/comment.rb', line 36 def @author ||= (user ? user.node : nil) end |
#author_name ⇒ Object
44 45 46 |
# File 'app/models/comment.rb', line 44 def self[:author_name] || ( ? .title : nil) end |
#can_write? ⇒ Boolean
TODO: test
78 79 80 |
# File 'app/models/comment.rb', line 78 def can_write? && discussion.open? end |
#node ⇒ Object
40 41 42 |
# File 'app/models/comment.rb', line 40 def node @node ||= discussion.node end |
#parent ⇒ Object
48 49 50 |
# File 'app/models/comment.rb', line 48 def parent @parent ||= self[:reply_to] ? secure(Comment) { Comment.find(self[:reply_to]) } : nil end |
#publish ⇒ Object
Publish the comment (set it’s status to pub
) TODO: test
59 60 61 |
# File 'app/models/comment.rb', line 59 def publish update_attributes( :status=> Zena::Status::Pub ) end |
#remove ⇒ Object
Remove the comment (set it’s status to rem
)
53 54 55 |
# File 'app/models/comment.rb', line 53 def remove update_attributes( :status=> Zena::Status::Rem ) end |
#replies(opt = {}) ⇒ Object
63 64 65 66 67 68 69 70 |
# File 'app/models/comment.rb', line 63 def replies(opt={}) if opt[:with_prop] conditions = ["reply_to = ? AND status >= #{Zena::Status::Pub}", self[:id]] else conditions = ["reply_to = ? AND status = #{Zena::Status::Pub}", self[:id]] end secure(Comment) { Comment.find(:all, :conditions=>conditions, :order=>'created_at ASC') } end |
#user ⇒ Object
Who wrote the comment (author’s User model)
31 32 33 |
# File 'app/models/comment.rb', line 31 def user @user ||= secure(User) { User.find(self[:user_id]) } end |
#zip ⇒ Object
needed by zafu for ajaxy stuff
73 74 75 |
# File 'app/models/comment.rb', line 73 def zip self[:id] end |