Module:Sponsored teams: Difference between revisions

From TwogPedia
No edit summary
No edit summary
Line 9: Line 9:


-- Look up Cargo table teams with current page as sponsor
-- Look up Cargo table teams with current page as sponsor
local tables = 'Sponsors'
local tables = 'Sponsors, Teams'
local fields = '_pageName, start, end, startRef, startRefName, endRef, endRefName'
local fields = 'Sponsors._pageName=_pageName, Sponsors.start=start, Sponsors.end=end, Sponsors.startRef=startRef, Sponsors.startRefName=startRefName, Sponsors.endRef=endRef, Sponsors.endRefName=endRefName, Teams.image=icon'
 
local currentDate = os.date('%Y-%m-%d'), os.time()
local currentDate = os.date('%Y-%m-%d'), os.time()
local cargoArgs = {
local cargoArgs = {
join = 'Sponsors._pageName = Teams._pageName',
where = 'id ="' ..  currentTitle .. '" AND type="team" AND (end is NULL OR end < ' .. currentDate .. ')',
where = 'id ="' ..  currentTitle .. '" AND type="team" AND (end is NULL OR end < ' .. currentDate .. ')',
limit=10,
limit=10,
Line 18: Line 20:
}
}
local results = cargo.query(tables, fields, cargoArgs)
local results = cargo.query(tables, fields, cargoArgs)
local ul = mw.html.create('ul')
local list = mw.html.create('table')
:addClass('sortable striped-table')
if #results > 0 then
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
for r = 1, #results do
local result = results[r]
local result = results[r]
        local li = mw.html.create('li')
        :wikitext('[[' .. result._pageName .. ']]')
        local teamRow = mw.html.create('tr')
        :addClass('bodyRow')
        local teamName = mw.html.create('td')
        :addClass('linkID')
        if result.icon then
        teamName:wikitext('<span class="icon">[[File:' .. result.icon .. '|18px]]</span>')
        end
        teamName:wikitext('[[' .. result._pageName .. ']]')
        if result.startRef then
        if result.startRef then
        local startRefName = result.startRefName or ''
        local startRefName = result.startRefName or ''
        li:wikitext(frame:preprocess('<ref name='.. startRefName .. '>' ..result.startRef .. '</ref>'))
        teamName:wikitext(frame:preprocess('<ref name='.. startRefName .. '>' ..result.startRef .. '</ref>'))
        end
        end
         
         
        ul:node(li)
        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 35: Line 62:
end
end
return container:node(ul)
return container:node(list)
end
end


return Sponsored
return Sponsored

Revision as of 22:58, 26 September 2022

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, Teams'
	local fields = 'Sponsors._pageName=_pageName, Sponsors.start=start, Sponsors.end=end, Sponsors.startRef=startRef, Sponsors.startRefName=startRefName, Sponsors.endRef=endRef, Sponsors.endRefName=endRefName, Teams.image=icon'

	local currentDate = os.date('%Y-%m-%d'), os.time()
	local cargoArgs = {
		join = 'Sponsors._pageName = Teams._pageName',
		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')
	        if result.icon then
	        	teamName:wikitext('<span class="icon">[[File:' .. result.icon .. '|18px]]</span>')
	        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