Documentation for this module may be created at Module:GameLanding/Tournaments/doc
local cargo = mw.ext.cargo
local p = {}
local prizeToString = require('Module:Functions').prizeToString
function p.tournaments(game)
local tables = 'Tournaments'
local fields = '_pageName, start, end, prize, logoAll, logoLight, logoDark, iconAll, iconLight, iconDark, venue'
local currentDate = os.date('%Y-%m-%d')
local cargoArgs = {
where = 'featured IS NULL AND _pageName LIKE "' .. game .. '/%" AND ( (start is NULL OR start < "' .. currentDate .. '") AND (end is NULL OR end > "' .. currentDate .. '") OR start > ' .. currentDate .. ' )',
limit = 10
}
local results = cargo.query(tables, fields, cargoArgs)
if #results > 0 then
local monthNames = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}
local headerRow = mw.html.create('div'):addClass('tournament__header tournament__row'):node(mw.html.create('div'):wikitext('Date')):node(mw.html.create('div'):wikitext('Prize')):node(mw.html.create('div'):wikitext('Name'))
local tournaments = mw.html.create('div'):addClass('tournament__container'):node(headerRow)
local tournamentContainer = mw.html.create('div'):addClass('box__container'):node(mw.html.create('div'):addClass('box__title'):wikitext('Tournaments')):node(tournaments)
for i = 1, #results do
local result = results[i]
local tournamentRow = mw.html.create('div'):addClass('tournament__row')
local currentTime = os.time()
local startTime = nil
if result.start then
startTime = mw.ustring.gsub(result.start, '(%d+)-(%d+)-(%d+)', function(year, month, day)
return os.time({year=tonumber(year), month=tonumber(month), day=tonumber(day)})
end)
end
local endTime = nil
if result['end'] then
endTime = mw.ustring.gsub(result['end'], '(%d+)-(%d+)-(%d+)', function(year, month, day)
return os.time({year=tonumber(year), month=tonumber(month), day=tonumber(day)})
end)
end
local date = mw.html.create('div')
-- If live
if (startTime ~= nil and os.difftime(currentTime, startTime) > 0) and (endTime == nil or os.difftime(currentTime, endTime) <= 0) then
date:wikitext('LIVE')
else
local startDate = 'TBD'
if result.start then
local year, month, day = result.start:match("(%d+)-(%d+)-(%d+)")
local monthName = monthNames[tonumber(month)]
startDate = monthName .. " " .. day .. ", " .. year
end
local endDate = 'TBD'
if result['end'] then
year, month, day = result['end']:match("(%d+)-(%d+)-(%d+)")
monthName = monthNames[tonumber(month)]
endDate = monthName .. " " .. day .. ", " .. year
end
date:wikitext(startDate .. ' - ' .. endDate)
end
local prize = mw.html.create('div'):wikitext('$' .. prizeToString(result.prize))
local icon = result.iconAll ~= '' and result.iconAll or result.iconLight ~= '' and result.iconLight or result.iconDark ~= '' and result.iconDark or result.logoAll ~= '' and result.logoAll or result.logoDark ~= '' and result.logoDark or result.logoLight ~= '' and result.logoLight
if not icon then icon = 'Tournament_placeholder.png' end
local name = mw.html.create('div'):addClass('tournament__name'):node(mw.html.create('div'):wikitext('[[File:' .. icon .. '|25px]]')):node(mw.html.create('div'):wikitext('[[' .. result._pageName .. ']]'))
-- featuredTournament:node(mw.html.create('div'):addClass('tc'):wikitext('[[File:' .. icon .. '|200px]]'))
-- featuredTournament:node(mw.html.create('div'):addClass('tc'):wikitext('[[' .. result._pageName .. ']]'))
tournaments:node(tournamentRow:node(date):node(prize):node(name))
end
return tournamentContainer
end
return nil
end
return p