@ -44,9 +44,8 @@ class Tournament : ModelObject, Storable {
var additionalEstimationDuration : Int = 0
var isDeleted : Bool = false
var isCanceled : Bool = false
var publishManually : Bool = false
var publishTeams : Bool = false
var publishWaitingList : Bool = fals e
// v a r p u b l i s h W a i t i n g L i s t : B o o l = f a l s e
var publishSummons : Bool = false
var publishGroupStages : Bool = false
var publishBrackets : Bool = false
@ -88,15 +87,14 @@ class Tournament : ModelObject, Storable {
case _isDeleted = " isDeleted "
case _isCanceled = " localId "
case _payment = " globalId "
case _publishManually = " publishManually "
case _publishTeams = " publishTeams "
case _publishWaitingList = " publishWaitingList "
// c a s e _ p u b l i s h W a i t i n g L i s t = " p u b l i s h W a i t i n g L i s t "
case _publishSummons = " publishSummons "
case _publishGroupStages = " publishGroupStages "
case _publishBrackets = " publishBrackets "
}
internal init ( event : String ? = nil , name : String ? = nil , startDate : Date = Date ( ) , endDate : Date ? = nil , creationDate : Date = Date ( ) , isPrivate : Bool = false , groupStageFormat : MatchFormat ? = nil , roundFormat : MatchFormat ? = nil , loserRoundFormat : MatchFormat ? = nil , groupStageSortMode : GroupStageOrderingMode , groupStageCount : Int = 4 , rankSourceDate : Date ? = nil , dayDuration : Int = 1 , teamCount : Int = 24 , teamSorting : TeamSortingType ? = nil , federalCategory : TournamentCategory , federalLevelCategory : TournamentLevel , federalAgeCategory : FederalTournamentAge , groupStageCourtCount : Int ? = nil , closedRegistrationDate : Date ? = nil , groupStageAdditionalQualified : Int = 0 , courtCount : Int = 2 , prioritizeClubMembers : Bool = false , qualifiedPerGroupStage : Int = 1 , teamsPerGroupStage : Int = 4 , entryFee : Double ? = nil , additionalEstimationDuration : Int = 0 , isDeleted : Bool = false , publishManually : Bool = false , publishTeams : Bool = false , publishWaitingList : Bool = false , publishSummons : Bool = false , publishGroupStages : Bool = false , publishBrackets : Bool = false ) {
internal init ( event : String ? = nil , name : String ? = nil , startDate : Date = Date ( ) , endDate : Date ? = nil , creationDate : Date = Date ( ) , isPrivate : Bool = false , groupStageFormat : MatchFormat ? = nil , roundFormat : MatchFormat ? = nil , loserRoundFormat : MatchFormat ? = nil , groupStageSortMode : GroupStageOrderingMode , groupStageCount : Int = 4 , rankSourceDate : Date ? = nil , dayDuration : Int = 1 , teamCount : Int = 24 , teamSorting : TeamSortingType ? = nil , federalCategory : TournamentCategory , federalLevelCategory : TournamentLevel , federalAgeCategory : FederalTournamentAge , groupStageCourtCount : Int ? = nil , closedRegistrationDate : Date ? = nil , groupStageAdditionalQualified : Int = 0 , courtCount : Int = 2 , prioritizeClubMembers : Bool = false , qualifiedPerGroupStage : Int = 1 , teamsPerGroupStage : Int = 4 , entryFee : Double ? = nil , additionalEstimationDuration : Int = 0 , isDeleted : Bool = false , publishTeams : Bool = false , publishSummons : Bool = false , publishGroupStages : Bool = false , publishBrackets : Bool = false ) {
self . event = event
self . name = name
self . startDate = startDate
@ -125,6 +123,10 @@ class Tournament : ModelObject, Storable {
self . entryFee = entryFee
self . additionalEstimationDuration = additionalEstimationDuration
self . isDeleted = isDeleted
self . publishTeams = publishTeams
self . publishSummons = publishSummons
self . publishBrackets = publishBrackets
self . publishGroupStages = publishGroupStages
}
required init ( from decoder : Decoder ) throws {
@ -160,9 +162,7 @@ class Tournament : ModelObject, Storable {
additionalEstimationDuration = try container . decode ( Int . self , forKey : . _additionalEstimationDuration )
isDeleted = try container . decode ( Bool . self , forKey : . _isDeleted )
isCanceled = try Tournament . _decodeCanceled ( container : container )
publishManually = try container . decodeIfPresent ( Bool . self , forKey : . _publishManually ) ? ? false
publishTeams = try container . decodeIfPresent ( Bool . self , forKey : . _publishTeams ) ? ? false
publishWaitingList = try container . decodeIfPresent ( Bool . self , forKey : . _publishWaitingList ) ? ? false
publishSummons = try container . decodeIfPresent ( Bool . self , forKey : . _publishSummons ) ? ? false
publishGroupStages = try container . decodeIfPresent ( Bool . self , forKey : . _publishGroupStages ) ? ? false
publishBrackets = try container . decodeIfPresent ( Bool . self , forKey : . _publishBrackets ) ? ? false
@ -295,6 +295,55 @@ class Tournament : ModelObject, Storable {
case canceled
}
func publishedTeamsDate ( ) -> Date {
startDate
}
func areTeamsPublished ( ) -> Bool {
Date ( ) >= startDate
}
func publishedGroupStagesDate ( ) -> Date ? {
if let first = groupStages ( ) . flatMap ( { $0 . playedMatches ( ) } ) . compactMap ( { $0 . startDate } ) . sorted ( ) . first ? . atNine ( ) {
if first . isEarlierThan ( startDate ) {
return startDate
} else {
return first
}
} else {
return nil
}
}
func areGroupStagesPublished ( ) -> Bool {
if let publishedGroupStagesDate = publishedGroupStagesDate ( ) {
return Date ( ) >= publishedGroupStagesDate
} else {
return false
}
}
func publishedBracketsDate ( ) -> Date ? {
if let first = rounds ( ) . flatMap ( { $0 . playedMatches ( ) } ) . compactMap ( { $0 . startDate } ) . sorted ( ) . first ? . atNine ( ) {
if first . isEarlierThan ( startDate ) {
return startDate
} else {
return first
}
} else {
return nil
}
}
func areBracketsPublished ( ) -> Bool {
if let publishedBracketsDate = publishedBracketsDate ( ) {
return Date ( ) >= publishedBracketsDate
} else {
return false
}
}
func shareURL ( ) -> URL ? {
return URLs . main . url . appending ( path : " tournament/ \( id ) " )
}
@ -1096,7 +1145,7 @@ class Tournament : ModelObject, Storable {
let matches = ( 0. . < matchCount ) . map { // 0 i s f i n a l m a t c h
let roundIndex = RoundRule . roundIndex ( fromMatchIndex : $0 )
let round = rounds [ roundIndex ]
return Match ( round : round . id , index : $0 , matchFormat : matchFormat )
return Match ( round : round . id , index : $0 , matchFormat : matchFormat , name : Match . setServerTitle ( upperRound : round , matchIndex : RoundRule . matchIndexWithinRound ( fromMatchIndex : $0 ) ) )
}
print ( matches . map {