-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0e78014
commit 49bcbba
Showing
7 changed files
with
129 additions
and
131 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# frozen_string_literal: true | ||
|
||
class EventList | ||
def fetch_events_list(user) | ||
participated_list = user.participations.pluck(:event_id) | ||
upcoming_event_list = Event.where('start_at > ?', Date.current).pluck(:id) | ||
|
||
joined_events = Event.where(id: participated_list & upcoming_event_list) | ||
upcoming_events = Event.where(id: upcoming_event_list).where.not(id: participated_list) | ||
{ | ||
joined_events:, | ||
upcoming_events: | ||
} | ||
end | ||
|
||
def fetch_regular_events_list(user) | ||
participated_list = user.regular_event_participations.pluck(:regular_event_id) | ||
regular_events_list = [] | ||
RegularEvent.where(id: participated_list).where(finished: false).find_each do |event| | ||
event.regular_event_repeat_rules.each do |repeat_rule| | ||
current_date = Time.zone.today | ||
|
||
list_regular_event_for_year(event, repeat_rule, current_date, regular_events_list) | ||
end | ||
end | ||
regular_events_list | ||
end | ||
|
||
private | ||
|
||
def list_regular_event_for_year(event, repeat_rule, current_date, regular_events_list) | ||
while current_date <= Time.zone.today + 1.year | ||
if repeat_rule.frequency.zero? | ||
day_of_the_week_symbol = DateAndTime::Calculations::DAYS_INTO_WEEK.key(repeat_rule.day_of_the_week) | ||
event_date = current_date.next_occurring(day_of_the_week_symbol).to_date | ||
event_date = event_date.next_occurring(day_of_the_week_symbol) while !event.hold_national_holiday && HolidayJp.holiday?(event_date) | ||
current_date = event_date + 1 | ||
else | ||
event_date = event.possible_next_event_date(current_date, repeat_rule) | ||
current_date = current_date.next_month.beginning_of_month | ||
end | ||
regular_events_list << { event_id: event.id, event_date: } | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# frozen_string_literal: true | ||
|
||
class IcalendarStr | ||
def convert_events_to_ical(events_list) | ||
event_cal = Icalendar::Calendar.new | ||
|
||
events_list[:joined_events].each do |event| | ||
add_event_to_calendar(event_cal, event, true) | ||
end | ||
|
||
events_list[:upcoming_events].each do |event| | ||
add_event_to_calendar(event_cal, event, false) | ||
end | ||
event_cal | ||
end | ||
|
||
def convert_regular_events_to_ical(regular_events_list) | ||
regular_event_cal = Icalendar::Calendar.new | ||
|
||
add_regular_event_to_calendar(regular_event_cal, regular_events_list) | ||
regular_event_cal | ||
end | ||
|
||
private | ||
|
||
def add_event_to_calendar(event_cal, event, joined) | ||
tzid = 'Asia/Tokyo' | ||
event_cal.event do |e| | ||
e.dtstart = Icalendar::Values::DateTime.new event.start_at, { 'tzid' => tzid } | ||
e.dtend = Icalendar::Values::DateTime.new event.end_at, { 'tzid' => tzid } | ||
e.summary = joined ? "【参加登録済】#{event.title}" : event.title | ||
e.description = event.description | ||
e.location = event.location | ||
e.uid = "event#{event.id}" | ||
e.sequence = Time.now.to_i | ||
end | ||
end | ||
|
||
def add_regular_event_to_calendar(regular_event_cal, regular_events_list) | ||
regular_events_list.each do |regular_event| | ||
tzid = 'Asia/Tokyo' | ||
event_date = Date.parse(regular_event[:event_date].to_s) | ||
event = RegularEvent.find(regular_event[:event_id]) | ||
|
||
regular_event_cal.event do |e| | ||
e.dtstart = Icalendar::Values::DateTime.new( | ||
DateTime.parse("#{event_date} #{event.start_at.strftime('%H:%M')}"), 'tzid' => tzid | ||
) | ||
e.dtend = Icalendar::Values::DateTime.new( | ||
DateTime.parse("#{event_date} #{event.end_at.strftime('%H:%M')}"), 'tzid' => tzid | ||
) | ||
e.summary = event.title | ||
e.description = event.description | ||
e.uid = "event#{event.id}#{event_date}" | ||
e.sequence = Time.now.to_i | ||
end | ||
end | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.