Class: Discussion
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Discussion
- Includes:
- RubyLess
- Defined in:
- app/models/discussion.rb
Overview
A #Discussion holds a list of comments for a #Node. An inside
discussion only appears when the node is not published. A #Comment can be added to an open
discussion. Discussions only show in there current language (each traduction gets its own discussion). #Discussions can be created in the ‘drive’ popup or are automatically created when the first comment is added. Discussions are automatically created only if there already exists an outside
and open
discussion for another language and if the current visitor is a commentator (User.commentator?).
Instance Method Summary collapse
- #can_destroy? ⇒ Boolean
- #comments(opts = {}) ⇒ Object
- #comments_count(opts = {}) ⇒ Object
-
#destroy ⇒ Object
TODO: test.
-
#inside? ⇒ Boolean
An
inside
discussion is not visible when the version is published. - #node ⇒ Object
- #o_node ⇒ Object
-
#open? ⇒ Boolean
An open discussion means new comments can be added.
Instance Method Details
#can_destroy? ⇒ Boolean
27 28 29 |
# File 'app/models/discussion.rb', line 27 def can_destroy? all_comments.size == 0 end |
#comments(opts = {}) ⇒ Object
31 32 33 34 35 36 37 38 |
# File 'app/models/discussion.rb', line 31 def comments(opts={}) if opts[:with_prop] conditions = ["discussion_id = ? AND reply_to IS NULL AND status > #{Zena::Status::Rem}", self[:id]] else conditions = ["discussion_id = ? AND reply_to IS NULL AND status = #{Zena::Status::Pub}", self[:id]] end Comment.find(:all, :conditions=>conditions, :order=>'created_at ASC') end |
#comments_count(opts = {}) ⇒ Object
40 41 42 43 44 45 46 47 |
# File 'app/models/discussion.rb', line 40 def comments_count(opts={}) if opts[:with_prop] conditions = ["discussion_id = ? AND status > #{Zena::Status::Rem}", self[:id]] else conditions = ["discussion_id = ? AND status = #{Zena::Status::Pub}", self[:id]] end Comment.count(:all, :conditions=>conditions) end |
#destroy ⇒ Object
TODO: test
50 51 52 53 54 55 56 57 |
# File 'app/models/discussion.rb', line 50 def destroy if can_destroy? super else errors.add('comments', 'not empty') false end end |
#inside? ⇒ Boolean
An inside
discussion is not visible when the version is published. Node readers = discussion readers = commentators
25 |
# File 'app/models/discussion.rb', line 25 def inside?; self[:inside]; end |
#node ⇒ Object
61 62 63 |
# File 'app/models/discussion.rb', line 61 def node secure!(Node) { o_node } end |
#o_node ⇒ Object
59 |
# File 'app/models/discussion.rb', line 59 alias o_node node |
#open? ⇒ Boolean
An open discussion means new comments can be added
21 |
# File 'app/models/discussion.rb', line 21 def open?; self[:open]; end |