Module:Team
From eSportsAmaze
More actions
Documentation for this module may be created at Module:Team/doc
-- MAIN 3: Active Roster Table
function p.activeRoster(frame)
local args = frame:getParent().args
local team = args.team or mw.title.getCurrentTitle().text
-- Query the Players table
local tables = "Players"
local fields = "id, real_name, role, nationality, image"
local queryArgs = {
where = "current_team = '" .. team .. "'",
orderBy = "role ASC, id ASC"
}
local results = cargo.query(tables, fields, queryArgs)
local root = html.create('table')
root:addClass('wikitable flat-table sortable')
:css('width', '100%')
:css('text-align', 'center')
:css('margin-top', '0px')
-- Table Header
local header = root:tag('tr')
header:tag('th'):wikitext('ID')
header:tag('th'):wikitext('Name')
header:tag('th'):wikitext('Role')
header:tag('th'):wikitext('Nationality')
if #results > 0 then
for _, row in ipairs(results) do
local tr = root:tag('tr')
-- Cell 1: ID with Image
local idCell = tr:tag('td')
:css('text-align', 'left')
:css('font-weight', 'bold')
if row.image and row.image ~= "" then
idCell:wikitext('[[File:' .. row.image .. '|30px|link=' .. row.id .. ']] ')
end
idCell:wikitext('[[' .. row.id .. ']]')
-- Cell 2: Real Name
tr:tag('td'):wikitext(row.real_name)
-- Cell 3: Role
tr:tag('td'):wikitext(row.role)
-- Cell 4: Nationality
tr:tag('td'):wikitext(row.nationality)
end
else
local tr = root:tag('tr')
tr:tag('td'):attr('colspan', '4'):wikitext('No players currently listed for this team.')
end
return tostring(root)
end