Module:TeamResults

local util_args = require('Module:ArgsUtil') local util_cargo = require('Module:CargoUtil') local util_html = require('Module:HtmlUtil') local util_table = require('Module:TableUtil') local util_text = require('Module:TextUtil') --local util_toggle = require('Module:ToggleUtil') --local util_tournament = require('Module:TournamentUtil')

local lang = mw.getLanguage('en') local placement = require('Module:Placement') local Team = require('Module:Team').team local League = require('Module:League').league local Role = require('Module:Role').role

local toggles = { showEuros = "_tog_object _toggler_show-Euros _toggler_hide-USD _toggler_hide-Original", showUSD = "_tog_object _toggler_show-USD _toggler_hide-Euros _toggler_hide-Original", showOriginal = "_tog_object _toggler_show-Original _toggler_hide-USD _toggler_hide-Euros", Euros = "_tog_object _toggle Euros", USD = "_tog_object _toggle USD", Original = "_tog_object _toggle Original", initOriginal = "_tog_object _toggle_initshow", initOther = "_tog_object _toggle_inithide" }

local p = {}

function p.makeHeader local Team = require('Module:Team').team local tbl = mw.html.create :tag("tr") :tag("th"):attr("colspan","30") :css({ background = "#E6E6E6", border = "1px solid black" }) :wikitext(Team{team,"teamname"} .. ' Tournament Results - Show Prize as (')			-- toggles to show USD & Euro			:tag('span')				:addClass(toggles.initOriginal):addClass(toggles.Original)				:wikitext('Local')				:wikitext(' &#8226; ')				:tag('span')					:addClass(toggles.showUSD)					:wikitext('USD')				:done				:wikitext(' &#8226; ')				:tag('span')					:addClass(toggles.showEuros)					:wikitext('Euros')				:done			:done			-- toggles to show original & euro			:tag('span')				:addClass(toggles.initOther):addClass(toggles.USD)				:tag('span')					:addClass(toggles.showOriginal)					:wikitext('Local')				:done				:wikitext(' &#8226; ')				:wikitext('USD')				:wikitext(' &#8226; ')				:tag('span')					:addClass(toggles.showEuros)					:wikitext('Euros')				:done			:done			-- toggles to show original & usd			:tag('span')				:addClass(toggles.initOther):addClass(toggles.Euros)				:tag('span') :addClass(toggles.showOriginal) :wikitext('Local') :done :wikitext(' &#8226; ') :tag('span') :addClass(toggles.showUSD) :wikitext('USD') :done :wikitext(' &#8226; ') :wikitext('Euros') :done :wikitext(')')		:done	:done	return tbl end

function p.currencyDisplay(prize, prizeUSD, prizeEuro, prizeMarkup) local tbl = mw.html.create local currencydisplay = {} if prize ~= '' then if prizeUSD ~= '' then currencydisplay.USD = '$ ' .. lang:formatNum(tonumber(prizeUSD)) else currencydisplay.USD = ' ' .. prizeMarkup .. ' '		end if prizeEuro ~= '' then currencydisplay.Euro = '€ ' .. lang:formatNum(tonumber(prizeEuro)) else currencydisplay.Euro = ' ' .. prizeMarkup .. ' '		end end tr:tag("td") :tag('span') :addClass(toggles.Original) :addClass(toggles.initOriginal) :wikitext(prizeMarkup) :done :tag("span") :addClass(toggles.USD) :addClass(toggles.initOther) :wikitext(currencydisplay.USD) :done :tag("span") :addClass(toggles.Euros) :addClass(toggles.initOther) :wikitext(currencydisplay.Euro) :done :done return tbl end

