Class: Cornerstone::Discussion

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/cornerstone/discussion.rb

Constant Summary collapse

STATUS =

CONSTANTS == #

Cornerstone::Config.discussion_statuses

Instance Method Summary collapse

Instance Method Details

#author_nameObject

INSTANCE METHODS == #



39
40
41
# File 'app/models/cornerstone/discussion.rb', line 39

def author_name
  self.posts.first.author_name
end

#closed?Boolean

returns true if discussion is ‘closed’

Returns:

  • (Boolean)


44
45
46
# File 'app/models/cornerstone/discussion.rb', line 44

def closed?
  self.status == Cornerstone::Discussion::STATUS.last
end

#created_by?(check_user) ⇒ Boolean

returns true if it was created by given user or if given user is an admin

Returns:

  • (Boolean)


49
50
51
52
53
# File 'app/models/cornerstone/discussion.rb', line 49

def created_by?(check_user)
  return false unless check_user.present?
  return true if check_user.cornerstone_admin?
  self.user && self.user == check_user
end

#participants(exclude_email = nil) ⇒ Object

returns an array of participants for the discussion



56
57
58
59
60
61
62
63
64
# File 'app/models/cornerstone/discussion.rb', line 56

def participants(exclude_email=nil)
  ps = []
  self.posts.each do |p|
    if p.author_name && p.author_email
      ps << [p.author_name, p.author_email]
    end
  end
  ps.delete_if{|p| p[1] == exclude_email}.uniq
end

#participants_email_list(exclude_email = nil) ⇒ Object

return a nicely formatted string for emailing i.e. Name <email_address>, Name <email_address>



68
69
70
# File 'app/models/cornerstone/discussion.rb', line 68

def participants_email_list(exclude_email=nil)
  participants(exclude_email).collect{ |p| "#{p[0]} <#{p[1]}>" }.join(", ")
end