Apex Legends Esports Wiki

READ MORE

Apex Legends Esports Wiki
Advertisement
To edit the documentation or categories for this module, click here.
-- CurrentLeagueParticipantNavbox
local m_team = require('Module:Team')
local util_navbox = require('Module:NavboxUtil')
local util_cargo = require('Module:CargoUtil')

local h = {}

function h.getThisTeam(args, title)
	if args[1] then
		return m_team.teamlinkname(args[1])
	elseif tabstype == 'Team' then
		return m_team.teamlinkname(title.baseText)
	else
		return nil
	end
end

function h.makeQuery(team)
	return {
		tables = "CurrentLeagues, TournamentRosters",
		fields = table.concat({
			"CONCAT(CurrentLeagues.Page)=Page",
			"CurrentLeagues.Event=Event",
		},','),
		where = string.format(
			'TournamentRosters.TeamLink="%s" AND CurrentLeagues.Page IS NOT NULL',
			team
		),
		groupBy = "CurrentLeagues.Page",
		join = "TournamentRosters._pageName = CurrentLeagues.Page",
		orderBy = 'CurrentLeagues.Priority ASC'
	}
end

function h.processData(result, suffix, navbox_args)
	for i, row in ipairs(result) do
		local teamsresult = h.getTeamsFromPage(row.Page)
		local teams = h.formatTeams(teamsresult, suffix)
		navbox_args['group' .. i] = "[[" .. row.Page .. "|" .. row.Event .. "]] Participants"
		navbox_args['list' .. i] = table.concat(teams, " ")
		navbox_args[('tr%sclass'):format(i)] = 'clpn-teamlist-row'
	end
	return
end

function h.getTeamsFromPage(page)
	return mw.ext.cargo.query("TournamentRosters","TeamLink", {
			where = '_pageName = "' .. page .. '"',
			groupBy = "TeamLink"
		})
end

function h.formatTeams(result, suffix)
	local tbl = {}
	for k, v in ipairs(result) do
		tbl[#tbl+1] = h.formatTeam(v.TeamLink, suffix)
	end
	return tbl
end

function h.formatTeam(team, suffix)
	if util_navbox.doesSuffixExist(team, suffix) then
		return m_team.rightmediumlinked(team, { suffix = suffix })
	else
		return string.format(
			'<span class="no-subpage">%s</span>',
			m_team.rightmediumlinked(team)
		)
	end
end

local p = {}

function p.CLPNavbox(frame)
	local args = frame
	if frame == mw.getCurrentFrame() then
		args = require( 'Module:ProcessArgs' ).merge( true )
	else
		frame = mw.getCurrentFrame()
	end
	
	local thisteam = h.getThisTeam(args, title)
	
	local title = mw.title.getCurrentTitle()
	local thisteam = h.getThisTeam(args, title)
	if not thisteam then
		return
	end
	local suffix = (args.suffix == 'Yes') and util_navbox.getSuffix(args, title)
	local result = util_cargo.queryAndCast(h.makeQuery(thisteam))
	if not next(result) then
		return ''
	end
	frame:callParserFunction('#vardefine','navbox','true')
	local navbox_args = {
		title = ('Current Events & Schedule - %s'):format(m_team.mediumplainlinked(thisteam)),
		state = 'mw-collapsible',
		name = 'CurrentLeagueParticipantNavbox'
	}
	h.processData(result, suffix, navbox_args)
	return frame:expandTemplate{
		title = 'navbox',
		args = navbox_args
	}
	
end

return p
Advertisement