Module:Sponsored teams: Difference between revisions

From TwogPedia
No edit summary
No edit summary
Line 10: Line 10:
-- 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'
local fields = '_pageName, start, end'
local fields = '_pageName, start, end, startRef, startRefName, endRef, endRefName'
 
local currentDate = os.date('%Y-%m-%d'), os.time()
local cargoArgs = {
local cargoArgs = {
where = 'Sponsors.id ="' ..  currentTitle .. '" AND Sponsors.type="team"',
where = 'id ="' ..  currentTitle .. '" AND type="team" AND (end is NULL OR end < ' .. currentDate .. ')',
limit=10,
limit=10,
orderBy='Sponsors.start'
orderBy='start'
}
}
local results = cargo.query(tables, fields, cargoArgs)
local results = cargo.query(tables, fields, cargoArgs)
Line 21: Line 21:
if #results > 0 then
if #results > 0 then
for r = 1, #results do
for r = 1, #results do
local result = results[r]
        local li = mw.html.create('li')
        local li = mw.html.create('li')
        :wikitext('[[' .. results[r]._pageName .. ']]')
        :wikitext('[[' .. result._pageName .. ']]')
        if result.startRef then
        local startRefName = result.startRefName or ''
        li:wikitext(frame:preprocess('<ref name='.. startRefName .. '>' ..result.startRef .. '</ref>'))
        end
       
        ul:node(li)
        ul:node(li)
    end
    end

Revision as of 18:19, 23 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'
	local fields = '_pageName, start, end, startRef, startRefName, endRef, endRefName'
	local currentDate = os.date('%Y-%m-%d'), os.time()
	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 ul = mw.html.create('ul')
	if #results > 0 then
		for r = 1, #results do
			local result = results[r]
	        local li = mw.html.create('li')
	        	:wikitext('[[' .. result._pageName .. ']]')
	        if result.startRef then
	        	local startRefName = result.startRefName or ''
	        	li:wikitext(frame:preprocess('<ref name='.. startRefName .. '>' ..result.startRef .. '</ref>'))
	        end
	        
	        ul:node(li)
	    end
	else 
		return nil
	end
	
	return container:node(ul)
end

return Sponsored