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, Teams'
local tables = 'Sponsors'
local fields = 'Sponsors._pageName=sponsorPage, Teams._pageName=teamPage, Teams.org=org'
local fields = '_pageName, start, end'


local cargoArgs = {
local cargoArgs = {
join = 'Sponsors._pageName=Teams.org',
where = 'Sponsors.id ="' .. currentTitle .. '" AND Sponsors.type="team"',
where = 'Sponsors.id= "' ..currentTitle .. '"',
limit=10,
limit=10,
orderBy='Sponsors.start'
orderBy='Sponsors.start'
}
}
local results = cargo.query(tables, fields, cargoArgs)
local results = cargo.query(tables, fields, cargoArgs)
mw.logObject(results)
local ul = mw.html.create('ul')
local ul = mw.html.create('ul')
if #results > 0 then
if #results > 0 then
for r = 1, #results do
for r = 1, #results do
mw.log(results[r].org == nil and #mw.text.split(results[r].sponsorPage, '/'))
        local li = mw.html.create('li')
if ( results[r].org or ( results[r].org == nil and #mw.text.split(results[r].sponsorPage, '/') ~= 1)) then
        :wikitext('[[' .. results[r]._pageName .. ']]')
mw.log(results[r])
        ul:node(li)
mw.logObject(results[r])
        local result = results[r]
        mw.log(result.sponsorPage)
        mw.log(type(result.sponsorPage))
mw.logObject(result.sponsorPage)
        local li = mw.html.create('li')
        :wikitext('[[' .. result.sponsorPage .. ']]')
        ul:node(li)
        end
    end
    end
else  
else  
return nil
return nil
end
end
mw.log(ul)
mw.logObject(ul)
return container:node(ul)
return container:node(ul)

Revision as of 14:51, 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'

	local cargoArgs = {
		where = 'Sponsors.id ="' ..  currentTitle .. '" AND Sponsors.type="team"',
		limit=10,
		orderBy='Sponsors.start'
	}
	local results = cargo.query(tables, fields, cargoArgs)
	local ul = mw.html.create('ul')
	if #results > 0 then
		for r = 1, #results do
	        local li = mw.html.create('li')
	        	:wikitext('[[' .. results[r]._pageName .. ']]')
	        ul:node(li)
	    end
	else 
		return nil
	end
	
	return container:node(ul)
end

return Sponsored