(debug old with fakeHoldsVariable) |
((via Mediawiker ST3)) |
||
Line 56: | Line 56: | ||
'TournamentResults.PageAndTeam IS NOT NULL', |
'TournamentResults.PageAndTeam IS NOT NULL', |
||
'TournamentRosters.PageAndTeam IS NOT NULL', |
'TournamentRosters.PageAndTeam IS NOT NULL', |
||
⚫ | |||
− | use_redirect_table and util_cargo.fakeHoldsVariable('TournamentRosters.RosterLinks', 'PlayerRedirects.AllName', ';;'), |
||
− | not use_redirect_table and ('TournamentRosters.RosterLinks HOLDS BINARY "%s"'):format(player), |
||
args.minplacement and ('Place_Number <= "%s"'):format(args.minplacement), |
args.minplacement and ('Place_Number <= "%s"'):format(args.minplacement), |
||
} |
} |
||
+ | h.addRedirectWhereConditionToWhere(tbl, player, use_redirect_table) |
||
return util_cargo.concatWhere(tbl) |
return util_cargo.concatWhere(tbl) |
||
+ | end |
||
+ | |||
+ | function h.addRedirectWhereConditionToWhere(tbl, player, use_redirect_table) |
||
+ | if use_redirect_table then |
||
⚫ | |||
+ | tbl[#tbl+1] = h.getRosterHoldsCondition('PlayerRedirects.AllName', util_cargo.fakeHoldsVariable) |
||
+ | else |
||
+ | tbl[#tbl+1] = h.getRosterHoldsCondition(player, util_cargo.fakeHolds) |
||
+ | end |
||
+ | end |
||
+ | |||
+ | function h.getRosterHoldsCondition(str, f) |
||
+ | local tbl = { |
||
+ | f('TournamentRosters.RosterLinks', str, ' *;; '), |
||
+ | f('TournamentResults.RosterLinks_Res', str, ' *;; *'), |
||
+ | } |
||
+ | return util_cargo.concatWhereOr(tbl) |
||
end |
end |
||
Revision as of 07:53, 30 June 2019
Edit the documentation or categories for this module. This module has an i18n file.
local util_args = require('Module:ArgsUtil')
local util_cargo = require('Module:CargoUtil')
local util_game = require('Module:GameUtil')
local util_html = require('Module:HTMLUtil')
local util_table = require('Module:TableUtil')
local util_text = require('Module:TextUtil')
local util_tournament = require('Module:TournamentUtil')
i18n = require('Module:I18nUtil')
local sep = '%s*;;%s*'
local m_team = require('Module:Team')
local League = require('Module:League').league
local placement = require('Module:Placement')
local COLUMNS = { 'Date', 'TeamSize', 'Place', 'PRPoints', 'Event', 'Team', 'Roster' }
local h = {}
function h.doQuery(player, show, use_redirect_table, args)
-- use_redirect_table will be false in self namespace
local tbl = {
tables = h.getTables(use_redirect_table),
join = h.getJoin(use_redirect_table),
where = h.getWhere(player, use_redirect_table, args),
fields = h.getFields(player, use_redirect_table),
groupBy = 'TournamentResults.UniqueLine',
orderBy = 'TournamentResults.Date DESC',
limit = h.getLimit(show),
}
return util_cargo.queryAndCast(tbl)
end
function h.getTables(redirects)
local tbl = { 'TournamentRosters', 'TournamentResults', 'InfoboxTournament=Tournaments' }
if redirects then
tbl[#tbl+1] = 'PlayerRedirects'
end
return tbl
end
function h.getJoin(redirects)
local tbl = {
'TournamentRosters.UniqueLine = TournamentResults.UniqueLine',
'TournamentResults.OverviewPage=Tournaments._pageName'
}
if redirects then
tbl[#tbl+1] = 'TournamentRosters.RosterLinks HOLDS PlayerRedirects.AllName'
end
return util_table.concat(tbl, ', ')
end
function h.getWhere(player, use_redirect_table, args)
local tbl = {
'TournamentResults.PageAndTeam IS NOT NULL',
'TournamentRosters.PageAndTeam IS NOT NULL',
args.minplacement and ('Place_Number <= "%s"'):format(args.minplacement),
}
h.addRedirectWhereConditionToWhere(tbl, player, use_redirect_table)
return util_cargo.concatWhere(tbl)
end
function h.addRedirectWhereConditionToWhere(tbl, player, use_redirect_table)
if use_redirect_table then
tbl[#tbl+1] = ('PlayerRedirects._pageName="%s"'):format(player)
tbl[#tbl+1] = h.getRosterHoldsCondition('PlayerRedirects.AllName', util_cargo.fakeHoldsVariable)
else
tbl[#tbl+1] = h.getRosterHoldsCondition(player, util_cargo.fakeHolds)
end
end
function h.getRosterHoldsCondition(str, f)
local tbl = {
f('TournamentRosters.RosterLinks', str, ' *;; '),
f('TournamentResults.RosterLinks_Res', str, ' *;; *'),
}
return util_cargo.concatWhereOr(tbl)
end
function h.getFields(player, redirects)
local tbl = {
"TournamentResults.Team=Team",
"TournamentResults.Prize_Markup=PrizeMarkup",
"Tournaments.Date=Date",
"TournamentResults.Place=Place",
"Tournaments.Name=Event",
"Tournaments.TeamSize=TeamSize",
"TournamentResults.Phase=Phase",
"Tournaments._pageName=EventLink",
"TournamentRosters.RosterLinks__full=RosterLinks",
"TournamentRosters.Roster=RosterNames",
"Tournaments.League=League",
"TournamentResults.PRPoints=PRPoints",
}
if redirects then
tbl[#tbl+1] = "CONCAT(PlayerRedirects.AllName)=ThisName"
else
tbl[#tbl+1] = ('CONCAT("%s")=ThisName'):format(player)
end
return tbl
end
function h.getLimit(show)
if show == 'overviewpage' then
return 10
elseif show == 'everything' then
return 500
end
return nil
end
function h.getTeammates(namesstr, linksstr, this)
local teammates = {}
local names = mw.text.split(namesstr or '',sep)
local links = mw.text.split(linksstr or '',sep)
for i,link in ipairs(links) do
if mw.ustring.lower(link) == mw.ustring.lower(this) then
teammates[#teammates+1] = ("'''%s'''"):format(names[i])
else
teammates[#teammates+1] = ("[[%s|%s]]"):format(link, names[i])
end
end
return table.concat(teammates, ", ")
end
function h.intro(args)
if args.show == 'overviewpage' then
return "''" .. i18n.print('seeall', mw.title.getCurrentTitle().rootText) .. "''"
end
return ''
end
local p = {}
function p.playerResults( frame )
i18n.initGlobalFromFile('PlayerResults')
local args = util_args.merge(true)
local player = args[1] or mw.title.getCurrentTitle().baseText
local use_redirect_table = not util_args.castAsBool(args.noredirects)
local result = h.doQuery(player, args.show, use_redirect_table, args)
local output = mw.html.create('div')
if args.show == 'everything' then
output = output:tag('div')
output:attr('id','trf-content')
end
local tbl = output:tag('table')
tbl:addClass("wikitable sortable hoverable-rows"):css("font-size","90%")
util_html.makeColspanHeader(tbl, i18n.print('TournamentResults', player), #COLUMNS)
util_html.headerFromI18n(tbl, COLUMNS)
for _,row in ipairs(result) do
tr = tbl:tag("tr")
tr:tag("td"):addClass('achievements-date'):wikitext(row.Date):done()
tr:tag('td'):wikitext(util_game.teamsize_names[row.TeamSize])
tr:node(placement.makeNode(row.Place))
tr:tag('td'):wikitext(row.PRPoints)
tr:tag("td")
:wikitext(League{row.League, 'onlyimage'})
:wikitext(util_text.intLink(row.EventLink, h.eventDisplay(row)))
tr:tag("td"):wikitext(m_team.rightshortlinked(row.Team))
tr:tag("td"):wikitext(h.getTeammates(row.RosterNames, row.RosterLinks, row.ThisName))
end
frame:callParserFunction{name="#vardefine:hasnewresults",args={"yes"}}
return h.intro(args), output
end
function h.eventDisplay(row)
if row.Phase then
return ('%s - %s'):format(row.Event, row.Phase)
end
return row.Event
end
return p