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

To edit the documentation or categories for this module, click here.


local util_args = require('Module:ArgsUtil')
local util_cargo = require('Module:CargoUtil')
local util_esports = require('Module:EsportsUtil')
local util_form = require('Module:FormUtil')
local util_html = require('Module:HtmlUtil')
local util_table = require("Module:TableUtil")
local util_text = require('Module:TextUtil')
local util_time = require('Module:TimeUtil')
local util_toggle = require('Module:ToggleUtil')
local util_vars = require('Module:VarsUtil')
local i18n = require('Module:i18nUtil')
local PHASE_SETTINGS = {
	{ 
		toggle = 'UpcomingNo',
		hidden = '_tog_object _toggle_inithide',
		when = '<',
		title = '[Show/Hide] Completed Matches'
	},
	{
		toggle = 'UpcomingYes',
		hidden = '',
		when = '>',
		title = '[Show/Hide] Upcoming Matches'
	}
}

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, 'Round')
	util_table.push(self.columns, 'VodsStream')
	self.widths.Round = 75
	self.widths.Match = 300
	self.widths.VodsStream = 125
	self.hideTBD = false
end

function SQA:run(args)
	local output = mw.html.create()
	self:printOutputInitialText(output)
	
	local tbl = output:tag('table'):addClass('wikitable'):css('text-align','center')
		
	for _, phase in ipairs(PHASE_SETTINGS) do
		self:printPhaseStart(tbl, phase)
		
		local result = util_cargo.queryAndCast(self:makeQuery(phase.when))
				
		for _, row in ipairs(result) do
			local tr = tbl:tag('tr'):addClass('_tog_object _toggle ' .. phase.toggle):addClass(phase.hidden)
			tr:tag('td'):wikitext(row.Tab or row.Round or ''):done()
			self:printMatch(tr, row)
			self:printDateAndTime(tr, row)
			h.printVodsOrStream(tr, row)
		end
	end
	return output
end

function SQA:printOutputInitialText(output)
	output:wikitext(('[[%s|Click here]] to view tournament page.'):format(self.page))
	util_html.clear(output)
	self:printCalendarExportFormLink(output)
	util_html.clear(output)
	self:printToggler(output)
end

function SQA:printCalendarExportFormLink(output)
	local url = util_form.fullURL({ template = 'MCE', form = 'MatchCalendarExport' }, { self.page })
	output:wikitext(util_text.extLink(url, 'Click here'), ' to create a CSV export of this event to your calendar.')
end

function SQA:printPhaseStart(tbl, phase)
	tbl:tag('tr')
		:tag('th')
		:attr('colspan',#self.columns)
		:addClass('_tog_object _toggler-' .. phase.toggle)
		:wikitext(phase.title)
	self:printWidthRow(tbl)
	local tr = tbl:tag('tr'):addClass('_tog_object _toggle ' .. phase.toggle):addClass(phase.hidden)
	self:printHeadings(tr)
end

function SQA:makeQuery(when)
	return {
		tables = { 'MatchSchedule=MS', 'MatchScheduleGame=MSG' },
		join = { 'MS.MatchId=MSG.MatchId' },
		fields = {
			'MS.Team1 [team]',
			'MS.Team2 [team]',
			'MS.Tab',
			'MS.Round',
			'MS.DateTime_UTC=UTC',
			'MS.Stream',
			'MS.DST',
			'MS.HasTime [boolean]',
			'MS.BestOf',
			'MS.MatchId', -- needed as the groupBy for the oneToMany
		},
		where = ('MS.OverviewPage="%s" AND MS.DateTime_UTC %s NOW()'):format(self.page, when),
		groupBy = 'MS.MatchId',
		orderBy = 'MS.DateTime_UTC',
		oneToMany = {
			groupBy = { 'MatchId' },
			fields = { VODs = 'COALESCE(MSG.VodPB,MSG.VodGameStart,MSG.Vod)=VOD', },
		},
	}
end

function h.printVodsOrStream(tr, row)
	if not row.Stream and not next(row.VODs) then
		tr:tag('td'):wikitext('Stream')
		return
	elseif h.hasNoVods(row.VODs) then
		local td = tr:tag('td')
		if row.Stream then
			td:wikitext(string.format('[%s Stream]', row.Stream))
		end
		return
	end
	tr:tag('td')
		:addClass('spoiler-free-vods')
		:wikitext(h.getVodsPadded(row.VODs, row.BestOf))
end

function h.hasNoVods(VODs)
	for _, row in ipairs(VODs) do
		if row.VOD then return false end
	end
	return true
end

function h.getVodsPadded(vods, bestOf)
	local links = {}
	for i = 1, bestOf do
		links[i] = util_text.ambiguousLink(vods[i] and vods[i].VOD or 'Main Page', i)
	end
	return util_table.concat(links, '')
end

return p
Advertisement