Module:ScheduleNavbox

local m_team = require('Module:Team')

local p = {} function p.main(frame) -- from args, to be used as a stand-alone navbox if frame == mw.getCurrentFrame then args = require('Module:ProcessArgs').merge(true) else frame = mw.getCurrentFrame end 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 = mw.ext.cargo.query(query.tables, query.fields, query) if not next(results) 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 = 'GameSchedule', fields = table.concat({			'Team1',			'Team2',			'DateTime',			'Tournament',			'TimeEntered',			'_pageName',			'ShownName'		},','), groupBy = 'UniqueLine', orderBy = 'DateTime 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 = string.format('%s', row._pageName, 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