Module:MatchInterviewQuery

local util_args = require('Module:ArgsUtil') local util_cargo = require("Module:CargoUtil") local util_html = require("Module:HtmlUtil") local util_map = require('Module:MapUtil') local util_table = require("Module:TableUtil") local util_text = require("Module:TextUtil") local util_time = require("Module:TimeUtil") local util_vars = require("Module:VarsUtil") local i18n = require("Module:I18nUtil") local lang = mw.getLanguage('en') local m_team = require('Module:Team')

local COLUMNS = { 'Date', 'Tournament', 'TeamDisplay', 'Link', classes = { TeamDisplay = 'postmatch-interviews-teams' } }

local h = {} local p = {} function p.main(frame) i18n.init('MatchInterviewQuery') local args = util_args.merge local player = args[1] or mw.title.getCurrentTitle.text local data = h.makeAndRunQuery(player) if #data == 0 then return '' end util_map.rowsInPlace(data, h.formatOneRow) return h.makeOutput(data) end

function h.makeAndRunQuery(player) local query = { tables = { 'MatchSchedule=MS', 'MatchSchedule__InterviewWith=MSInt', 'PlayerRedirects=PRMS', 'MatchScheduleGame=MSG', 'MatchScheduleGame__InterviewWith=MSGInt', 'PlayerRedirects=PRMSG', 'Tournaments=T', },		join = { 'MS._ID=MSInt._rowID', 'MSInt._value=PRMS.AllName', 'MS.UniqueMatch=MSG.UniqueMatch', 'MSG._ID=MSGInt._rowID', 'MSGInt._value=PRMSG.AllName', 'MS.OverviewPage=T.OverviewPage', },		fields = { 'T.Name=Tournament', 'MS.VodInterview=MSInterview', 'MSG.VodInterview=MSGInterview', 'MS.Winner=MSWinner[number]', 'MS.DateTime_UTC=Date', 'MS.Team1', 'MS.Team2', 'MSG.Blue', 'MSG.Red', 'MSG.Winner=MSGWinner', },		where = { ('PRMS.OverviewPage="%s" OR PRMSG.OverviewPage="%s"'):format(player, player) },		orderBy = 'MS.DateTime_UTC DESC', groupBy = 'MSInterview,MSGInterview', }	util_cargo.logQuery(query) return util_cargo.queryAndCast(query) end

function h.formatOneRow(row) row.Tournament = h.makeTournamentDisplay(row) row.TeamDisplay = tostring(util_html.vsAlign( m_team.leftshort(h.getTeam1(row)), m_team.rightshort(h.getTeam2(row)) ))	row.Link = util_text.extLink(row.MSInterview or row.MSGInterview) row.Date = util_time.strToDateStr(row.Date) end

function h.makeTournamentDisplay(row) local tbl = { util_text.intLinkOrText(row.Tournament), row.Tab }	return table.concat(tbl, ' - ') end

function h.getTeam1(row) if row.MSInterview then return row['Team1'] end return row.Blue end

function h.getTeam2(row) if row.MSInterview then return row['Team2'] end return row.Red end

function h.makeOutput(data) local output = mw.html.create output:tag('h3') :wikitext(i18n.default('heading')) h.printTable(output, data) return output end

function h.printTable(output, data) local tbl = output:tag('table') :addClass('wikitable') :addClass('postmatch-interviews') util_html.printHeaderFromI18n(tbl, COLUMNS) util_html.printRowsByList(tbl, data, COLUMNS) end

return p