article_block.rb
1.21 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
47
48
49
50
51
52
class ArticleBlock < Block
def self.description
_('Display one of your contents')
end
def help
_('This block displays one of your articles. You can edit the block to select which one of your articles is going to be displayed in the block.')
end
def content(args={})
block = self
lambda do
block_title(block.title) +
(block.article ? article_to_html(block.article, :gallery_view => false) : _('Article not selected yet.'))
end
end
def article_id
self.settings[:article_id]
end
def article_id= value
self.settings[:article_id] = value.blank? ? nil : value.to_i
end
def article(reload = false)
@article = nil if reload
if @article || article_id
begin
@article = Article.find(article_id)
rescue ActiveRecord::RecordNotFound
# dangling reference, clear it
@article = nil
self.article_id = nil
self.save!
end
end
@article
end
def article=(obj)
self.article_id = obj.id
@article = obj
end
def available_articles
return [] if self.box.nil? or self.box.owner.nil?
self.box.owner.kind_of?(Environment) ? self.box.owner.portal_community.articles : self.box.owner.articles
end
end