Aggiunge i tornei con hub, pagina pubblica e tabellone per semifinali e finali.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -2,7 +2,14 @@ class Match < ApplicationRecord
|
||||
include Coverable
|
||||
|
||||
belongs_to :team
|
||||
belongs_to :tournament, optional: true
|
||||
belongs_to :home_participant, class_name: "TournamentParticipant", optional: true
|
||||
belongs_to :away_participant, class_name: "TournamentParticipant", optional: true
|
||||
belongs_to :tournament_group, optional: true
|
||||
belongs_to :tournament_round, optional: true
|
||||
belongs_to :winner_participant, class_name: "TournamentParticipant", optional: true
|
||||
has_many :stream_sessions, dependent: :destroy
|
||||
has_many :broadcast_assignments, class_name: "TournamentBroadcastAssignment", dependent: :destroy
|
||||
|
||||
has_one_attached :opponent_logo_file
|
||||
|
||||
@@ -20,6 +27,8 @@ class Match < ApplicationRecord
|
||||
|
||||
before_validation :normalize_sport_key
|
||||
before_validation :inherit_sport_from_team, on: :create
|
||||
before_validation :sync_tournament_display_names
|
||||
after_commit :sync_tournament_broadcast_assignments, on: %i[create update]
|
||||
|
||||
scope :scheduled_for_live, -> {
|
||||
where.not(scheduled_at: nil).where("scheduled_at >= ?", Time.zone.now)
|
||||
@@ -116,6 +125,30 @@ class Match < ApplicationRecord
|
||||
Sports::Catalog.find_optional(sport_key)&.dig(:label) || sport_key.to_s.humanize
|
||||
end
|
||||
|
||||
def tournament_match?
|
||||
has_attribute?(:tournament_id) && tournament_id.present?
|
||||
end
|
||||
|
||||
def home_display_name
|
||||
home_participant&.name.presence || (tournament_match? ? I18n.t("tournaments.tbd") : team.name)
|
||||
end
|
||||
|
||||
def away_display_name
|
||||
away_participant&.name.presence || (tournament_match? ? I18n.t("tournaments.tbd") : opponent_name.presence)
|
||||
end
|
||||
|
||||
def matchup_label
|
||||
"#{home_display_name} vs #{away_display_name}"
|
||||
end
|
||||
|
||||
def played?
|
||||
result_status == "played"
|
||||
end
|
||||
|
||||
def court_or_location
|
||||
court.presence || location
|
||||
end
|
||||
|
||||
# Alias legacy API/spec (colonna rinominata in sport_key).
|
||||
def sport
|
||||
sport_key
|
||||
@@ -132,12 +165,34 @@ class Match < ApplicationRecord
|
||||
end
|
||||
|
||||
def inherit_sport_from_team
|
||||
if has_attribute?(:tournament_id) && tournament.present?
|
||||
self.sport_key = tournament.sport_key if new_record? || sport_key.blank?
|
||||
return
|
||||
end
|
||||
|
||||
return unless team.present?
|
||||
|
||||
# Il default DB (pallavolo) non deve prevalere sullo sport della squadra alla creazione.
|
||||
self.sport_key = team.sport_key if new_record? || sport_key.blank?
|
||||
end
|
||||
|
||||
def sync_tournament_display_names
|
||||
return unless has_attribute?(:tournament_id) && tournament_id.present?
|
||||
|
||||
self.opponent_name = away_display_name if away_participant.present? || opponent_name.blank?
|
||||
venue_court = [tournament&.venue, court].compact_blank
|
||||
self.location = venue_court.join(" — ") if venue_court.any?
|
||||
|
||||
self.category = tournament.name if category.blank? && tournament.present?
|
||||
end
|
||||
|
||||
def sync_tournament_broadcast_assignments
|
||||
return unless has_attribute?(:tournament_id) && tournament_id.present?
|
||||
return unless saved_change_to_court? || saved_change_to_scheduled_at? || previously_new_record?
|
||||
|
||||
Tournaments::SyncAssignments.sync_match!(self)
|
||||
end
|
||||
|
||||
def sport_key_known
|
||||
return if sport_key.blank?
|
||||
return if Sports::Catalog.find_optional(sport_key)
|
||||
|
||||
Reference in New Issue
Block a user