Module:Sponsored teams: Difference between revisions

From TwogPedia
No edit summary
No edit summary
 
(2 intermediate revisions by the same user not shown)
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 = 'Sponsors._pageName=_pageName, Sponsors.start=start, Sponsors.end=end, Sponsors.startRef=startRef, Sponsors.startRefName=startRefName, Sponsors.endRef=endRef, Sponsors.endRefName=endRefName, TeamImages.iconLight=iconLight, TeamImages.iconDark=iconDark, TeamImages.iconAll=iconAll'
local fields = '_pageName, start, end, startRef, startRefName, endRef, endRefName'
local fields = '_pageName, start, end, startRef, startRefName, endRef, endRefName'
local currentDate = os.date('%Y-%m-%d')
local currentDate = os.date('%Y-%m-%d')


local cargoArgs = {
local cargoArgs = {
-- join = 'Sponsors._pageName = TeamImages._pageName',
-- where = 'Sponsors.id ="' ..  currentTitle .. '" AND (TeamImages._pageName=Sponsors._pageName or TeamImages._pageName=SUBSTRING_INDEX(Sponsors._pageName, "/", -1)) AND Sponsors.type="team" AND (Sponsors.end is NULL OR Sponsors.end < "' .. currentDate .. '")',
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 24: Line 21:
local list = mw.html.create('table')
local list = mw.html.create('table')
:addClass('sortable striped-table')
:addClass('sortable striped-table')
mw.logObject(results)
 
if #results > 0 then
if #results > 0 then
local titleRow = mw.html.create('tr')
local titleRow = mw.html.create('tr')
Line 43: Line 40:
        :addClass('linkID')
        :addClass('linkID')
         
         
        tables = 'TeamImages'
        tables = 'Logos'
fields = '_pageName, iconLight, iconDark, iconAll'
fields = '_pageName, logoLight, logoDark, logoAll, iconLight, iconDark, iconAll'
mw.log('pagename')
 
mw.log(result._pageName)
local pageNameSplit = mw.text.split(result._pageName,'/')[2] or ''
local pageNameSplit = mw.text.split(result._pageName,'/')[2] or ''


Line 53: Line 49:
}
}
local iconResult = cargo.query(tables, fields, cargoArgs)
local iconResult = cargo.query(tables, fields, cargoArgs)
mw.log('ICONRESULT: ')
mw.logObject(iconResult)
mw.logObject(iconResult[1])


        if #iconResult > 0 then
        if #iconResult > 0 then
        mw.log('SAIN SISSE')
        if iconResult[1].iconAll then
        if iconResult[1].iconAll then
        mw.log('LOGO ALLLLL')
        teamName:wikitext('<span class="team-icon">[[File:' .. iconResult[1].iconAll .. '|20px]]</span>')
        teamName:wikitext('<span class="icon">[[File:' .. iconResult[1].iconAll .. '|18px]]</span>')
        else  
        else  
        mw.log('ELSEEEEEEEESLEEE')
        if iconResult[1].iconLight and iconResult[1].iconDark then
        if iconResult[1].iconLight and iconResult[1].iconDark then
        mw.log('BOTH LOGOS')
        teamName:wikitext('<span class="team-icon light">[[File:' .. iconResult[1].iconLight .. '|18px]]</span>')
        teamName:wikitext('<span class="icon light">[[File:' .. iconResult[1].iconLight .. '|18px]]</span>')
        teamName:wikitext('<span class="team-icon dark-inline-flex">[[File:' .. iconResult[1].iconDark .. '|18px]]</span>')
        teamName:wikitext('<span class="icon dark-inline">[[File:' .. iconResult[1].iconDark .. '|18px]]</span>')
        elseif iconResult[1].iconLight or iconResult[1].iconDark then
        elseif iconResult[1].iconLight or iconResult[1].iconDark then
        mw.log('EITHER LOGO')
        local file = iconResult[1].iconLight or iconResult[1].iconDark
        local file = iconResult[1].iconLight or iconResult[1].iconDark
        teamName:wikitext('<span class="icon">[[File:' .. file .. '|18px]]</span>')
        teamName:wikitext('<span class="team-icon">[[File:' .. file .. '|20px]]</span>')
        end
        end
        end
        end

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