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

Documentation for this module may be created at Module:UpcomingMatches/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_stats = require("Module:StatsUtil")
local util_table = require("Module:TableUtil")
local util_text = require("Module:TextUtil")
local util_vars = require("Module:VarsUtil")
local i18n = require("Module:I18nUtil")
local lang = mw.getLanguage('en')
local SQA = require('Module:ScheduleQueryAbstract'):extends()
local h = {}
local p = {}
function p.main(frame)
	local args = util_args.merge()
	return SQA(args[1]):run(args)
end

function SQA:init(page)
	self:super('init', page)
	table.insert(self.columns, 1, 'Match')
	table.insert(self.columns, 1, 'Tournament')
	util_table.push(self.columns, 'Stream')
	self.widths.Match = 300
	self.widths.Stream = 125
	self.hideTBD = true
end

function SQA:run(args)
	local data = h.makeAndRunQuery(args)
	return self:makeOutput(data)
end

function h.makeAndRunQuery(args)
	local query = {
		tables = {
			'MatchSchedule=MS',
			'Tournaments=T',
		},
		join = {
			'MS.OverviewPage=T.OverviewPage'
		},
		fields = {
			'MS.Team1 [team]',
			'MS.Team2 [team]',
			'MS.DateTime_UTC=UTC',
			'MS.Stream',
			'MS.DST',
			'MS.HasTime [boolean]',
			'MS.BestOf',
			'MS.MatchId',
			'T.Name=Tournament',
			'T.Region [region]',
			'T.League [league]',
			'T.LeagueIconKey [league]',
		},
		where = h.getWhere(args),
		orderBy = 'MS.DateTime_UTC',
	}
	return util_cargo.queryAndCast(query)
end

function h.getWhere(args)
	local where = {
		args.tag and ('MS.Tags HOLDS "%s"'):format(args.tag),
		'MS.DateTime_UTC >= NOW()',
	}
	return where
end

function SQA:makeOutput(data)
	local output = mw.html.create()
	self:printToggler(output)
	self:printTable(output, data)
	return output
end

function SQA:printTable(output, data)
	local tbl = output:tag('table')
		:addClass('wikitable')
	self:printWidthRow(tbl)
	self:printHeadings(tbl:tag('tr'))
	for _, row in ipairs(data) do
		self:printRow(tbl, row)
	end
end

function SQA:printRow(tbl, row)
	if not row.UTC then return end
	local tr = tbl:tag('tr')
	tr:tag('td'):wikitext(h.getTournament(row))
	local td = self:printMatch(tr, row)
	td:addClass('upcoming-matches-match')
	self:printDateAndTime(tr, row)
	tr:tag('td'):wikitext(util_text.extLink(row.Stream))
end

function h.getTournament(row)
	local tbl = {}
	tbl[#tbl+1] = row.Region:image()
	tbl[#tbl+1] = row.LeagueIconKey:image() or row.League:image()
	tbl[#tbl+1] = util_text.intLinkOrText(row.Tournament)
	return table.concat(tbl, ' ')
end

return p
Advertisement