app/helpers/meeting_reservations_helper.rb
# Returns either a new *individual event* reservation instance or an existing one when found
# (according to the parameters).
#
# Assumes all parameters are valid instances of the respective classes.
# (Returns a new empty instance in case of invalid parameters)
#
Returns either a new *individual event* reservation instance or an existing one when found
(according to the parameters).

Assumes all parameters are valid instances of the respective classes.
(Returns a new empty instance in case of invalid parameters)
Returns either a new * individual event * reservation instance or an existing one when found ( according to the parameters ) . Assumes all parameters are valid instances of the respective classes . ( Returns a new empty instance in case of invalid parameters )
def find_or_new_meeting_event_reservation( current_user, meeting, team_affiliation, badge, event )
    return MeetingEventReservation.new unless current_user.instance_of?(User) &&
            meeting.instance_of?(Meeting) && team_affiliation.instance_of?(TeamAffiliation) &&
            badge.instance_of?(Badge) && event.instance_of?(MeetingEvent)
    mer = MeetingEventReservation.where(
      meeting_id:       meeting.id,
      team_id:          team_affiliation.team_id,
      swimmer_id:       badge.swimmer_id,
      badge_id:         badge.id,
      meeting_event_id: event.id
    ).first
    if mer                                          
      mer
    else                                            
      swimmer = badge.swimmer
      best_finder = SwimmerPersonalBestFinder.new( swimmer )
      possible_best = best_finder.get_entry_best_timing(
        badge,
        meeting,
        event.event_type,
        meeting.pool_types.first,
        true 
      )
      MeetingEventReservation.new(
        meeting_id:       meeting.id,
        team_id:          team_affiliation.team_id,
        swimmer_id:       swimmer.id,
        badge_id:         badge.id,
        meeting_event_id: event.id,
        user_id:          current_user.id,
        is_doing_this:    false,
        suggested_minutes:  possible_best ? possible_best.minutes : 0,
        suggested_seconds:  possible_best ? possible_best.seconds : 0,
        suggested_hundreds: possible_best ? possible_best.hundreds : 0
      )
    end
  end
def find_or_new_meeting_event_reservation ( current_user , meeting , team_affiliation , badge , event ) return MeetingEventReservation . new unless current_user . instance_of? ( User ) && meeting . instance_of? ( Meeting ) && team_affiliation . instance_of? ( TeamAffiliation ) && badge . instance_of? ( Badge ) && event . instance_of? ( MeetingEvent ) mer = MeetingEventReservation . where ( meeting_id : meeting . id , team_id : team_affiliation . team_id , swimmer_id : badge . swimmer_id , badge_id : badge . id , meeting_event_id : event . id ) . first if mer mer else swimmer = badge . swimmer best_finder = SwimmerPersonalBestFinder . new ( swimmer ) possible_best = best_finder . get_entry_best_timing ( badge , meeting , event . event_type , meeting . pool_types . first , true ) MeetingEventReservation . new ( meeting_id : meeting . id , team_id : team_affiliation . team_id , swimmer_id : swimmer . id , badge_id : badge . id , meeting_event_id : event . id , user_id : current_user . id , is_doing_this : false , suggested_minutes : possible_best ? possible_best . minutes : 0 , suggested_seconds : possible_best ? possible_best . seconds : 0 , suggested_hundreds : possible_best ? possible_best . hundreds : 0 ) end end
Returns either a new *individual event* reservation instance or an existing one when found
(according to the parameters).
Returns either a new * individual event * reservation instance or an existing one when found ( according to the parameters ) .
# Existing? # NEW? # convert_pool_type
current_user
<not_specific>
meeting
<not_specific>
team_affiliation
<not_specific>
badge
<not_specific>
event
<not_specific>