(Created page with "local cargo = mw.ext.cargo local stringifyDate = require('Module:Functions').stringifyDate local p = {} function p.person() local currentDate = os.date('%Y-%m-%d') local tables = 'AllMatches, Participants' local fields = 'AllMatches._pageName=_pageName, AllMatches.p1=p1, AllMatches.p2=p2, AllMatches.date=date, AllMatches.bestof=bestof' local playerPage = mw.title.getCurrentTitle().text local cargoArgs = { join = 'AllMatches._pageName=Participants._pageName', w...") |
mNo edit summary |
||
(6 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
local cargo = mw.ext.cargo | local cargo = mw.ext.cargo | ||
local | |||
local Functions = require('Module:Functions') | |||
local getTeamLogo = Functions.getTeamLogo | |||
local prizeToString = Functions.prizeToString | |||
local timeUntil = Functions.timeUntil | |||
local stringifyDate = Functions.stringifyDate | |||
local p = {} | local p = {} | ||
function p. | function p.get(tournament, team) | ||
local currentDate = os.date('%Y-%m-%d') | local currentDate = os.date('%Y-%m-%d') | ||
local tables = 'AllMatches | -- Get live matches | ||
local fields = ' | local tables = 'AllMatches' | ||
local fields = '_pageName, p1, p2, date, bestof' | |||
local playerPage = mw.title.getCurrentTitle().text | 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') | |||
if #results > 0 then | if #results > 0 then | ||
local | 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' | |||
if result.p1 then | |||
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))) | |||
else | |||
team1:node(mw.html.create('div'):attr('style', styleLeft):node('<div style="font-size: 0.8rem; text-align: right;">TBD</div>'):node(getTeamLogo(nil, game, size))) | |||
end | |||
if result.p2 then | |||
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>]]')) | |||
else | |||
team2:node(mw.html.create('div'):attr('style', styleRight):node(getTeamLogo(nil, game, size)):node('<div style="font-size: 0.8rem;">TBD</div>')) | |||
end | |||
row:node(time):node(team1):node(vs):node(team2) | |||
container:node(row) | |||
end | end | ||
end | end | ||
return p | return p |
Latest revision as of 05:18, 29 October 2023
Documentation for this module may be created at Module:Infobox/Widget/Upcoming matches/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'
if result.p1 then
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)))
else
team1:node(mw.html.create('div'):attr('style', styleLeft):node('<div style="font-size: 0.8rem; text-align: right;">TBD</div>'):node(getTeamLogo(nil, game, size)))
end
if result.p2 then
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>]]'))
else
team2:node(mw.html.create('div'):attr('style', styleRight):node(getTeamLogo(nil, game, size)):node('<div style="font-size: 0.8rem;">TBD</div>'))
end
row:node(time):node(team1):node(vs):node(team2)
container:node(row)
end
end
return p