Module:GameLanding/Featured tournament

From TwogPedia
< Module:GameLanding
Revision as of 11:30, 29 September 2023 by Couchor (talk | contribs) (Created page with "local cargo = mw.ext.cargo local p = {} local prizeToString = require('Module:Functions').prizeToString function p.featured(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="1" AND _pageName LIKE "' .. game .. '/%"', limit = 1 -- where = 'featured="Yes" AND _pageName LIKE "' .. args.gam...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Documentation for this module may be created at Module:GameLanding/Featured tournament/doc

local cargo = mw.ext.cargo
local p = {}
local prizeToString = require('Module:Functions').prizeToString

function p.featured(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="1" AND _pageName LIKE "' .. game .. '/%"',
		limit = 1
		-- where = 'featured="Yes" AND _pageName LIKE "' .. args.game .. '/%" AND (start is NULL OR start < "' .. currentDate .. '") AND (end is NULL OR end > "' .. currentDate .. '")'
	}
	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 featuredTournament = mw.html.create('div'):addClass('box__container'):node(mw.html.create('div'):addClass('box__title'):wikitext('Featured tournament'))
		local result = results[1]

		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

		featuredTournament:node(mw.html.create('div'):addClass('tc'):wikitext('[[File:' .. icon .. '|200px]]'))
		featuredTournament:node(mw.html.create('div'):addClass('tc'):wikitext('[[' .. result._pageName .. ']]'))
		
		local info = mw.html.create('div'):addClass('featured__info')
		local date = mw.html.create('div')
		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:node(mw.html.create('div'):addClass('fw-600'):wikitext('Date')):node(mw.html.create('div'):wikitext(startDate .. ' - ' .. endDate))
		
		local prize = mw.html.create('div')
		prize:node(mw.html.create('div'):addClass('fw-600'):wikitext('Prize')):node(mw.html.create('div'):wikitext('$' .. prizeToString(result.prize)))
		
		featuredTournament:node(info:node(date):node(prize))
		
		return featuredTournament
	end
	return nil
end

return p