Class: Discussion

Inherits:
ActiveRecord::Base
  • Object
show all
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

Instance Method Details

#can_destroy?Boolean

Returns:

  • (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

#destroyObject

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

Returns:

  • (Boolean)


25
# File 'app/models/discussion.rb', line 25

def inside?; self[:inside]; end

#nodeObject



61
62
63
# File 'app/models/discussion.rb', line 61

def node
  secure!(Node) { o_node }
end

#o_nodeObject



59
# File 'app/models/discussion.rb', line 59

alias o_node node

#open?Boolean

An open discussion means new comments can be added

Returns:

  • (Boolean)


21
# File 'app/models/discussion.rb', line 21

def open?; self[:open]; end