Module:Infobox location: Difference between revisions

From TwogPedia
No edit summary
No edit summary
Line 4: Line 4:
local Subheader = require('Module:Infobox/Widget/Subheader')
local Subheader = require('Module:Infobox/Widget/Subheader')
local LinksWidget = require('Module:Infobox/Widget/Links')
local LinksWidget = require('Module:Infobox/Widget/Links')
local ListWidget = require('Module:Infobox/Widget/List')
local SponsorsWidget = require('Module:Infobox/Widget/Sponsors')
local LocationWidget = require('Module:Infobox/Widget/Location')
local LocationWidget = require('Module:Infobox/Widget/Location')
local RowWidget = require('Module:Infobox/Widget/Row')
local RowWidget = require('Module:Infobox/Widget/Row')
local cargo = mw.ext.cargo


local Flags = require('Module:Flags')
local Flags = require('Module:Flags')
Line 14: Line 15:
local args = getArgs(frame)
local args = getArgs(frame)
local headerNode = Header.make(args.title or mw.title.getCurrentTitle(), args.image or '')
local headerNode
if args.logoAll or args.logoLight or args.logoDark then
headerNode = Header.make(args.title or mw.title.getCurrentTitle().text, args.logoLight, args.logoDark, args.logoAll)
elseif args.franchise then
local currentDate = os.date('%Y-%m-%d')
local tables = 'LocationImages'
local fields = '_pageName, logoLight, logoDark, logoAll, start, end'
local cargoArgs = {
where = '_pageName="' .. args.franchise .. '" AND  (start is NULL OR start < "' .. currentDate .. '") AND (end is NULL OR end > "' .. currentDate .. '")'
}
local results = cargo.query(tables, fields, cargoArgs)
 
if #results > 0 then
if ( results[1].logoAll ) then
headerNode = Header.make(args.title or currentTitle, nil, nil, results[1].logoAll)
else
headerNode = Header.make(args.title or currentTitle, results[1].logoLight, results[1].logoDark)
end
end
else
headerNode = Header.make(args.title or mw.title.getCurrentTitle().text)
end
local container = mw.html.create('div')
local container = mw.html.create('div')
Line 40: Line 62:
container:node(RowWidget.make('Capacity', args.capacity))
container:node(RowWidget.make('Capacity', args.capacity))
end
end
if args.franchise then
if args.franchise then
container:node(RowWidget.make('Franchise', args.franchise, frame))
container:node(RowWidget.make('Franchise', args.franchise, frame))
local tables = 'Sponsors'
local fields = 'id, startRef, startRefName, endRef, endRefName'
local cargoArgs = {
where = '_pageName="' ..args.franchise .. '"'
}
local results = cargo.query(tables, fields, cargoArgs)
if #results > 0 then
    container:node(RowWidget.make('Sponsors', SponsorsWidget.make(results, frame)))
end
end
if args.sponsors and args.franchise == nil then
container:node(RowWidget.make('Sponsors', args.sponsors))
end
end
if args.sponsors then
if args.locationsponsor then
container:node(RowWidget.make('Sponsors', ListWidget.make(args.sponsors)))
container:node(RowWidget.make('Location specific sponsors', args.locationsponsor))
end
end

Revision as of 21:38, 28 September 2022

Documentation for this module may be created at Module:Infobox location/doc

local getArgs = require('Module:Arguments').getArgs
local Links = require('Module:Links')
local Header = require('Module:Infobox/Widget/Header')
local Subheader = require('Module:Infobox/Widget/Subheader')
local LinksWidget = require('Module:Infobox/Widget/Links')
local SponsorsWidget = require('Module:Infobox/Widget/Sponsors')
local LocationWidget = require('Module:Infobox/Widget/Location')
local RowWidget = require('Module:Infobox/Widget/Row')
local cargo = mw.ext.cargo

local Flags = require('Module:Flags')
local Infobox = {}

function Infobox.main(frame)
	local args = getArgs(frame)
	
	local headerNode
	if args.logoAll or args.logoLight or args.logoDark then
		 headerNode = Header.make(args.title or mw.title.getCurrentTitle().text, args.logoLight, args.logoDark, args.logoAll)
	elseif args.franchise then
		local currentDate = os.date('%Y-%m-%d')
		local tables = 'LocationImages'
		local fields = '_pageName, logoLight, logoDark, logoAll, start, end'
		local cargoArgs = {
			where = '_pageName="' .. args.franchise .. '" AND  (start is NULL OR start < "' .. currentDate .. '") AND (end is NULL OR end > "' .. currentDate .. '")'
		}
		local results = cargo.query(tables, fields, cargoArgs)

		if #results > 0 then
			if ( results[1].logoAll ) then
				headerNode = Header.make(args.title or currentTitle, nil, nil, results[1].logoAll)
			else 
				headerNode = Header.make(args.title or currentTitle, results[1].logoLight, results[1].logoDark)
			end
		end
	else 
		headerNode = Header.make(args.title or mw.title.getCurrentTitle().text)
	end
	
	local container = mw.html.create('div')
		:addClass('ib')
		
	container:node(headerNode):node(Subheader.make('Location Information'))
	
	if args.opened then
		container:node(RowWidget.make('Opened', args.opened))
	end
	
	if args.type then
		container:node(RowWidget.make('Type', args.type))
	end
	
	if args.country then
		container:node(RowWidget.make('Location', LocationWidget.make(args.country, args.city, 'Locations')))
	end
	
	if args.address then
		container:node(RowWidget.make('Address', args.address))
	end
	
	if args.capacity then
		container:node(RowWidget.make('Capacity', args.capacity))
	end
	
	if args.franchise then
		container:node(RowWidget.make('Franchise', args.franchise, frame))
		local tables = 'Sponsors'
		local fields = 'id, startRef, startRefName, endRef, endRefName'
		local cargoArgs = {
			where = '_pageName="' ..args.franchise .. '"'
		}
		local results = cargo.query(tables, fields, cargoArgs)
		if #results > 0 then
	    	container:node(RowWidget.make('Sponsors', SponsorsWidget.make(results, frame)))
		end
	end
	
	if args.sponsors and args.franchise == nil then
		container:node(RowWidget.make('Sponsors', args.sponsors))
	end
	
	if args.locationsponsor then
		container:node(RowWidget.make('Location specific sponsors', args.locationsponsor))
	end
	
	container:node(Subheader.make('Links'))
	
	local transformedLinks = Links.transform(args)
	local fullLinks = LinksWidget.make(transformedLinks, 'team')
	
	container:node(fullLinks)
	return container
end

return Infobox