|
|
|
|
@ -40,7 +40,12 @@ class Queries { |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static func mostCashes(realm: Realm, notable: Bool = false) -> [CumulatedResults] { |
|
|
|
|
enum SortBy { |
|
|
|
|
case cashes |
|
|
|
|
case wins |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static func mostCashes(realm: Realm, notable: Bool = false, sort: SortBy = .cashes) -> [CumulatedResults] { |
|
|
|
|
|
|
|
|
|
var players = realm.objects(Player.self) |
|
|
|
|
if (notable) { |
|
|
|
|
@ -52,12 +57,22 @@ class Queries { |
|
|
|
|
crArray.append(CumulatedResults(player: player)) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
switch sort { |
|
|
|
|
case .cashes: |
|
|
|
|
return crArray.sorted(by: { (cr1, cr2) -> Bool in |
|
|
|
|
if cr1.numberOfCashes == cr2.numberOfCashes { |
|
|
|
|
return cr1.total > cr2.total |
|
|
|
|
} |
|
|
|
|
return cr1.numberOfCashes > cr2.numberOfCashes |
|
|
|
|
}) |
|
|
|
|
case .wins: |
|
|
|
|
return crArray.sorted(by: { (cr1, cr2) -> Bool in |
|
|
|
|
if cr1.winsCount == cr2.winsCount { |
|
|
|
|
return cr1.numberOfCashes > cr2.numberOfCashes |
|
|
|
|
} |
|
|
|
|
return cr1.winsCount > cr2.winsCount |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static func allWinnersSortedByEvent(realm: Realm, date: Date? = nil) -> [TournamentWinner] { |
|
|
|
|
@ -261,5 +276,4 @@ class Queries { |
|
|
|
|
return games |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|