Module:Sponsored teams: Difference between revisions

From TwogPedia
No edit summary
No edit summary
 
(9 intermediate revisions by the same user not shown)
Line 7: Line 7:
:addClass('sponsored')
:addClass('sponsored')
local currentTitle = mw.title.getCurrentTitle().text
local currentTitle = mw.title.getCurrentTitle().text
-- Look up Cargo table teams with current page as sponsor
-- Look up Cargo table teams with current page as sponsor
local tables = 'Sponsors, Teams'
local tables = 'Sponsors'
local fields = 'Sponsors._pageName'
local fields = '_pageName, start, end, startRef, startRefName, endRef, endRefName'
local currentDate = os.date('%Y-%m-%d')


local cargoArgs = {
local cargoArgs = {
join = 'Sponsors._pageName=Teams._pageName, Sponsors._pageName=Teams.org',
where = 'id ="' .. currentTitle .. '" AND type="team" AND (end is NULL OR end > "' .. currentDate .. '")',
where = 'Sponsors.id= "' ..currentTitle .. '" OR Teams.org="' .. currentTitle .. '"',
limit=10,
limit=10,
orderBy='Sponsors.start'
orderBy='start'
}
}
local results = cargo.query(tables, fields, cargoArgs)
local results = cargo.query(tables, fields, cargoArgs)
local list = mw.html.create('table')
:addClass('sortable striped-table')
 
if #results > 0 then
if #results > 0 then
local ul = mw.html.create('ul')
local titleRow = mw.html.create('tr')
:addClass('headerRow')
local nameCell = mw.html.create('th')
:wikitext('Team')
local startCell = mw.html.create('th')
:wikitext('Sponsored since')
local endCell = mw.html.create('th')
:wikitext('Sponsored until')
list:node(titleRow:node(nameCell):node(startCell):node(endCell))
for r = 1, #results do
for r = 1, #results do
mw.log(results[r])
local result = results[r]
mw.logObject(results[r])
        local result = results[r]
        local teamRow = mw.html.create('tr')
        local li = mw.html.create('li')
        :addClass('bodyRow')
        :wikitext('[[' .. result._pageName .. ']]')
        local teamName = mw.html.create('td')
        ul:node(li)
        :addClass('linkID')
       
        tables = 'Logos'
fields = '_pageName, logoLight, logoDark, logoAll, iconLight, iconDark, iconAll'
 
local pageNameSplit = mw.text.split(result._pageName,'/')[2] or ''
 
cargoArgs = {
where = '(_pageName="' ..  result._pageName .. '" OR _pageName ="' .. pageNameSplit.. '" ) AND (start is null or start < "' .. currentDate.. '") AND (end is NULL OR end > "' .. currentDate .. '")'
}
local iconResult = cargo.query(tables, fields, cargoArgs)
 
        if #iconResult > 0 then
        if iconResult[1].iconAll then
        teamName:wikitext('<span class="team-icon">[[File:' .. iconResult[1].iconAll .. '|20px]]</span>')
        else
        if iconResult[1].iconLight and iconResult[1].iconDark then
        teamName:wikitext('<span class="team-icon light">[[File:' .. iconResult[1].iconLight .. '|18px]]</span>')
        teamName:wikitext('<span class="team-icon dark-inline-flex">[[File:' .. iconResult[1].iconDark .. '|18px]]</span>')
        elseif iconResult[1].iconLight or iconResult[1].iconDark then
        local file = iconResult[1].iconLight or iconResult[1].iconDark
        teamName:wikitext('<span class="team-icon">[[File:' .. file .. '|20px]]</span>')
        end
        end
        end
        teamName:wikitext('[[' .. result._pageName .. ']]')
        if result.startRef then
        local startRefName = result.startRefName or ''
        teamName:wikitext(frame:preprocess('<ref name='.. startRefName .. '>' ..result.startRef .. '</ref>'))
        end
       
        local startDate = mw.html.create('td')
        :addClass('tc')
        :wikitext(result.start)
        local endDate = mw.html.create('td')
        :addClass('tc')
        :wikitext(result['end'])
       
        list:node(teamRow:node(teamName):node(startDate):node(endDate))
    end
    end
