forked from SteamWar/SteamWar
Add even more Advancements
This commit is contained in:
@@ -86,6 +86,24 @@ class CheckedSchematic(id: EntityID<CompositeID>) : CompositeEntity(id) {
|
||||
useDb {
|
||||
find { (CheckedSchematicTable.nodeOwner eq owner.id) and (CheckedSchematicTable.seen eq false) }.orderBy(CheckedSchematicTable.endTime to SortOrder.DESC).toList()
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun countAccepted(owner: SteamwarUser) =
|
||||
useDb {
|
||||
find { (CheckedSchematicTable.nodeOwner eq owner.id) and (CheckedSchematicTable.declineReason eq "freigegeben") }.count()
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun countAccepted(owner: SteamwarUser, type: String) =
|
||||
useDb {
|
||||
find { (CheckedSchematicTable.nodeOwner eq owner.id) and (CheckedSchematicTable.declineReason eq "freigegeben") and (CheckedSchematicTable.nodeType like "$type%") }.count()
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun countChecked(validator: SteamwarUser) =
|
||||
useDb {
|
||||
find { CheckedSchematicTable.validator eq validator.id }.count()
|
||||
}
|
||||
}
|
||||
|
||||
val node by CheckedSchematicTable.nodeId.transform({ it?.let { EntityID(it, SchematicNodeTable) } }, { it?.value })
|
||||
|
||||
@@ -130,6 +130,38 @@ class EventFight(id: EntityID<Int>) : IntEntity(id), Comparable<EventFight> {
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun countEventFights(fighter: SteamwarUser) =
|
||||
useDb {
|
||||
exec(
|
||||
"SELECT COUNT(DISTINCT F.FightID) AS FightCount FROM FightPlayer INNER JOIN Fight F on FightPlayer.FightID = F.FightID INNER JOIN EventFight EF on F.FightID = EF.Fight WHERE UserID = ?",
|
||||
args = listOf(IntegerColumnType() to fighter.id.value)
|
||||
) {
|
||||
if (it.next()) {
|
||||
it.getLong("FightCount")
|
||||
} else {
|
||||
0
|
||||
}
|
||||
}
|
||||
?: 0
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun getHighestPlacement(fighter: SteamwarUser) =
|
||||
useDb {
|
||||
exec(
|
||||
"SELECT MIN(TT.Placement) AS Placement FROM FightPlayer INNER JOIN Fight F on FightPlayer.FightID = F.FightID INNER JOIN EventFight EF on F.FightID = EF.Fight INNER JOIN TeamTeilnahme TT on TT.EventID = EF.EventID WHERE UserID = ?",
|
||||
args = listOf(IntegerColumnType() to fighter.id.value)
|
||||
) {
|
||||
if (it.next()) {
|
||||
it.getInt("Placement")
|
||||
} else {
|
||||
Int.MAX_VALUE
|
||||
}
|
||||
}
|
||||
?: Int.MAX_VALUE
|
||||
}
|
||||
}
|
||||
|
||||
val fightID by EventFightTable.id.transform({ EntityID(it, EventFightTable) }, { it.value })
|
||||
|
||||
@@ -20,9 +20,12 @@
|
||||
package de.steamwar.sql
|
||||
|
||||
import de.steamwar.sql.internal.useDb
|
||||
import org.jetbrains.exposed.v1.core.IntegerColumnType
|
||||
import org.jetbrains.exposed.v1.core.VarCharColumnType
|
||||
import org.jetbrains.exposed.v1.core.dao.id.CompositeID
|
||||
import org.jetbrains.exposed.v1.core.dao.id.CompositeIdTable
|
||||
import org.jetbrains.exposed.v1.core.dao.id.EntityID
|
||||
import org.jetbrains.exposed.v1.core.eq
|
||||
import org.jetbrains.exposed.v1.core.inList
|
||||
import org.jetbrains.exposed.v1.dao.CompositeEntity
|
||||
import org.jetbrains.exposed.v1.dao.CompositeEntityClass
|
||||
@@ -69,6 +72,28 @@ class FightPlayer(id: EntityID<CompositeID>) : CompositeEntity(id) {
|
||||
useDb {
|
||||
find { FightPlayerTable.fightId inList fightIds.toList() }.toList()
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun countFights(userId: Int) =
|
||||
useDb {
|
||||
find { FightPlayerTable.userId eq userId }.count()
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun countFights(userId: Int, type: String) =
|
||||
useDb {
|
||||
exec(
|
||||
"SELECT COUNT(*) AS FightCount FROM FightPlayer INNER JOIN Fight F on FightPlayer.FightID = F.FightID WHERE UserID = ? AND GameMode LIKE ?",
|
||||
args = listOf(IntegerColumnType() to userId, VarCharColumnType() to "$type%")
|
||||
) {
|
||||
if (it.next()) {
|
||||
it.getInt("FightCount")
|
||||
} else {
|
||||
0
|
||||
}
|
||||
}
|
||||
?: 0
|
||||
}
|
||||
}
|
||||
|
||||
val fightID by FightPlayerTable.fightId.transform({ EntityID(it, FightTable) }, { it.value })
|
||||
|
||||
Reference in New Issue
Block a user