Module:Infobox/Widget/Upcoming matches: Difference between revisions

From TwogPedia
(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
Line 1: Line 1:
local cargo = mw.ext.cargo
local cargo = mw.ext.cargo
local stringifyDate = require('Module:Functions').stringifyDate
 
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.person()
function p.get(tournament, team)
local currentDate = os.date('%Y-%m-%d')
local currentDate = os.date('%Y-%m-%d')
local tables = 'AllMatches, Participants'
-- Get live matches
local fields = 'AllMatches._pageName=_pageName, AllMatches.p1=p1, AllMatches.p2=p2, AllMatches.date=date, AllMatches.bestof=bestof'
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 = {
join = 'AllMatches._pageName=Participants._pageName',
where = '_pageName = "' .. 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 .. '"))',
where = '(Participants.players HOLDS "' .. playerPage .. '" OR Participants.coaches HOLDS "' .. playerPage .. '" OR Participants.analysts HOLDS "' .. playerPage .. '" OR Participants.managers HOLDS "' .. playerPage .. '") AND (AllMatches.date is NOT NULL AND AllMatches.date > "' .. currentDate .. '") AND (AllMatches.winner IS NULL OR AllMatches.winner = 0) AND ((AllMatches.p1 = Participants.team OR AllMatches.p2 = Participants.team) OR (AllMatches.p1 = "' .. playerPage .. '" OR AllMatches.p2 = "' .. playerPage .. '"))'
orderBy = 'date'
}
}
 
local results = cargo.query(tables, fields, cargoArgs)
local results = cargo.query(tables, fields, cargoArgs)
    local container = mw.html.create('table')


if #results > 0 then
if #results > 0 then
local container = mw.html.create('div'):attr('style', 'padding: 10px;')
p.matchHtml(container, results, 'true')
end
-- Check for upcoming matches
cargoArgs.where = '_pageName = "' .. 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;'
 
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)))
team2:node(mw.html.create('div'):attr('style', styleRight):node(getTeamLogo(result.p2, game)):node('[[' .. result.p2 .. '|<div style="font-size: 0.8rem;">' .. string.gsub(result.p2, game .. '/', '') .. '</div>]]'))
row:node(time):node(team1):node(vs):node(team2)
for i = 1, #results do
container:node(row)
local result = results[i]
local game = mw.text.split(result._pageName, '/')[1] .. '/'
local team1 = mw.html.create('div'):addClass('w-100'):css('text-align', 'end'):wikitext('[[' .. result.p1 .. '|' .. string.gsub(result.p1,game,'')  .. ']]')
local team2 = mw.html.create('div'):addClass('w-100'):wikitext('[[' .. result.p2 .. '|' .. string.gsub(result.p2,game,'') .. ']]', '')
local firstRow = mw.html.create('div'):attr('style', 'display: flex; gap: 0.5rem;'):node(team1):node(mw.html.create('div'):wikitext('vs')):node(team2)
local tournament = mw.html.create('div'):addClass('w-100 tc'):wikitext('[[' .. result._pageName .. ']]')
local date = mw.html.create('div'):addClass('w-100'):wikitext(stringifyDate(result.date))
local secondRow = mw.html.create('div'):attr('style', 'display: flex; gap: 0.5rem;'):node(tournament):node(mw.html.create('abbr'):attr('title', 'Best of ' .. result.bestof):wikitext('Bo' .. result.bestof)):node(date)
local match = mw.html.create('div'):attr('style', 'margin-bototm: 15px; border: 1px solid #000; padding: 5px;'):node(firstRow):node(secondRow)
container:node(match)
end
return container
else
return nil
end
end
return nil
end
end


return p
return p

Revision as of 15:42, 12 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 = "' .. 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')

	if #results > 0 then
		p.matchHtml(container, results, 'true')
	end
	
	-- Check for upcoming matches
	cargoArgs.where = '_pageName = "' .. 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;'

		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)))
		team2:node(mw.html.create('div'):attr('style', styleRight):node(getTeamLogo(result.p2, game)):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