topic.rb
1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
class ProposalsDiscussionPlugin::Topic < Folder
alias :discussion :parent
has_many :proposals, :class_name => 'ProposalsDiscussionPlugin::Proposal', :foreign_key => 'parent_id'
has_many :proposals_comments, :class_name => 'Comment', :through => :children, :source => :comments
has_many :proposals_authors, :class_name => 'Person', :through => :children, :source => :created_by
settings_items :color, :type => :string
attr_accessible :color
def self.short_description
_("Discussion topic")
end
def self.description
_('Container for proposals.')
end
def most_active_participants
proposals_authors.group('profiles.id').order('count(articles.id) DESC').includes(:environment, :preferred_domain, :image)
end
def to_html(options = {})
proc do
render :file => 'content_viewer/topic', :locals => {:topic => @page}
end
end
def allow_create?(user)
true
end
def max_score
@max ||= [1, proposals.maximum(:comments_count)].max
end
def proposal_tags
proposals.tag_counts.inject({}) do |memo,tag|
memo[tag.name] = tag.count
memo
end
end
end