Documentation for this module may be created at Module:TournamentResultsQueryAbstract/doc
local util_args = require('Module:ArgsUtil')
local util_cargo = require('Module:CargoUtil')
local util_esports = require('Module:EsportsUtil')
local util_html = require('Module:HtmlUtil')
local util_map = require('Module:MapUtil')
local util_table = require('Module:TableUtil')
local util_text = require('Module:TextUtil')
local util_toggle = require('Module:ToggleUtil')
local util_tournament = require('Module:TournamentUtil')
local util_vars = require('Module:VarsUtil')
local i18n = require('Module:i18nUtil')
local Reload = require('Module:Reload')
local m_team = require('Module:Team')
local Sprite = require('Module:Sprite').sprite
local lang = mw.getLanguage('en')
local placement = require('Module:Placement')
local PopupButton = require('Module:PopupButton')
local sep = '%s*;;%s*'
local sep2 = '%s*,%s*'
local h = {}
local s = {}
local p = require('Module:LuaClassSystem').class.abstract()
p.CURRENCY_TOGGLE = {
order = { 'Local', 'USD', 'Euros' },
sep = ' • ',
section = 'teamres-togglers-currency',
all = 'teamres-currency-all',
}
function p:init(queryType)
i18n.init(('%sResults'):format(queryType))
self.queryType = queryType
self.limitOverviewpage = nil
self.limitEverything = nil
self.COLUMNS = {}
end
function p:run(args)
util_toggle.oflInit(self.CURRENCY_TOGGLE)
local subject = self:getSubject(args)
local query = self:getQuery(args, subject)
local result = util_cargo.queryAndCast(query)
util_map.selfRowsInPlace(self, result, self.formatOneRow)
return self:introSentence(args), self:intro(args), self:makeOutput(result, subject)
end
function p:getSubject(args) end
function p:getQuery(args, subject)
local query = {
tables = self:getTables(args),
join = self:getJoin(args),
where = self:getWhere(args, subject),
fields = self:getFields(args),
groupBy = 'Res.UniqueLine',
orderBy = 'Res.Date DESC',
limit = self:getLimit(args)
}
util_cargo.logQuery(query)
return query
end
function p:getTables(args)
local tables = {
"TournamentRosters=Ros",
"TournamentResults=Res",
"Tournaments=T",
}
return tables
end
function p:getJoin(args)
local join = {
"Res.PageAndTeam = Ros.PageAndTeam",
"Res._pageName=T._pageName",
}
return join
end
function p:getWhere(args, subject)
local where = {
'Res.PageAndTeam IS NOT NULL',
'Ros.PageAndTeam IS NOT NULL',
self:getSubjectWhereCondition(args, subject),
args.minplacement and ('Place_Number <= "%s"'):format(args.minplacement),
}
return where
end
function p:getSubjectWhereCondition(subject) end
function p:getFields(args)
local fields = {
"Res.Team",
"Res.Prize_Markup=PrizeMarkup",
"Res.PrizeOther",
"Res.Prize",
"Res.PrizeUnit",
"Res.Prize_USD",
"Res.Prize_Euro",
"Res.Date",
"Res.Place",
"Res.Phase",
"Ros.RosterLinks",
"Ros.Roles",
"Res.LastResult",
"Res.LastOpponent_Markup=LastOpponent",
"T.League",
"T.LeagueIconKey",
"T.OverviewPage=EventLink",
"T.Name=Event",
}
return fields
end
function p:getLimit(args)
if args.show == 'overviewpage' then
return self.limitOverviewpage
elseif args.show == 'everything' then
return self.limitEverything
end
return nil
end
function p:formatOneRow(row)
row.LastResult = self:getLastResult(row)
row.Prize = self:getPrizeDisplay(row)
row.Roster = self:getRoster(row)
row.Tournament = ('%s %s%s'):format(
s.LeagueSprite(row.LeagueIconKey or row.League),
util_text.intLink(row.EventLink, row.Event),
row.Phase and (' - %s'):format(row.Phase) or ''
)
row.PlaceDisplay = placement.display(row.Place)
row.classes = {
Prize = 'achivements-prize-cell',
Date = 'achivements-date',
PlaceDisplay = ('achievements-place %s'):format(placement.class(row.Place) or ''),
LastResult = 'achievements-lastresult-cell'
}
row.attrs = {
PlaceDisplay = {
['data-sort-value'] = placement.sort(row.Place)
}
}
end
function p:getLastResult(row)
local div = mw.html.create('div')
:addClass('achievements-lastresult-outer')
div:tag('span')
:addClass('achievements-lastresult-inner')
:wikitext(row.LastResult)
div:wikitext(row.LastOpponent)
local div_right = div:tag('div')
:addClass('achievements-lastresult-right')
PopupButton.tth(div_right, row.EventLink, row.Event, row.Team)
return tostring(div)
end
function p:getPrizeDisplay(row)
local currencydisplay = { Local = row.PrizeMarkup }
if row.Prize then
row.PrizeMarkup = row.PrizeMarkup or row.Prize
if row.Prize_USD and row.Prize_USD ~= '' then
currencydisplay.USD = '$ ' .. lang:formatNum(tonumber(row.Prize_USD))
else
currencydisplay.USD = '<span style="font-style:italic;">' .. row.PrizeMarkup .. '</span>'
end
if row.Prize_Euro and row.Prize_Euro ~= '' then
currencydisplay.Euros = '€ ' .. lang:formatNum(tonumber(row.Prize_Euro))
else
currencydisplay.Euros = '<span style="font-style:italic;">' .. row.PrizeMarkup .. '</span>'
end
end
local currencyCell = mw.html.create()
for _, v in ipairs(self.CURRENCY_TOGGLE.order) do
self:printOneCurrency(currencydisplay, currencyCell, v)
end
return currencyCell
end
function p:printOneCurrency(displays, currencyCell, this)
local span = currencyCell:tag('span')
:wikitext(displays[this])
util_toggle.oflCellClasses(span, self.CURRENCY_TOGGLE, this)
end
function p:getRoster(row)
local teammates = {}
local links = util_text.split(row.RosterLinks, sep)
local roles = row.Roles and util_text.split(row.Roles, sep) or ''
for i, link in ipairs(links) do
local thisrole = util_map.splitAndConcat(roles[i] or '', nil, s.RoleSprite, nil) or ''
teammates[#teammates+1] = ("%s %s"):format(thisrole, self:getOneMember(link, row))
end
return table.concat(teammates, ", ")
end
function p:getOneMember(link, row)
return util_esports.playerLinked(link)
end
function p:introSentence(args)
if args.show == 'overviewpage' and not Reload.isReload() then
return "''" .. i18n.print('seeall', mw.title.getCurrentTitle().rootText) .. "''"
end
return ''
end
function p:intro(args)
return Reload.intro(
'FilterTournamentResults',
('%sResults'):format(self.queryType),
args
)
end
function p:makeOutput(result, subject)
local output = Reload.wrapper()
local tbl = output:tag('div'):tag('table')
:addClass("wikitable sortable hoverable-rows")
:css({ ["font-size"] = "90%" })
util_html.printColspanHeader(tbl, self:makeHeaderText(subject), #self.COLUMNS)
util_html.printHeaderFromI18n(tbl, self.COLUMNS)
util_html.printRowsByList(tbl, result, self.COLUMNS)
self:finalizeTable(tbl, result, subject)
return output
end
function p:makeHeaderText(subject) end
function p:finalizeTable(tbl) end
function s.RoleSprite(id)
return Sprite{
id,
size = '15',
type = 'Role',
notext = true,
nolink = true,
}
end
function s.LeagueSprite(id)
return Sprite{
id,
type = 'League'
}
end
return p