(Created page with "local cargo = mw.ext.cargo local func = require('Module:Functions') local UpcomingMatches = require('Module:Infobox/Widget/Upcoming matches').get local Functions = require('Module:Functions') local stringifyDate = Functions.stringifyDate local getTeamLogo = Functions.getTeamLogo local timeUntil = Functions.timeUntil local colorModeDiv = Functions.colorModeDiv local p = {} function p.get(Subheader, team) local currentDate = os.date('%Y-%m-%d') -- Get live tournaments...") |
mNo edit summary |
||
Line 1: | Line 1: | ||
local cargo = mw.ext.cargo | local cargo = mw.ext.cargo | ||
local Functions = require('Module:Functions') | local Functions = require('Module:Functions') | ||
local getTeamLogo = Functions.getTeamLogo | local getTeamLogo = Functions.getTeamLogo | ||
local prizeToString = Functions.prizeToString | |||
local timeUntil = Functions.timeUntil | local timeUntil = Functions.timeUntil | ||
local | local stringifyDate = Functions.stringifyDate | ||
local p = {} | local p = {} | ||
function p.get( | function p.get(tournament, team) | ||
local currentDate = os.date('%Y-%m-%d') | local currentDate = os.date('%Y-%m-%d') | ||
-- Get live | -- Get live matches | ||
local tables = ' | local tables = 'AllMatches' | ||
local fields = ' | local fields = '_pageName, p1, p2, date, bestof' | ||
local | local playerPage = mw.title.getCurrentTitle().text | ||
team = team or '' | |||
local cargoArgs = { | local cargoArgs = { | ||
where = '_pageName LIKE "' .. tournament .. '/%" AND (date is NOT NULL AND date <= "' .. currentDate .. '") AND (winner IS NULL OR winner = 0) AND ((p1 = "' .. team .. '" OR p2 = "' .. team .. '") OR (p1 = "' .. playerPage .. '" OR p2 = "' .. playerPage .. '"))', | |||
orderBy = 'date' | |||
} | } | ||
local results = cargo.query(tables, fields, cargoArgs) | |||
local container = mw.html.create('table'):addClass('w-100 tc') | |||
local container = mw.html.create(' | |||
if #results > 0 then | |||
p.matchHtml(container, results, 'true') | |||
if # | |||
end | end | ||
-- Check for upcoming matches | |||
cargoArgs.where = '_pageName LIKE "' .. tournament .. '/%" AND (date is NOT NULL AND date > "' .. currentDate .. '") AND (winner IS NULL OR winner = 0) AND ((p1 = "' .. team .. '" OR p2 = "' .. team .. '") OR (p1 = "' .. playerPage .. '" OR p2 = "' .. playerPage .. '"))' | |||
results = cargo.query(tables, fields, cargoArgs) | |||
if #results > 0 then | |||
p.matchHtml(container, results) | |||
end | end | ||
return container | return container | ||
end | end | ||
function p. | function p.matchHtml(container, results, live) | ||
local | local game = mw.text.split(results[1]._pageName, '/')[1] | ||
for i = 1, #results do | for i = 1, #results do | ||
local result = results[i] | local result = results[i] | ||
local row = mw.html.create('tr') | |||
local time = mw.html.create('td'):attr('style', 'padding: 4px; font-size: 0.8rem;') | |||
local team1 = mw.html.create('td'):attr('style', 'padding: 4px;') | |||
local vs = mw.html.create('td'):attr('style', 'padding: 4px;'):node(mw.html.create('abbr'):attr('title', 'Best-of-' .. result.bestof):wikitext('Bo' .. result.bestof)) | |||
local team2 = mw.html.create('td'):attr('style', 'padding: 4px;') | |||
if live then time:wikitext('LIVE') else time:wikitext(timeUntil(result.date)) end | |||
local styleLeft = 'display: flex; column-gap: 0.2rem;justify-content: end; align-items: center;' | |||
local styleRight = 'display: flex; column-gap: 0.2rem;justify-content: start; align-items: center;' | |||
local size = '20x20px' | |||
team1:node(mw.html.create('div'):attr('style', styleLeft):node('[[' .. result.p1 .. '|<div style="font-size: 0.8rem; text-align: right;">' .. string.gsub(result.p1, game .. '/', '') .. '</div>]]'):node(getTeamLogo(result.p1, game, size))) | |||
team2:node(mw.html.create('div'):attr('style', styleRight):node(getTeamLogo(result.p2, game, size)):node('[[' .. result.p2 .. '|<div style="font-size: 0.8rem;">' .. string.gsub(result.p2, game .. '/', '') .. '</div>]]')) | |||
row:node(time):node(team1):node(vs):node(team2) | |||
container:node(row) | |||
end | end | ||
end | end | ||
return p | return p |
Revision as of 20:50, 22 October 2023
Documentation for this module may be created at Module:Infobox/Widget/Tournaments/doc
local cargo = mw.ext.cargo
local Functions = require('Module:Functions')
local getTeamLogo = Functions.getTeamLogo
local prizeToString = Functions.prizeToString
local timeUntil = Functions.timeUntil
local stringifyDate = Functions.stringifyDate
local p = {}
function p.get(tournament, team)
local currentDate = os.date('%Y-%m-%d')
-- Get live matches
local tables = 'AllMatches'
local fields = '_pageName, p1, p2, date, bestof'
local playerPage = mw.title.getCurrentTitle().text
team = team or ''
local cargoArgs = {
where = '_pageName LIKE "' .. tournament .. '/%" AND (date is NOT NULL AND date <= "' .. currentDate .. '") AND (winner IS NULL OR winner = 0) AND ((p1 = "' .. team .. '" OR p2 = "' .. team .. '") OR (p1 = "' .. playerPage .. '" OR p2 = "' .. playerPage .. '"))',
orderBy = 'date'
}
local results = cargo.query(tables, fields, cargoArgs)
local container = mw.html.create('table'):addClass('w-100 tc')
if #results > 0 then
p.matchHtml(container, results, 'true')
end
-- Check for upcoming matches
cargoArgs.where = '_pageName LIKE "' .. tournament .. '/%" AND (date is NOT NULL AND date > "' .. currentDate .. '") AND (winner IS NULL OR winner = 0) AND ((p1 = "' .. team .. '" OR p2 = "' .. team .. '") OR (p1 = "' .. playerPage .. '" OR p2 = "' .. playerPage .. '"))'
results = cargo.query(tables, fields, cargoArgs)
if #results > 0 then
p.matchHtml(container, results)
end
return container
end
function p.matchHtml(container, results, live)
local game = mw.text.split(results[1]._pageName, '/')[1]
for i = 1, #results do
local result = results[i]
local row = mw.html.create('tr')
local time = mw.html.create('td'):attr('style', 'padding: 4px; font-size: 0.8rem;')
local team1 = mw.html.create('td'):attr('style', 'padding: 4px;')
local vs = mw.html.create('td'):attr('style', 'padding: 4px;'):node(mw.html.create('abbr'):attr('title', 'Best-of-' .. result.bestof):wikitext('Bo' .. result.bestof))
local team2 = mw.html.create('td'):attr('style', 'padding: 4px;')
if live then time:wikitext('LIVE') else time:wikitext(timeUntil(result.date)) end
local styleLeft = 'display: flex; column-gap: 0.2rem;justify-content: end; align-items: center;'
local styleRight = 'display: flex; column-gap: 0.2rem;justify-content: start; align-items: center;'
local size = '20x20px'
team1:node(mw.html.create('div'):attr('style', styleLeft):node('[[' .. result.p1 .. '|<div style="font-size: 0.8rem; text-align: right;">' .. string.gsub(result.p1, game .. '/', '') .. '</div>]]'):node(getTeamLogo(result.p1, game, size)))
team2:node(mw.html.create('div'):attr('style', styleRight):node(getTeamLogo(result.p2, game, size)):node('[[' .. result.p2 .. '|<div style="font-size: 0.8rem;">' .. string.gsub(result.p2, game .. '/', '') .. '</div>]]'))
row:node(time):node(team1):node(vs):node(team2)
container:node(row)
end
end
return p