Module:Sponsored teams: Difference between revisions

From TwogPedia
No edit summary
No edit summary
Line 12: Line 12:
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 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')
mw.log(currentDate)
local cargoArgs = {
local cargoArgs = {
join = 'Sponsors._pageName = Teams._pageName',
join = 'Sponsors._pageName = Teams._pageName',

Revision as of 11:15, 27 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')
	mw.log(currentDate)
	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