Class: SocialFramework::Schedule
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- SocialFramework::Schedule
- Defined in:
- app/models/social_framework/schedule.rb
Overview
Class that is the schedule that a user has
Instance Method Summary collapse
-
#confirm_event(event) ⇒ Object
- Confirm an event to schedule ====== Params:
event -
Eventto confirm Returns false if no exist a invitation or has no disponibility or true if could confirm event.
- Confirm an event to schedule ====== Params:
-
#create_event(title, start, duration = nil, description = "", particular = false) ⇒ Object
- Create an event to user this schedule ====== Params:
title Stringevent titlestartDateTimedate and hour to start eventdurationActiveSupport::Durationof the event, if nil is used until end of start daydescriptionStringevent description, default is “”particular-
Booleanset event as private or not, default is false Returns event created or nil in error case.
- Create an event to user this schedule ====== Params:
-
#enter_in_event(event) ⇒ Object
- Enter in an public event ====== Params:
event -
Eventto enter Returns ParticipantEvent created or nil if that event is particular or already exist events in that period.
- Enter in an public event ====== Params:
-
#events_in_period(start, finish = start.end_of_day) ⇒ Object
- Check disponibility in specific time interval ====== Params:
start DateTimeevent startfinish-
DateTimeevent finish, if nil is start.end_of_day Returns anArrayofEventthat they are present in the time interval.
- Check disponibility in specific time interval ====== Params:
-
#exit_event(event) ⇒ Object
- Exit of an event ====== Params:
event -
Eventto exit Returns ParticipantEvent destroyed or nil if user is creator.
- Exit of an event ====== Params:
-
#remove_event(event) ⇒ Object
- Remove an event created by self.user ====== Params:
event -
Eventto remove Returns Event destroyed or nil if user is not creator.
- Remove an event created by self.user ====== Params:
Instance Method Details
#confirm_event(event) ⇒ Object
Confirm an event to schedule
Params:
event-
Eventto confirm
Returns false if no exist a invitation or has no disponibility or true if could confirm event
48 49 50 51 52 53 54 55 |
# File 'app/models/social_framework/schedule.rb', line 48 def confirm_event(event) participant_event = get_participant_event(event) return false if participant_event.nil? or not events_in_period(event.start, event.finish).empty? relation_user_route(event) participant_event.confirmed = true participant_event.save end |
#create_event(title, start, duration = nil, description = "", particular = false) ⇒ Object
Create an event to user this schedule
Params:
title-
Stringevent title start-
DateTimedate and hour to start event duration-
ActiveSupport::Durationof the event, if nil is used until end of start day description-
Stringevent description, default is “” particular-
Booleanset event as private or not, default is false
Returns event created or nil in error case
16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'app/models/social_framework/schedule.rb', line 16 def create_event(title, start, duration = nil, description = "", particular = false) finish = set_finish_date(start, duration) return if finish.nil? or not events_in_period(start, finish).empty? event_class = ModelFabric.get_class(SocialFramework.event_class) event = event_class.create(title: title, start: start, finish: finish, description: description, particular: particular) unless event.nil? participant_event_class.create(event: event, schedule: self, confirmed: true, role: "creator") end return event end |
#enter_in_event(event) ⇒ Object
Enter in an public event
Params:
event-
Eventto enter
Returns ParticipantEvent created or nil if that event is particular or already exist events in that period
35 36 37 38 39 40 41 42 |
# File 'app/models/social_framework/schedule.rb', line 35 def enter_in_event(event) return if event.nil? or event.particular or not events_in_period(event.start, event.finish).empty? if get_participant_event(event).nil? relation_user_route(event) participant_event_class.create(event: event, schedule: self, confirmed: true, role: "participant") end end |
#events_in_period(start, finish = start.end_of_day) ⇒ Object
Check disponibility in specific time interval
Params:
start-
DateTimeevent start finish-
DateTimeevent finish, if nil is start.end_of_day
Returns an Array of Event that they are present in the time interval
88 89 90 91 92 93 94 95 96 97 |
# File 'app/models/social_framework/schedule.rb', line 88 def events_in_period(start, finish = start.end_of_day) event_class = ModelFabric.get_class(SocialFramework.event_class) events = event_class.joins(:participant_events).where( "social_framework_participant_events.schedule_id = ? AND " + "social_framework_participant_events.confirmed = ? AND " + "social_framework_events.start < ? AND " + "social_framework_events.finish > ?", self.id, true, finish, start).order(start: :asc) return events end |
#exit_event(event) ⇒ Object
Exit of an event
Params:
event-
Eventto exit
Returns ParticipantEvent destroyed or nil if user is creator
61 62 63 64 65 66 67 68 |
# File 'app/models/social_framework/schedule.rb', line 61 def exit_event(event) participant_event = get_participant_event(event) if not participant_event.nil? and participant_event.role != "creator" self.user.routes.delete(event.route) unless event.route.nil? participant_event.destroy end end |
#remove_event(event) ⇒ Object
Remove an event created by self.user
Params:
event-
Eventto remove
Returns Event destroyed or nil if user is not creator
74 75 76 77 78 79 80 81 |
# File 'app/models/social_framework/schedule.rb', line 74 def remove_event(event) participant_event = get_participant_event(event) if not participant_event.nil? and participant_event.role == "creator" event.route.destroy unless event.route.nil? event.destroy end end |