Module:Infobox/Widget/Tournaments: Difference between revisions

From TwogPedia
(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 func = require('Module:Functions')
 
local UpcomingMatches = require('Module:Infobox/Widget/Upcoming matches').get
local Functions = require('Module:Functions')
local Functions = require('Module:Functions')
local stringifyDate = Functions.stringifyDate
local getTeamLogo = Functions.getTeamLogo
local getTeamLogo = Functions.getTeamLogo
local prizeToString = Functions.prizeToString
local timeUntil = Functions.timeUntil
local timeUntil = Functions.timeUntil
local colorModeDiv = Functions.colorModeDiv
local stringifyDate = Functions.stringifyDate
local p = {}
local p = {}


function p.get(Subheader, team)
function p.get(tournament, team)
local currentDate = os.date('%Y-%m-%d')
local currentDate = os.date('%Y-%m-%d')
-- Get live tournaments
-- Get live matches
local tables = 'Tournaments, Participants'
local tables = 'AllMatches'
local fields = 'Tournaments._pageName=_pageName, Tournaments.start=start, Tournaments.end=end, Tournaments.logoAll=logoAll, Tournaments.logoLight=logoLight, Tournaments.logoDark=logoDark, Tournaments.iconAll=iconAll, Tournaments.iconLight=iconLight, Tournaments.iconDark=iconDark, Participants.team=team'
local fields = '_pageName, p1, p2, date, bestof'
local currentPage = mw.title.getCurrentTitle().text
local playerPage = mw.title.getCurrentTitle().text
   
team = team or ''
 
local cargoArgs = {
local cargoArgs = {
join = 'Tournaments._pageName=Participants._pageName'
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'
}
}
if not team then
 
    cargoArgs.where = '(Participants.players HOLDS "' .. currentPage .. '" OR Participants.coaches HOLDS "' .. currentPage .. '" OR Participants.analysts HOLDS "' .. currentPage .. '" OR Participants.managers HOLDS "' .. currentPage .. '") AND (Tournaments.start is NOT NULL AND Tournaments.start <= "' .. currentDate .. '") AND (Tournaments.end IS NOT NULL AND Tournaments.end >= ' .. currentDate .. ')'
local results = cargo.query(tables, fields, cargoArgs)
    else
    cargoArgs.where = 'Participants.team = "' .. currentPage .. '" AND (Tournaments.start is NOT NULL AND Tournaments.start <= "' .. currentDate .. '") AND (Tournaments.end IS NOT NULL AND Tournaments.end >= ' .. currentDate .. ')'
    end
local playerLiveResults = cargo.query(tables, fields, cargoArgs)
     local container = mw.html.create('table'):addClass('w-100 tc')
     local container = mw.html.create('div')
 
if #playerLiveResults > 0 then
if #results > 0 then
container:node(Subheader.make('Live tournaments')):node(p.tournamentWrapper(playerLiveResults, true))
p.matchHtml(container, results, 'true')
end
-- Get upcoming tournaments
if not team then
    cargoArgs.where = '(Participants.players HOLDS "' .. currentPage .. '" OR Participants.coaches HOLDS "' .. currentPage .. '" OR Participants.analysts HOLDS "' .. currentPage .. '" OR Participants.managers HOLDS "' .. currentPage .. '") AND (Tournaments.start is NOT NULL AND Tournaments.start > "' .. currentDate .. '")'
    else
    cargoArgs.where = 'Participants.team = "' .. currentPage .. '" AND (Tournaments.start is NOT NULL AND Tournaments.start > "' .. currentDate .. '")'
    end
local playerUpcomingResults = cargo.query(tables, fields, cargoArgs)
if #playerUpcomingResults > 0 then
container:node(Subheader.make('Upcoming tournaments')):node(p.tournamentWrapper(playerUpcomingResults))
end
end
if not team and #playerUpcomingResults == 0 and #playerLiveResults == 0 then
-- Check for upcoming matches
-- Get live tournaments for talent
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 .. '"))'
tables = 'Tournaments, Talent'
results = cargo.query(tables, fields, cargoArgs)
fields = 'Tournaments._pageName=_pageName, Tournaments.start=start, Tournaments.end=end, Tournaments.logoAll=logoAll, Tournaments.logoLight=logoLight, Tournaments.logoDark=logoDark, Tournaments.iconAll=iconAll, Tournaments.iconLight=iconLight, Tournaments.iconDark=iconDark'
if #results > 0 then
p.matchHtml(container, results)
cargoArgs = {
join = 'Tournaments._pageName=Talent._pageName',
where = 'Talent.people HOLDS "' .. currentPage .. '" AND (Tournaments.start is NOT NULL AND Tournaments.start <= "' .. currentDate .. '") AND (Tournaments.end IS NOT NULL AND Tournaments.end >= ' .. currentDate .. ')'
}
local talentLiveResults = cargo.query(tables, fields, cargoArgs)
if #talentLiveResults > 0 then
container:node(Subheader.make('Live tournaments')):node(p.tournamentWrapper(talentLiveResults, true))
end
end
end
return container
return container
end
end


function p.tournamentWrapper(results, live)
function p.matchHtml(container, results, live)
local wrapper = mw.html.create('div'):attr('style', 'padding: 10px;')
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>]]'))
local dateDiv = mw.html.create('div')
row:node(time):node(team1):node(vs):node(team2)
if live then if result['end'] then dateDiv:wikitext('Until ' ..stringifyDate(result['end']) ) else dateDiv:wikitext('Until TBD') end else dateDiv:wikitext('Starts on ' .. stringifyDate(result.start)) end
local logoDiv = mw.html.create('div')
local nameDiv = mw.html.create('div'):wikitext('[[' .. result._pageName .. ']]')
local tournamentInfo = mw.html.create('div'):attr('style', 'display: flex; gap: 0.5rem; justify-content: center; align-items: center;'):node(dateDiv):node(logoDiv):node(nameDiv)
local matches = mw.html.create('div')
local tournamentContainer = mw.html.create('div'):node(tournamentInfo):node(matches)
local iconSize = '30px'
if result.iconAll then
logoDiv:node('[[File:' .. result.iconAll .. '|' .. iconSize .. '|link=' .. result._pageName .. ']]')
elseif result.iconLight and result.iconDark then
logoDiv:node(colorModeDiv('[[File:' .. result.iconLight .. '|' .. iconSize .. '|link=' .. result._pageName .. ']]', '[[File:' .. result.iconDark .. '|' .. iconSize .. '|link=' .. result._pageName .. ']]'))
elseif result.logoAll then
logoDiv:node('[[File:' .. result.logoAll .. '|' .. iconSize .. '|link=' .. result._pageName .. ']]')
elseif result.logoLight and result.logoDark then
logoDiv:node(colorModeDiv('[[File:' .. result.logoLight .. '|' .. iconSize .. '|link=' .. result._pageName .. ']]', '[[File:' .. result.logoDark .. '|' .. iconSize .. '|link=' .. result._pageName .. ']]'))
else
local logo = result.iconLight or result.iconDark or result.logoLight or result.logoDark
logoDiv:node('[[File:' .. logo .. '|' .. iconSize .. '|link=' .. result._pageName .. ']]')
end
-- Check if any upcoming or live matches for this tournament and player
container:node(row)
tournamentContainer:node(UpcomingMatches(result._pageName, result.team))
wrapper:node(tournamentContainer)
end
end
return wrapper
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