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 | 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, | -- 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 currentDate = os.date('%Y-%m-%d') | local currentDate = os.date('%Y-%m-%d') | ||
local cargoArgs = { | local cargoArgs = { | ||
join = 'Sponsors._pageName = | -- join = 'Sponsors._pageName = TeamImages._pageName', | ||
where = 'id ="' .. currentTitle .. '" AND type="team" AND (end is NULL OR end < ' .. currentDate .. ')', | -- 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 .. '")', | |||
limit=10, | limit=10, | ||
orderBy='start' | orderBy='start' | ||
Line 23: | Line 24: | ||
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 41: | Line 42: | ||
local teamName = mw.html.create('td') | local teamName = mw.html.create('td') | ||
:addClass('linkID') | :addClass('linkID') | ||
if | |||
tables = 'TeamImages' | |||
fields = '_pageName, iconLight, iconDark, iconAll' | |||
mw.log('pagename') | |||
mw.log(result._pageName) | |||
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) | |||
mw.log('ICONRESULT: ') | |||
mw.logObject(iconResult) | |||
mw.logObject(iconResult[1]) | |||
if #iconResult > 0 then | |||
mw.log('SAIN SISSE') | |||
if iconResult[1].iconAll then | |||
mw.log('LOGO ALLLLL') | |||
teamName:wikitext('<span class="icon">[[File:' .. iconResult[1].iconAll .. '|18px]]</span>') | |||
else | |||
mw.log('ELSEEEEEEEESLEEE') | |||
if iconResult[1].iconLight and iconResult[1].iconDark then | |||
mw.log('BOTH LOGOS') | |||
teamName:wikitext('<span class="icon light">[[File:' .. iconResult[1].iconLight .. '|18px]]</span>') | |||
teamName:wikitext('<span class="icon dark-inline">[[File:' .. iconResult[1].iconDark .. '|18px]]</span>') | |||
elseif iconResult[1].iconLight or iconResult[1].iconDark then | |||
mw.log('EITHER LOGO') | |||
local file = iconResult[1].iconLight or iconResult[1].iconDark | |||
teamName:wikitext('<span class="icon">[[File:' .. file .. '|18px]]</span>') | |||
end | |||
end | |||
end | end | ||
teamName:wikitext('[[' .. result._pageName .. ']]') | |||
if result.startRef then | if result.startRef then | ||
local startRefName = result.startRefName or '' | local startRefName = result.startRefName or '' |
Revision as of 07:27, 28 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 = '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 currentDate = os.date('%Y-%m-%d')
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 .. '")',
limit=10,
orderBy='start'
}
local results = cargo.query(tables, fields, cargoArgs)
local list = mw.html.create('table')
:addClass('sortable striped-table')
mw.logObject(results)
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 = 'TeamImages'
fields = '_pageName, iconLight, iconDark, iconAll'
mw.log('pagename')
mw.log(result._pageName)
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)
mw.log('ICONRESULT: ')
mw.logObject(iconResult)
mw.logObject(iconResult[1])
if #iconResult > 0 then
mw.log('SAIN SISSE')
if iconResult[1].iconAll then
mw.log('LOGO ALLLLL')
teamName:wikitext('<span class="icon">[[File:' .. iconResult[1].iconAll .. '|18px]]</span>')
else
mw.log('ELSEEEEEEEESLEEE')
if iconResult[1].iconLight and iconResult[1].iconDark then
mw.log('BOTH LOGOS')
teamName:wikitext('<span class="icon light">[[File:' .. iconResult[1].iconLight .. '|18px]]</span>')
teamName:wikitext('<span class="icon dark-inline">[[File:' .. iconResult[1].iconDark .. '|18px]]</span>')
elseif iconResult[1].iconLight or iconResult[1].iconDark then
mw.log('EITHER LOGO')
local file = iconResult[1].iconLight or iconResult[1].iconDark
teamName:wikitext('<span class="icon">[[File:' .. file .. '|18px]]</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