Paladins Esports Wiki
Advertisement
To edit the documentation or categories for this module, click here.
local util_text = require('Module:TextUtil')

local p = {}

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 placement = require('Module:Placementnames')
	local m_team = require('Module:Team')
	local m_role = require('Module:Role')
	local League = require('Module:League').league
	
	local tbl = mw.html.create('table')
	local teamlink = m_team.teamlinkname(team)
	local earnings = {}
	
	local fieldstable = {
		"TournamentResults.TeamLink=TeamLink",
		"TournamentResults.Prize_Markup=PrizeMarkup",
		"TournamentResults.PrizeOther=PrizeOther",
		"TournamentResults.Prize=Prize",
		"TournamentResults.PrizeUnit=PrizeUnit",
		"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 }
	local result = mw.ext.cargo.query(cargotables, cargofields, cargoquery)
	
	tbl:addClass("wikitable sortable"):css("font-size","90%")
		:tag("tr")
			:tag("th"):css({ background = "#E6E6E6", border = "1px solid black" }):attr("colspan","30")
			:wikitext(m_team.teamname(team) .. ' Tournament Results'):done()
		:done()
		:tag("tr")
			:tag("th"):css("width","60"):wikitext("Date"):done()
			:tag("th"):css("width","60"):wikitext("Place"):done()
			:tag("th"):css("width","80"):wikitext("Prize"):done()
			:tag("th"):css("width","250"):wikitext("Event"):done()
			--:tag("th"):css("width","150"):wikitext("Last Result"):done()
			:tag("th"):wikitext("Roster"):done()
		:done()
	
	for _,row in ipairs(result) do
		place = placement[string.lower(row["Place"])] or { bgcolor = "", hiddensort = "", fontcolor = "red", display = "Invalid Placement Name[[Category:Pages With Invalid Placement Names]]" }
		tr = tbl:tag("tr")
		tr:tag("td"):wikitext(row["Date"]):done() -- Need to format this right still
		:tag("td")
				:css({ ["background-color"] = "#" .. place["bgcolor"], color = place["fontcolor"], ["text-align"] = "center" })
				:wikitext('<span style="display:none;">' .. place.hiddensort .. "</span>'''" .. place.display .. "'''")
			:done()
		:tag("td"):wikitext(row["PrizeMarkup"]):done()
		tdEvent = tr:tag("td"):wikitext(League{row["League"],"onlyimage"} .. " [[" .. row["EventLink"] .. "|" .. row["Event"])
		if row["Phase"] ~= nil and row["Phase"] ~= "" then
			tdEvent:wikitext(" - " .. row["Phase"])
		end 
		tdEvent:wikitext("]]"):done()
		--if row["LastOpponent"] == "Group Stage (W/L)" then
		--	row["LastOpponent"] = "Group Stage"
		--end
		--tr:tag("td"):wikitext('<span style="width:40px;display:inline-block;">' .. row["LastResult"] .. '</span>' .. row["LastOpponent"])
		
		teammates = {}
		teammatenames = util_text.split(row["RosterNames"],";;")
        teammatelinks = util_text.split(row["RosterLinks"],";;")
		roles = util_text.split(row["Roles"],";;")
		
		if teammatelinks[1] ~= "" then
			for index,teammatelink in ipairs(teammatelinks) do
				thisroles = {}
				for i, role in ipairs(mw.text.split(roles[index] or '','%s*,%s*')) do
					thisroles[i] = (m_role.onlyimage(role))
				end
				thisrole = table.concat(thisroles,"")
				teammates[#teammates+1] = thisrole .. "&nbsp;[[" .. teammatelink .. "|" .. teammatenames[index] .. "]]"
			end
		end
		tr:tag("td"):wikitext(table.concat(teammates, " &#8226; "))
		
		row["PrizeUnit"] = row["PrizeUnit"] or ""
		
		if row["Prize"] ~= nil and 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 .. " " .. mw.getLanguage('en'):formatNum(amount)
	end
	
	td:wikitext(table.concat(earningstable," &#8226; ")):done()
	
	text = tostring(tbl)
	
	return text
	
end

return p
Advertisement