app/controllers/meetings_controller.rb
# Enlists all "my" meetings for the current user.
#
# Includes:
# - all tagged meetings (both by user_id and affiliation_id)
# - only meetings belonging to a not-yet ended season are shown
#
# Besides showing all meetings tagged by a team manager for an affiliation
# in which the current user has a badge, this allows each user to build
# a customized calendar to check out frequently.
#
Enlists all "my" meetings for the current user.
Includes:
all tagged meetings (both by user_id and affiliation_id)
only meetings belonging to a not-yet ended season are shown

Besides showing all meetings tagged by a team manager for an affiliation
in which the current user has a badge, this allows each user to build
a customized calendar to check out frequently.
Enlists all " my " meetings for the current user . Includes : all tagged meetings ( both by user_id and affiliation_id ) only meetings belonging to a not - yet ended season are shown Besides showing all meetings tagged by a team manager for an affiliation in which the current user has a badge this allows each user to build a customized calendar to check out frequently .
def my
    open_season_ids = Season.is_not_ended.select(:id).map{|s| s.id }
    browsable_season_ids = open_season_ids
    meeting_id_list = Meeting
      .where( "meetings.season_id IN (?)", browsable_season_ids )
      .tagged_with( "u#{ current_user.id }", on: :tags_by_users )
      .select( :id, :season_id )
      .map{ |meeting| meeting.id }
    if current_user.has_associated_swimmer?
      browsable_season_ids
        .map{ |season_id| current_user.find_team_affiliation_id_from_badges_for(season_id) }
        .compact.each do |tagger_team_affiliation_id|
          meeting_id_list += Meeting
            .where( ["meetings.season_id IN (?)", browsable_season_ids] )
            .tagged_with( "ta#{ tagger_team_affiliation_id }", on: :tags_by_teams )
            .select( :id, :season_id )
            .map{ |meeting| meeting.id }
        end
      meeting_id_list += current_user.swimmer.meetings
        .where( ["meetings.season_id IN (?)", browsable_season_ids] )
        .select( :id, :season_id )
        .map{ |meeting| meeting.id }
    end
    @calendarMeetingPicker = CalendarMeetingPicker.new( nil, nil, nil, meeting_id_list.uniq! )
    @calendarDAO = @calendarMeetingPicker.pick_meetings( 'DESC', false, current_user )
    @meetings = @calendarDAO.get_meetings
  end
def my open_season_ids = Season . is_not_ended . select ( :id ) . map { | s | s . id } browsable_season_ids = open_season_ids meeting_id_list = Meeting . where ( "meetings.season_id IN (?)" , browsable_season_ids ) . tagged_with ( "u#{ current_user.id }" , on : :tags_by_users ) . select ( :id , :season_id ) . map { | meeting | meeting . id } if current_user . has_associated_swimmer? browsable_season_ids . map { | season_id | current_user . find_team_affiliation_id_from_badges_for ( season_id ) } . compact . each do | tagger_team_affiliation_id | meeting_id_list += Meeting . where ( [ "meetings.season_id IN (?)" , browsable_season_ids ] ) . tagged_with ( "ta#{ tagger_team_affiliation_id }" , on : :tags_by_teams ) . select ( :id , :season_id ) . map { | meeting | meeting . id } end meeting_id_list += current_user . swimmer . meetings . where ( [ "meetings.season_id IN (?)" , browsable_season_ids ] ) . select ( :id , :season_id ) . map { | meeting | meeting . id } end @calendarMeetingPicker = CalendarMeetingPicker . new ( nil , nil , nil , meeting_id_list . uniq! ) @calendarDAO = @calendarMeetingPicker . pick_meetings ( 'DESC' , false , current_user ) @meetings = @calendarDAO . get_meetings end
Enlists all "my" meetings for the current user.
Enlists all " my " meetings for the current user .
# Why refine? If user tags a meeting out form his affikliation it should be shown # Refine the list of open seasons: #browsable_season_ids = open_season_ids.select{ |season_id| #  ! current_user.find_team_affiliation_id_from_badges_for( season_id ).nil? #} + open_season_ids.select{ |season_id| #  ! current_user.find_team_affiliation_id_from_team_managers_for( season_id ).nil? #} #browsable_season_ids.uniq! # Extract the user-tagged browsable meetings: # If user has an associated swimmer look for team tagged and attended meetings too # Add also the team-tagged browsable meetings. # Find the current, browsable team affiliations that may have tagged the meetings, # and, for each, add any tagged meeting found to the list: #          .where( ["meetings.id not in (?) and meetings.season_id IN (?)", meeting_id_list, browsable_season_ids] ) # Add also any already attended and closed meeting belonging to the browsable # seasons: (the relationship w/ swimmer is through MIRs, so the inner join is enough) #        .where( ["meetings.id not in (?) and meetings.season_id IN (?)", meeting_id_list, browsable_season_ids] )