Module:ScheduleNavbox

local util_args = require('Module:ArgsUtil') local util_cargo = require('Module:CargoUtil') local util_text = require("Module:TextUtil") local m_team = require('Module:Team')

local p = {} function p.main(frame) local frame = util_args.merge local navboxArgs = p.navboxArgs local exists = p.addToArgs(navboxArgs, args.navboxtype, args[1]) if not exists then return '' else return frame:expandTemplate{ title = 'Navbox', args = navboxArgs } end end

function p.addToArgs(navboxArgs, navtype, subarg, n)	-- use just this if adding to another navbox local helper local subject if navtype == 'Team' then helper = require('Module:ScheduleNavboxTeamHelper') subject = m_team.teamlinkname(subarg or mw.title.getCurrentTitle.baseText) elseif navtype == 'Tournament' then helper = require('Module:ScheduleNavboxTournamentHelper') subject = mw.title.makeTitle('',subarg).redirectTarget or subarg else error('Invalid navbox type') end local query = p.makeQuery query.where = helper.where(subject) local results = util_cargo.queryAndCast(query, true) if #results == 0 then return false end p.formatResults(results) local makeNavbox = helper.makeNavboxArgs(navboxArgs, results, subject, n or 0) return true end

function p.makeQuery return { tables = 'MatchSchedule', fields = { 'Team1', 'Team2', 'DateTime_UTC=DateTime', 'OverviewPage=Tournament', 'HasTime=TimeEntered', 'ShownName' },		groupBy = 'UniqueMatch', orderBy = 'DateTime_UTC ASC' } end

function p.formatResults(results) for i, row in ipairs(results) do		row.Team1Formatted = m_team.onlyimagelinked(row.Team1, {size=45}) row.Team2Formatted = m_team.onlyimagelinked(row.Team2, {size=45}) row.EventLinked = util_text.intLink(row.Tournament, row.ShownName) end end

function p.navboxArgs return { name = 'ScheduleNavbox', title = 'Upcoming Matches', state = 'mw-collapsible', id = 'schedule-navbox', liststyle ='white-space:nowrap;', bodyclass = 'upcoming-matches' } end

return p