Module:TopSchedule

local m_team = require('Module:Team') local util_cargo = require('Module:CargoUtil') local util_time = require('Module:TimeUtil') local util_html = require('Module:HTMLUtil') local util_form = require('Module:FormUtil')

local h = {}

function h.makeQuery(where) return { tables = 'GameSchedule', fields = table.concat({			'Team1',			'Team2',			'DateTime',			'Tournament',			'TimeEntered',			'_pageName',			'ShownName',			'Round',			'Stream'		},','), groupBy = 'UniqueLine', orderBy = 'DateTime ASC', where = 'DateTime > NOW - INTERVAL 3 HOUR', limit = 50, types = { TimeEntered = 'boolean' }	} end

function h.formatResults(result) for i, row in ipairs(result) do		if not (row.Team1 or row.Team2) then row.Matchup = row.Round else Team1Formatted = row.Team1 ~= 'TBD' and m_team.onlyimagelinked(row.Team1, { size = 45 }) or 'TBD' Team2Formatted = row.Team2 ~= 'TBD' and m_team.onlyimagelinked(row.Team2, { size = 45 }) or 'TBD' row.Matchup = string.format('%s vs %s',				Team1Formatted,				Team2Formatted			) end row.EventLinked = string.format('%s', row._pageName or , row.ShownName or row._pageName or ) countdown = util_time.countdown(row.DateTime, {			data_end = 'toggle',			i = 'ts-' .. i,			default = 'LIVE'		}) row.Countdown = row.Stream and string.format('[%s %s]', row.Stream, countdown) or countdown row.Calendar = string.format(			'', 			util_form.fullURL('SpoilerFreeSchedule','SFS', {row.OverviewPage})		) end end

function h.printContent(result, div) for i, row in ipairs(result) do		local tbl = div:tag('div') :addClass('topschedule-box') :attr('data-expiration',tonumber(util_time.unix(row.DateTime)+3600)) :attr('data-i',i) tbl:tag('div'):addClass('topschedule-header'):wikitext(row.EventLinked):done :tag('div'):addClass('topschedule-vs') :tag('div'):addClass('topschedule-content'):wikitext(row.Matchup):done :done tbl:tag('div'):addClass('topschedule-time hlist') :tag('li'):addClass('plainlinks'):wikitext(row.Countdown):done :tag('li'):wikitext(row.Calendar):done :done end end

local p = {} function p.main(frame) if frame == mw.getCurrentFrame then args = require('Module:ProcessArgs').merge(true) else frame = mw.getCurrentFrame end local query = h.makeQuery local result = util_cargo.queryAndCast(query) if not next(result) then return '' end h.formatResults(result) local div = mw.html.create('div'):addClass('topschedule') h.printContent(result, div) return div end

return p