discussion_block.rb
1 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
class CommentParagraphPlugin::DiscussionBlock < Block
settings_items :presentation_mode, :type => String, :default => 'title_only'
settings_items :total_items, :type => Integer, :default => 5
settings_items :discussion_status, :type => Integer
attr_accessible :presentation_mode, :total_items, :discussion_status
VALID_CONTENT = ['CommentParagraphPlugin::Discussion']
STATUS_NOT_OPENED = 0
STATUS_AVAILABLE = 1
STATUS_CLOSED = 2
def self.description
c_('Discussion Articles')
end
def help
_("This block displays all profile's article discussion")
end
def discussions
holder.articles.where(type: VALID_CONTENT).order('created_at DESC').limit(self.total_items)
end
def holder
return nil if self.box.nil? || self.box.owner.nil?
if self.box.owner.kind_of?(Environment)
return nil if self.box.owner.portal_community.nil?
self.box.owner.portal_community
else
self.box.owner
end
end
def mode?(attr)
attr == self.presentation_mode
end
end