Module:TopSchedulePage

local Team = require('Module:Team').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 p = {} function p.main(frame) if frame == mw.getCurrentFrame then args = require('Module:ProcessArgs').merge(true) else frame = mw.getCurrentFrame end local query = p.makeQuery local result = util_cargo.queryAndCast(query) if not next(result) then return '' end p.formatResults(result) return p.formatSchedule(result, frame) end

function p.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 p.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 Team{ row.Team1, 'htmlimglinked', size = 45 } or 'TBD' Team2Formatted = row.Team2 ~= 'TBD' and Team{ row.Team2, 'htmlimglinked', size = 45 } or 'TBD' row.Matchup = string.format('%s vs %s',				Team1Formatted,				Team2Formatted			) end row.EventLinked = string.format('%s', mw.site.server, row._pageName, row.ShownName) countdown = util_time.countdown(row.DateTime, { data_end = 'toggle', i = i, default = 'LIVE' }) row.Countdown = row.Stream and string.format('%s', row.Stream, countdown) or countdown row.Calendar = string.format(			'', 			util_form.makeBaseQueryURLFromArgs('SpoilerFreeSchedule','SFS', { row._pageName }, 'full')		) end end

function p.formatSchedule(result, frame) local res = '' for i, row in ipairs(result) do		local tbl = mw.html.create tbl:tag('div'):addClass('topschedule-box') :tag('div'):addClass('topschedule-header'):wikitext(row.EventLinked):done :tag('div'):addClass('topschedule-vs') :tag('div'):addClass('topschedule-content'):wikitext(row.Matchup):done :done :tag('div'):addClass('topschedule-time hlist') :tag('li'):wikitext(row.Countdown):done :tag('li'):wikitext(row.Calendar):done :done res = res .. tostring(tbl) end return res end

return p