Module:PageIsOrganizing

From TwogPedia
Revision as of 20:19, 26 April 2024 by Couchor (talk | contribs) (Created page with "local cargo = mw.ext.cargo local Flags = require('Module:Flags') local p = {} function p.main(frame) local currentTitle = mw.title.getCurrentTitle().text local empty = true -- Check if there are any interviews for this page local tables = 'Tournaments' local fields = '_pageName, start, end, prize, logoAll, logoLight, logoDark, iconAll, iconLight, iconDark' local currentDate = os.date('%Y-%m-%d') local cargoArgs = { where = 'organizer HOLDS "' .. currentTi...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Documentation for this module may be created at Module:PageIsOrganizing/doc

local cargo = mw.ext.cargo
local Flags = require('Module:Flags')

local p = {}

function p.main(frame)
	local currentTitle = mw.title.getCurrentTitle().text
	local empty = true

	-- Check if there are any interviews for this page
	local tables = 'Tournaments'
	local fields = '_pageName, start, end, prize, logoAll, logoLight, logoDark, iconAll, iconLight, iconDark'
    local currentDate = os.date('%Y-%m-%d')
	local cargoArgs = {
		where = 'organizer HOLDS "' ..  currentTitle .. '"',
		limit=30,
		orderBy = 'start'
	}
	local results = cargo.query(tables, fields, cargoArgs)

    local Table = mw.html.create('table')
			:addClass('striped-table')
	
		local titleRow = mw.html.create('tr')
			:addClass('headerRow')
		local nameCell = mw.html.create('th')
			:wikitext('Name')
		local startCell = mw.html.create('th')
			:wikitext('Start')
        local endCell = mw.html.create('th')
			:wikitext('End')
        local prizeCell = mw.html.create('th')
			:wikitext('Prize')
		Table:node(titleRow:node(nameCell):node(startCell):node(endCell):node(prizeCell))

	local container = mw.html.create()
		:node(mw.html.create('h2'):wikitext('Organized tournaments'))
        :node(Table)

	if #results > 0 then
		empty = false
		
		for r = 1, #results do
			local result = results[r]
            
            local icon = result.iconAll or result.iconDark or result.iconLight or result.logoAll or result.logoDark or result.logoLight or 'Tournament_placeholder.png'
		    local nameTd = mw.html.create('td'):wikitext('[[File:' .. icon .. '|25x25px|link=' .. result._pageName .. ']]'):wikitext('[[' .. result._pageName .. ']]')

		    local startTd = mw.html.create('td'):wikitext(result.start)
             local endTd = mw.html.create('td'):wikitext(result['end'])
             local prizeTd = mw.html.create('td'):wikitext('$' .. result.prize)
            local tournamentRow = mw.html.create('tr'):addClass('bodyRow')
                  :node(nameTd)
                  :node(startTd)
                  :node(endTd)
                  :node(prizeTd)

			
			Table:node(tournamentRow)
		end
		
	end
	
	if empty then
		return '<span class="d-none"></span>'
	else
		return container
	end
	
end

return p