else  
else  
Line 33: Line 82:
end
end
return container:node(list)
return container:node(ul)
end
end


return Sponsored
return Sponsored

Latest revision as of 23:09, 5 May 2023

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

local cargo = mw.ext.cargo

local Sponsored = {}

function Sponsored.get(frame)
	local container = mw.html.create('div')
		:addClass('sponsored')
	local currentTitle = mw.title.getCurrentTitle().text

	-- Look up Cargo table teams with current page as sponsor
	local tables = 'Sponsors'
		local fields = '_pageName, start, end, startRef, startRefName, endRef, endRefName'
	local currentDate = os.date('%Y-%m-%d')

	local cargoArgs = {
		where = 'id ="' ..  currentTitle .. '" AND type="team" AND (end is NULL OR end > "' .. currentDate .. '")',
		limit=10,
		orderBy='start'
	}
	local results = cargo.query(tables, fields, cargoArgs)
	local list = mw.html.create('table')
		:addClass('sortable striped-table')

	if #results > 0 then
		local titleRow = mw.html.create('tr')
			:addClass('headerRow')
		local nameCell = mw.html.create('th')
			:wikitext('Team')
		local startCell = mw.html.create('th')
			:wikitext('Sponsored since')
		local endCell = mw.html.create('th')
			:wikitext('Sponsored until')
		list:node(titleRow:node(nameCell):node(startCell):node(endCell))
		for r = 1, #results do
			local result = results[r]
			
	        local teamRow = mw.html.create('tr')
	        	:addClass('bodyRow')
	        local teamName = mw.html.create('td')
	        	:addClass('linkID')
	        
	        tables = 'Logos'
			fields = '_pageName, logoLight, logoDark, logoAll, iconLight, iconDark, iconAll'

			local pageNameSplit = mw.text.split(result._pageName,'/')[2] or ''

			cargoArgs = {
				where = '(_pageName="' ..  result._pageName .. '" OR _pageName ="' .. pageNameSplit.. '" ) AND (start is null or start < "' .. currentDate.. '") AND (end is NULL OR end > "' .. currentDate .. '")'
			}
			local iconResult = cargo.query(tables, fields, cargoArgs)

	        if #iconResult > 0 then
	        	if iconResult[1].iconAll then
	        		teamName:wikitext('<span class="team-icon">[[File:' .. iconResult[1].iconAll .. '|20px]]</span>')
	        	else 
	        		if iconResult[1].iconLight and iconResult[1].iconDark then
	        			teamName:wikitext('<span class="team-icon light">[[File:' .. iconResult[1].iconLight .. '|18px]]</span>')
	        			teamName:wikitext('<span class="team-icon dark-inline-flex">[[File:' .. iconResult[1].iconDark .. '|18px]]</span>')
	        		elseif iconResult[1].iconLight or iconResult[1].iconDark then
	        			local file = iconResult[1].iconLight or iconResult[1].iconDark
	        			teamName:wikitext('<span class="team-icon">[[File:' .. file .. '|20px]]</span>')
	        		end
	        	end
	        end
	        teamName:wikitext('[[' .. result._pageName .. ']]')
	        if result.startRef then
	        	local startRefName = result.startRefName or ''
	        	teamName:wikitext(frame:preprocess('<ref name='.. startRefName .. '>' ..result.startRef .. '</ref>'))
	        end
	        
	        local startDate = mw.html.create('td')
	        	:addClass('tc')
	        	:wikitext(result.start)
	        local endDate = mw.html.create('td')
	        	:addClass('tc')
	        	:wikitext(result['end'])
	        
	        list:node(teamRow:node(teamName):node(startDate):node(endDate))
	    end
	else 
		return nil
	end
	
	return container:node(list)
end

return Sponsored