Module:PlayerResults

local placement = require('Module:Placement') local m_team = require('Module:Team') local League = require('Module:League').league local m_role = require('Module:Role')

local p = {}

function p.playerResults( frame ) if frame == mw.getCurrentFrame then args = require( 'Module:ProcessArgs').norm else frame = mw.getCurrentFrame end local player = args[1] or mw.title.getCurrentTitle.baseText local fieldstable = { "TournamentResults.TeamLink=TeamLink", "TournamentResults.Prize_Markup=PrizeMarkup", "TournamentResults.Date=Date", "TournamentResults.Place=Place", "TournamentResults.Event=Event", "TournamentResults.Phase=Phase", "CONCAT(TournamentResults._pageName)=EventLink", "TournamentRosters.RosterLinks__full=RosterLinks", "TournamentRosters.Roster=RosterNames", "TournamentRosters.Roles=Roles", "Tournaments.League=League", "CONCAT(PlayerRedirects.AllName)=ThisName", }	local cargotables = "TournamentRosters, TournamentResults, Tournaments, PlayerRedirects" local cargojoin = "TournamentRosters._pageName = TournamentResults.RosterPage, TournamentResults._pageName=Tournaments._pageName, TournamentRosters.RosterLinks HOLDS PlayerRedirects.AllName" local cargofields = table.concat(fieldstable,",") local cargowhere = 'PlayerRedirects._pageName="' .. player .. '" AND TournamentRosters.TeamLink = TournamentResults.TeamLink' local cargogroupBy = "TournamentResults.UniqueLine" local cargoorderBy = "TournamentResults.Date desc" local cargoquery = { where = cargowhere, join = cargojoin, groupBy = cargogroupBy, orderBy = cargoorderBy } cargoquery.limit = p.getLimit(args.show) local result = mw.ext.cargo.query(cargotables, cargofields, cargoquery) local tbl = mw.html.create('table') tbl:addClass("wikitable sortable"):css("font-size","90%") :tag("tr") :tag("th"):css({ background = "#E6E6E6", border = "1px solid black" }):attr("colspan","30") :wikitext(player .. ' Tournament Results'):done :done :tag("tr") :tag("th"):css("width","60"):wikitext("Date"):done :tag("th"):css("width","60"):wikitext("Place"):done :tag("th"):css("width","300"):wikitext("Event"):done :tag("th"):css("width","250"):wikitext("Team"):done :tag("th"):wikitext("Roster"):done :done for _,row in ipairs(result) do		tr = tbl:tag("tr") tr:tag("td"):css({ ['white-space'] = 'nowrap' }):wikitext(row.Date):done :node(placement.makeNode(row.Place)) tdEvent = tr:tag("td"):wikitext(League{row.League,"onlyimage"} .. " " .. row.Event)		if row["Phase"] ~= "" then			tdEvent:wikitext(" - " .. row.Phase)		end 		tdEvent:wikitext(""):done tr:tag("td"):wikitext(m_team.rightshortlinked(row.TeamLink)) tr:tag("td"):wikitext(p.getTeammates(row.RosterNames, row.RosterLinks, row.Roles, row.ThisName)) end frame:callParserFunction{name="#vardefine:hasnewresults",args={"yes"}} local text = {} text[#text+1] = p.intro(args.show) text[#text+1] = tostring(tbl) output = table.concat(text,'') return output end

function p.getLimit(show) if show == 'overviewpage' then return 5 elseif show == 'everything' then return 500 end return nil end

function p.getTeammates(namesstr, linksstr, rolesstr, thisname) local teammates = {} local teammatenames = mw.text.split(namesstr,"%s*;;%s*") local teammatelinks = mw.text.split(linksstr,"%s*;;%s*") local roles = mw.text.split(rolesstr,"%s*;;%s*") for index,teammatelink in ipairs(teammatelinks) do		local thisroles = {} for i, role in ipairs(mw.text.split(roles[index] or '','%s*,%s*')) do			thisroles[i] = (m_role.onlyimage(role)) end local thisrole = table.concat(thisroles,"") if mw.ustring.lower(teammatelink) == mw.ustring.lower(thisname) then teammates[#teammates+1] = thisrole .. " '''" .. teammatenames[index] .. "'''"		else teammates[#teammates+1] = thisrole .. " " .. teammatenames[index] .. "" end end local output = table.concat(teammates, ", ") return output end

function p.intro(show) if show == 'overviewpage' then return string.format(":This table shows up to the 5 most recent results. For complete results, click here.",mw.title.getCurrentTitle.rootText) end return '' end

function p.intro(show) if notitletext == 'yes' then return nil end return '' end

return p