events_helper.rb
1.83 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
module EventsHelper
include DatesHelper
include ActionView::Helpers::OutputSafetyHelper
def list_events(date, events)
title = _('Events for %s') % show_date_month(date)
user_events = events.select { |item| item.display_to?(user) }
events_for_month = safe_join(user_events.map {|item| display_event_in_listing(item)}, '')
content_tag('h2', title) +
content_tag('div',
(events.any? ?
content_tag('table', events_for_month) :
content_tag('em', _('No events for this month'), :class => 'no-events')
), :id => 'agenda-items'
)
end
def display_event_in_listing(article)
content_tag( 'tr',
content_tag('td',
content_tag('div', show_time(article.start_date) + ( article.end_date.nil? ? '' : (_(" to ") + show_time(article.end_date))),:class => 'event-date' ) +
content_tag('div',link_to(article.name,article.url),:class => 'event-title') +
content_tag('div',(article.address.nil? or article.address == '') ? '' : (_('Place: ') + article.address),:class => 'event-place')
)
)
end
def populate_calendar(selected_date, events)
selected_date = selected_date.to_date
events = events.reject{ |event| !event.display_to? user }
calendar = Event.date_range(selected_date.year, selected_date.month).map do |date|
[
# the day itself
date,
# is there any events in this date?
events.any? {|event| event.date_range.cover?(date)},
# is this date in the current month?
true
]
end
# pad with days before
while calendar.first.first.wday != 0
calendar.unshift([calendar.first.first - 1.day, false, false])
end
# pad with days after (until Saturday)
while calendar.last.first.wday != 6
calendar << [calendar.last.first + 1.day, false, false]
end
calendar
end
end