Module:PlayerListChart

local util_args = require('Module:ArgsUtil') local util_cargo = require('Module:CargoUtil') local util_esports = require("Module:EsportsUtil") local util_map = require("Module:MapUtil") local util_text = require('Module:TextUtil') local m_team = require('Module:Team')

local DEFAULTS = { tables = { 'Players', 'PlayerRedirects=PR', 'PlayerPronunciationFiles=PPF' }, join = { 'Players.OverviewPage=PR.OverviewPage', 'PR.AllName=PPF.Player' }, groupBy = 'Players.OverviewPage', orderBy='ID', limit = '999', types = { IsRetired = 'boolean', }, }

local FIELDS = { 'Players._pageName', 'Players.ID', 'Players.NameFull', 'Players.Team', 'Players.TeamLast', 'COALESCE(Players.Nationality__FULL,Players.Country)=Country [CountryList]', 'Players.Role', 'Players.Stream', 'Players.Twitter', 'Players.Birthdate', 'Players.Age', 'Players.IsRetired', 'PPF._pageName=PronunciationFile', } local FIELDORDER = { 'ID', 'NameFull', 'Team', 'Country', 'Role', 'Stream', 'Twitter', 'Birthdate', 'Age' } local DISPLAY = { TeamLast = 'Last Team', NameFull = 'Name', Birthdate = 'Birthday', Askfm = 'AskFM' }

local h = {} local p = {} function p.main(frame) local args = util_args.merge local query = util_cargo.queryFromArgs(args, DEFAULTS) local fieldorder = h.getFields(args.fieldorder, query, util_args.castAsBool(args.lastteam)) util_cargo.logQuery(query) local result = util_cargo.queryAndCast(query) h.formatResults(result) return h.printTable(result, fieldorder) end

function h.getFields(fieldorder, query, lastteam) if not query.fields then query.fields = mw.clone(FIELDS) local order = mw.clone(FIELDORDER) if lastteam then order[3] = 'TeamLast' end return order else return util_text.split(fieldorder or query.fields) end end

function h.formatResults(result) for i, row in ipairs(result) do		h.formatResult(row) end return end

function h.formatResult(row) -- we allow field list to be specified outside of this module for some terrible reason -- this should be changed to COLUMNS later -- but for now check existence of fields before assuming they are here row.ID = h.getDisplayId(row) row.Team = h.getTeam(row) row.TeamLast = row.TeamLast and m_team.rightmediumlinked(row.TeamLast) row.Country = row.Country and row.Country:flairs{sep=' '} row.Stream = row.Stream and string.format('[%s Stream]', row.Stream) row.Twitter = row.Twitter and string.format(		'%s',		row.Twitter,		row.Twitter	) row.Askfm = row.Askfm and string.format(		'%s',		row.Askfm,		row.Askfm	) end

function h.getTeam(row) if row.IsRetired then return m_team.rightmediumlinked('Retired') end return row.Team and m_team.rightmediumlinked(row.Team) end

function h.getDisplayId(row) return util_text.intLink(row._pageName, row.ID) .. ' ' .. h.makePPFButton(row.PronunciationFile) end

function h.makePPFButton(file) if not file then return '' end return tostring(mw.getCurrentFrame:callParserFunction{			name = '#tag:sm2',			args = { file:gsub('File:', '') }		}) end

function h.printTable(result, fieldorder) local tbl = mw.html.create('table') :addClass('cargoTable') :addClass('sortable') h.addHeading(tbl, fieldorder) for _, row in ipairs(result) do		local tr = tbl:tag('tr') for _, v in ipairs(fieldorder) do			tr:tag('td') :addClass('field_' .. v)				:wikitext(row[v]) end end return tbl end

function h.addHeading(tbl, fieldorder) local tr = tbl:tag('tr') for _, v in ipairs(fieldorder) do		tr:tag('th'):wikitext(DISPLAY[v] or v)	end return end return p