Leaguepedia | League of Legends Esports Wiki
Advertisement
Leaguepedia | League of Legends Esports Wiki

Documentation for this module may be created at Module:MatchInterviewQuery/doc

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 LCS = require('Module:LuaClassSystem')

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

local QB = LCS.class()

function QB:init(interviewTableShort, interviewTableLong)
	self.interviewTableShort = interviewTableShort
	self.interviewTableLong = interviewTableLong
end

function QB:getTables()
	local tables = {
		'MatchSchedule=MS',
		'MatchScheduleGame=MSG',
		('%s__InterviewWith=InterviewWith'):format(self.interviewTableLong),
		'PlayerRedirects=PR',
		'Tournaments=T',
	}
	return tables
end

function QB:getJoin()
	local join = {
		'MS.MatchId=MSG.MatchId',
		('%s._ID=InterviewWith._rowID'):format(self.interviewTableShort),
		'InterviewWith._value=PR.AllName',
		'MS.OverviewPage=T.OverviewPage',
	}
	return join
end

function QB:getFields()
	local fields = {
		'T.Name=Tournament',
		'MS.VodInterview=MSInterview',
		'MSG.VodInterview=MSGInterview',
		'MS.Winner=MSWinner[number]',
		'MS.DateTime_UTC=Date',
		'MS.Team1 [team]',
		'MS.Team2 [team]',
		'MSG.Blue [team]',
		'MSG.Red [team]',
		'MSG.Winner=MSGWinner',
		'CONCAT(COALESCE(MS.VodInterview,"EmptyMSInterview"),"____",COALESCE(MSG.VodInterview,"EmptyMSGInterview"))=UniqueKey'
	}
	return fields
end

function QB:getWhere(player)
	return ('PR.OverviewPage="%s"'):format(player)
end

function QB:getGroupBy()
	return 'MS.VodInterview, MSG.VodInterview, MS.MatchId'
end

function h.makeAndRunQuery(player)
	local builderMS = QB('MS', 'MatchSchedule')
	local builderMSG = QB('MSG', 'MatchScheduleGame')
	local query = {
		union = true,
		{
			tables = builderMS:getTables(),
			join = builderMS:getJoin(),
			where = builderMS:getWhere(player),
			fields = builderMS:getFields(),
			groupBy = builderMSG:getGroupBy(),
		},
		{
			tables = builderMSG:getTables(),
			join = builderMSG:getJoin(),
			where = builderMSG:getWhere(player),
			fields = builderMSG:getFields(),
			groupBy = builderMSG:getGroupBy(),
		},
		sortKey = { 'Date' },
		sortOrder = { false },
		uniqueKey = 'UniqueKey',
	}
	return util_cargo.queryAndCast(query)
end

function h.formatOneRow(row)
	row.Tournament = h.makeTournamentDisplay(row)
	row.TeamDisplay = tostring(util_html.vsAlign(
		h.getTeam1(row):flair{len='short'},
		h.getTeam2(row):flair{len='short'}
		))
	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('wikitable2')
		:addClass('hoverable-rows')
		:addClass('postmatch-interviews')
	util_html.printHeaderFromI18n(tbl, COLUMNS)
	util_html.printRowsByList(tbl, data, COLUMNS)
end

return p
Advertisement