Module:PlayerTeamHistoryEmbeddedAbstract

-- Subclasses PTH Abstract -- Is subclassed by regular & compact views + stores

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_math = require("Module:MathUtil") local util_news = require("Module:NewsUtil") local util_source = require("Module:SourceUtil") local util_table = require("Module:TableUtil") local util_text = require("Module:TextUtil") local util_time = require("Module:TimeUtil") local util_timedelta = require("Module:TimedeltaUtil") local util_vars = require("Module:VarsUtil") local i18n = require('Module:i18nUtil') local lang = mw.getLanguage('en')

local m_team = require('Module:Team')

local PTH = require('Module:PlayerTeamHistoryAbstract'):extends

local h = {}

function PTH:init(name) self:super('init', name) self.COLUMNS = { 'RegionDisplay', 'TeamDisplay', 'RoleDisplay', 'DateJoinDisplay', 'DateLeaveDisplay', 'DurationDisplay', classes = { RoleDisplay = 'player-team-history-role', },		colclasses = { RoleDisplay = 'unsortable', RegionDisplay = 'unsortable', StatusDisplay = 'unsortable', },		sorttypes = { DateJoinDisplay = 'number', DateLeaveDisplay = 'number', DurationDisplay = 'number' } } end

function PTH:getStatusAndUpdateFlag(row) if row.StatusJoin then self.INCLUDE_STATUS = true end -- originally this printed Status but actually we should be printing the StatusJoin -- or well i think so...... row.StatusDisplay = i18n.print(row.StatusJoin) end

-- cargo STORE function PTH:storeCargo(changesByLine) util_map.selfRowsInPlace(		self,		changesByLine,		PTH.processAndStoreCargoRow,		changesByLine	) end

function PTH:processAndStoreCargoRow(row, changesByLine) local cargoRow = self:getCargoVariables(row, changesByLine) util_cargo.store(cargoRow) end

function PTH:getCargoVariables(row, changesByLine) -- these aren't exhaustively every interesting variable -- this table should be joined to RosterChanges twice -- once as RCJoin (on RosterChangeIdJoin) -- and once as RCLeave (on RosterChangeIdLeave) local cargoVariables = { _table = self.CargoStoreTableName, Player = row.Player, Team = row.Team, DateJoin = row.DateJoin, DateLeave = row.DateLeave, Duration = self:getDurationInDays(row), RosterChangeIdJoin = row.RosterChangeIdJoin, RosterChangeIdLeave = row.RosterChangeIdLeave, RosterChangeIds = util_table.concat(row.RosterChangeIds, ','), ResidencyLeave = row.ResidencyOld or util_vars.getVar('residency'), NameLeave = h.getCurrentName(row), NextTeam = h.getNextTeamValue(row, changesByLine), IsCurrent = not row.TeamLeave, ContractEnd = row.ContractEnd, }	cargoVariables.NextIsRetired = h.getNextIsRetiredValue(row, cargoVariables) return cargoVariables end

function PTH:getDurationInDays(row) if not row.DateJoin or not row.DateLeave then return nil end if row.IsApproxDateJoin or row.IsApproxDateLeave then return nil end return tonumber(util_timedelta.approxDurationDays(self:getDurationArgs(row))) end

function h.getCurrentName(row) -- PlayerLeave is correct; this is the Leaving name param -- Even though the PlayerRename table is queried in PTHAbstract, that's used -- to create the current_id variable when a player is actively on a team only. -- otherwise we just use use PlayerLeave and don't care. -- So actually I don't think we need the join here period.... return row.PlayerLeave or util_vars.getVar('current_id') end

function h.getNextTeamValue(row, changesByLine) if row.NextTeam then return row.NextTeam end if not row.TeamLeave then return nil end if row.index == #changesByLine then return end return changesByLine[row.index +1].Team end

function h.getNextIsRetiredValue(row, cargoVariables) if not row.TeamLeave then return nil end if cargoVariables.NextTeam then return false end return util_vars.getBool('isretired') end

-- display function PTH:getTeamDisplay(row) return row.TeamJoin and m_team.rightmediumlinked(row.TeamLeave or row.TeamJoin) end

function PTH:getDateDisplay(row, when) return util_news.getDateAndRefDisplayForTable(row, when) end

function PTH:printEditButtons(td, row) local div = td:tag('div') :addClass('player-team-history-edit') h.printOneEditButton(div, row._pageNameJoin, 'ej') h.printOneEditButton(div, row._pageNameLeave, 'el') end

function h.printOneEditButton(div, link, text) if not link then return end div:tag('span') :addClass('player-team-history-edit-' .. text) :addClass('logged-in-link') :wikitext(text) :attr('data-href', link) end

return PTH