software_events_block.rb
1.19 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
53
54
55
56
class SoftwareCommunitiesPlugin::SoftwareEventsBlock < Block
settings_items :amount_of_events, :type => :integer, :default => 3
attr_accessible :amount_of_events
validates :amount_of_events,
:presence => true, :numericality => {
greater_than_or_equal_to: 1
}
def self.description
_('Software community events')
end
def help
_('This block displays the software community events in a list.')
end
def default_title
_('Other events')
end
def content(args={})
block = self
lambda do |object|
render(
:file => 'blocks/software_events',
:locals => { :block => block }
)
end
end
def cacheable?
false
end
def get_events
yesterday = DateTime.yesterday.end_of_day
self.owner.events.where("start_date > ?", yesterday).order(:start_date, :id).limit(self.amount_of_events)
end
def get_events_except event_slug=""
event_slug = "" if event_slug.nil?
get_events.where("slug NOT IN (?)", event_slug)
end
def has_events_to_display? current_event_slug=""
not get_events_except(current_event_slug).empty?
end
def should_display_title?
self.box.position != 1
end
end