Module:PlayerCurrentTeam

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_sort = require("Module:SortUtil") local util_source = require("Module:SourceUtil") local util_table = require("Module:TableUtil") local util_text = require("Module:TextUtil") local util_title = require("Module:TitleUtil") local util_vars = require("Module:VarsUtil") local i18n = require('Module:i18nUtil')

local OD = require('Module:OrderedDict')

local PCT = require('Module:NewsCurrentStatusAbstract'):extends

local h = {}

local p = {}

-- for testing to be called from MW function p.test(frame) local args = util_args.merge local result = p.main(args[1]) local output = mw.html.create('table') :addClass('wikitable') for _, row in ipairs(result) do		output:tag('tr') :tag('td'):wikitext(row.team) :tag('td'):wikitext(tostring(row.role)) :tag('td'):wikitext(row.role:images) end return output end

-- intended to be called by Infobox/Player -- so this does not apply any processing to the output -- and instead just returns a data table function p.main(player) return PCT:init(player) end

function PCT:defaultOutput return { last = {}, contractDates = {} } end

function PCT:getTables local ret = { 'NewsItems=News', 'RosterChanges=RC', 'PlayerRedirects=PR1', 'Contracts', 'PlayerRedirects=PR2', 'TeamRedirects=TRed1', -- join from contracts to ST1 'TeamRedirects=TRed2', -- join from news to ST2 'SisterTeams=ST1', -- the sister team page (if one exists) of the contract team 'SisterTeams=ST2', -- the sister team page (if one exists) of the news team }	return ret end

function PCT:getJoin local ret = { 'News.NewsId=RC.NewsId', 'News.NewsId=Contracts.NewsId', 'RC.Player=PR1.AllName', 'Contracts.Player=PR2.AllName', -- contracts need to respect contracts from the same org 'Contracts.Team=TRed1.AllName', 'TRed1._pageName=ST1.Team', -- roster changes need to discover the org so we can pull contracts 'RC.Team=TRed2.AllName', 'TRed2._pageName=ST2.Team', }	return ret end

function PCT:getWhere(player) local where = { ('PR1.OverviewPage="%s"'):format(player), ('PR2.OverviewPage="%s"'):format(player), }	return util_cargo.concatWhereOr(where) end

function PCT:getFields local fields = self:super('getFields') fields[#fields+1] = 'Contracts.ContractEnd' fields[#fields+1] = 'COALESCE(ST1._pageName, Contracts.Team, ST2._pageName, RC.Team)=SisterTeamPage' fields[#fields+1] = 'COALESCE(PR1.OverviewPage, PR2.OverviewPage)=PlayerLink' fields[#fields+1] = 'Contracts.IsRemoval=IsContractRemoval' return fields end

function PCT:processOneChangeRow(row) row.Subject = row.Team row.team = row.Team row.role = row.Role if row.IsContractRemoval then self.CONTRACT_DATES[row.SisterTeamPage] = nil end if row.ContractEnd then self.CONTRACT_DATES[row.SisterTeamPage] = row.ContractEnd end end

function PCT:makeOutput(listOfSubjects, listOfChanges) listOfSubjects.last = h.getLastTeamList(listOfChanges) listOfSubjects.contractDates = self.CONTRACT_DATES return listOfSubjects end

function h.getLastTeamList(listOfChanges) return h.getLastTeamInfo(listOfChanges[#listOfChanges]) end

function h.getLastTeamInfo(row) local ret = { team = row.Team, role = row.Role, }	return ret end

return p