function p.teamResults( frame ) if frame == mw.getCurrentFrame then args = require( 'Module:ProcessArgs').norm else frame = mw.getCurrentFrame end local team = args[1] or tostring(mw.title.getCurrentTitle) local tbl = mw.html.create('table') local teamlink = Team{team,"teamlinkname"} local earnings = {} local fieldstable = { "TournamentResults.TeamLink=TeamLink", "TournamentResults.Prize_Markup=PrizeMarkup", "TournamentResults.PrizeOther=PrizeOther", "TournamentResults.Prize=Prize", "TournamentResults.PrizeUnit=PrizeUnit", "TournamentResults.Prize_USD=Prize_USD", "TournamentResults.Prize_Euro=Prize_Euro", "TournamentResults.Date=Date", "TournamentResults.Place=Place", "TournamentResults.Event=Event", "TournamentResults.Phase=Phase", "CONCAT(TournamentResults._pageName)=EventLink", "TournamentRosters.RosterLinks__full=RosterLinks", "TournamentRosters.Roster=RosterNames", "TournamentRosters.Roles=Roles", "TournamentResults.LastResult=LastResult", "TournamentResults.LastOpponent_Markup=LastOpponent", "Tournaments.League=League", }	local cargotables = "TournamentRosters, TournamentResults, Tournaments" local cargojoin = "TournamentResults.RosterPage = TournamentRosters._pageName, TournamentResults._pageName=Tournaments._pageName" local cargofields = table.concat(fieldstable,",") local cargowhere = 'TournamentResults.TeamLink="' .. teamlink .. '" AND (TournamentRosters.TeamLink = TournamentResults.TeamLink OR TournamentRosters.TeamLink IS NULL)' local cargogroupBy = "TournamentResults.UniqueLine" local cargoorderBy = "TournamentResults.Date desc" local cargoquery = { where = cargowhere, join = cargojoin, groupBy = cargogroupBy, orderBy = cargoorderBy } cargoquery.limit = p.getLimit(args.show) local result = mw.ext.cargo.query(cargotables, cargofields, cargoquery) tbl:addClass("wikitable sortable"):css({ ["font-size"] = "90%", ['table-layout'] = 'fixed' }) :node(p.makeHeader) :tag("tr"):css({ visibility = 'collapse' }) :tag('th'):css({ width = '60px' }):done :tag('th'):css({ width = '70px' }):done :tag('th'):css({ width = '100px' }):done :tag('th'):css({ width = '370px' }):done :tag('th'):done :done :tag("tr") :tag("th"):wikitext("Date"):done :tag("th"):wikitext("Place"):done :tag("th"):wikitext("Prize"):done :tag("th"):wikitext("Event"):done :tag("th"):wikitext("Roster"):done :done local totalprizeUSD = 0 local totalprizeEuro = 0 for _,row in ipairs(result) do		tr = tbl:tag("tr") tr:tag("td"):css({ ['white-space'] = 'nowrap' }):wikitext(row["Date"]):done :node(placement.makeNode(row.Place)) :node(p.currencyDisplay(row.Prize,row.Prize_USD,row.Prize_Euro,row.PrizeMarkup)) tdEvent = tr:tag("td"):wikitext(League{row["League"],"onlyimage"} .. " " .. row["Event"])		if row["Phase"] ~= "" then			tdEvent:wikitext(" - " .. row["Phase"])		end 		tdEvent:wikitext(""):done teammates = {} teammatenames = mw.text.split(row["RosterNames"],"%s*;;%s*") teammatelinks = mw.text.split(row["RosterLinks"],"%s*;;%s*") roles = mw.text.split(row["Roles"],"%s*;;%s*") if teammatelinks[1] ~= "" then for index,teammatelink in ipairs(teammatelinks) do				thisroles = {} thisrole = table.concat(thisroles,"") teammates[#teammates+1] = "" .. teammatenames[index] .. "" end end tr:tag("td"):wikitext(table.concat(teammates, ", ")) if row["Prize"] ~= "" then earnings[row["PrizeUnit"]] = (earnings[row["PrizeUnit"]] or 0) + tonumber(row["Prize"],10) end tr:done end td = tbl:tag("tr") :tag("th"):attr("colspan","30"):wikitext("Total Prize: ") local earningstable = {} for currency, amount in pairs(earnings) do earningstable[#earningstable+1] = currency .. " " .. lang:formatNum(amount) end td:wikitext(table.concat(earningstable," &#8226; ")):done local text = {} text[#text+1] = p.intro(args.show) text[#text+1] = tostring(tbl) local output = table.concat(text,'') return output end

function p.getLimit(show) if show == 'overviewpage' then return 10 elseif show == 'everything' then return 500 end return nil end

function p.intro(show) if show == 'overviewpage' then return string.format(":This table shows up to the 10 most recent results. For complete results, click here.",mw.title.getCurrentTitle.rootText) end return '' end

function p.intro(show) if notitletext == 'yes' then return nil end return '' end

return p