Halo Esports Wiki

We are currently performing extensive maintenance to this wiki and as a result there will likely be errors. Please be patient while we work to fix all problems.

READ MORE

Halo Esports Wiki
Advertisement

Documentation for this module may be created at Module:TournamentResultsQueryAbstract/doc

local util_args = require('Module:ArgsUtil')
local util_cargo = require('Module:CargoUtil')
local util_esports = require('Module:EsportsUtil')
local util_html = require('Module:HtmlUtil')
local util_map = require('Module:MapUtil')
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 util_vars = require('Module:VarsUtil')
local i18n = require('Module:i18nUtil')
local Reload = require('Module:Reload')

local m_team = require('Module:Team')
local Game = require('Module:Game')
local Sprite = require('Module:Sprite').sprite
local lang = mw.getLanguage('en')
local Placement = require('Module:Placement')
local PopupButton = require('Module:PopupButton')

local sep = '%s*;;%s*'
local sep2 = '%s*,%s*'
local h = {}
local s = {}
local p = require('Module:LuaClassSystem').class.abstract()

function p:init(queryType)
	
	self.CURRENCY_TOGGLE = {
		order = { 'Local', 'USD', 'Euros' },
		sep = ' • ',
		section = 'teamres-togglers-currency',
		all = 'teamres-currency-all',
	}
	
	i18n.init(('%sResults'):format(queryType))
	i18n.init(('TournamentResultsQuery'):format(queryType))
	self.queryType = queryType
	self.limitOverviewpage = nil
	self.limitEverything = nil
	self.COLUMNS = {}
end

function p:run(args)
	util_toggle.oflInit(self.CURRENCY_TOGGLE)
	local subject = self:getSubject(args)
	local query = self:getQuery(args, subject)
	local result = util_cargo.queryAndCast(query)
	util_map.selfRowsInPlace(self, result, self.formatOneRow)
	return self:introSentence(args), self:intro(args), self:makeOutput(result, subject)
end

function p:getSubject(args) end

function p:getQuery(args, subject)
	local query = {
		tables = self:getTables(args),
		join = self:getJoin(args),
		where = self:getWhere(args, subject),
		fields = self:getFields(args),
		groupBy = 'Res.UniqueLine',
		orderBy = self:getOrderBy(args),
		limit = self:getLimit(args)
	}
	util_cargo.logQuery(query)
	return query
end

function p:getTables(args)
	local tables = {
		"TournamentResults=Res", 
		"TournamentRosters=Ros", 
		"Tournaments=T",
	}
	return tables
end

function p:getJoin(args)
	local join = {
		"Res.PageAndTeam=Ros.PageAndTeam",
		"Res.OverviewPage=T.OverviewPage",
	}
	return join
end

function p:getWhere(args, subject)
	local where = {
		'Res.PageAndTeam IS NOT NULL',
		'Res.PageAndTeam=Ros.PageAndTeam',
		self:getSubjectWhereCondition(args, subject),
		self:getTypeWhereCondition(args),
		args.minplacement and ('Place_Number <= "%s"'):format(args.minplacement),
		args.tier and ('T.Tier = "%s"'):format(args.tier),
	}
	return where
end

function p:getSubjectWhereCondition(subject) end

function p:getTypeWhereCondition(args) end

function p:getFields(args)
	local fields = {
		"Res.Team",
		"Res.Prize_Markup=PrizeMarkup",
		"Res.PrizeOther",
		"Res.Prize",
		"Res.PrizeUnit",
		"Res.Prize_USD",
		"Res.Prize_Euro",
		"Res.Date",
		"Res.Place",
		"Res.Phase",
		"Ros.RosterLinks",
		"Ros.Roles",
		"COALESCE(T.LeagueIconKey,T.League)=League[league]",
		"T.OverviewPage=EventLink",
		"T.Name=Event",
		"T.EventType=Type",
		'T.Game=Game',
		'T.Tier=Tier',
		"COALESCE(Res._pageName,T._pageName)=_pageName",
	}
	return fields
end

function p:getOrderBy(args)
	return 'Res.Date DESC'
end

function p:getLimit(args)
	if args.limit then return args.limit end
	if args.show == 'overviewpage' then
		return self.limitOverviewpage
	elseif args.show == 'everything' then
		return self.limitEverything
	end
	return nil
end

function p:formatOneRow(row)
	if not row.EventLink then
		error(i18n.print('error_missingPageName', row._pageName))
	end
	row.Game = Game(row.Game):image() or ''
	row.PrizeDisplay = self:getPrizeDisplay(row)
	row.Roster = self:getRoster(row)
	row.Tournament = ('%s %s%s'):format(
		row.League:image() or '',
		util_text.intLink(row.EventLink, row.Event),
		row.Phase and (' - %s'):format(row.Phase) or ''
	)
	local place = Placement(row.Place)
	row.PlaceDisplay = place:display()
	row.TeamDisplay = m_team.rightshortlinked(row.Team)
	row.classes = {
		PrizeDisplay = 'achivements-prize-cell',
		Date = 'achivements-date',
		PlaceDisplay = ('achievements-place %s'):format(place:cssClass() or ''),
		LastResult = 'achievements-lastresult-cell'
	}
	row.attrs = {
		PlaceDisplay = {
			['data-sort-value'] = place:sortValue()
		}
	}
end

function p:getLastResult(row)
	local div = mw.html.create('div')
		:addClass('achievements-lastresult-outer')
	div:tag('span')
		:addClass('achievements-lastresult-inner')
		:wikitext(row.LastResult)
	div:wikitext(row.LastOpponent)
	local div_right = div:tag('div')
		:addClass('achievements-lastresult-right')
	PopupButton.tth(div_right, row.EventLink, row.Event, row.Team)
	return tostring(div)
end

function p:getPrizeDisplay(row)
	local currencydisplay = { Local = row.PrizeMarkup }
	if row.Prize then
		row.PrizeMarkup = row.PrizeMarkup or row.Prize
		if row.Prize_USD and row.Prize_USD ~= '' then
			currencydisplay.USD = '$ ' .. lang:formatNum(tonumber(row.Prize_USD))
		else
			currencydisplay.USD = '<span style="font-style:italic;">' .. row.PrizeMarkup .. '</span>'
		end
		if row.Prize_Euro and row.Prize_Euro ~= '' then
			currencydisplay.Euros = '€ ' .. lang:formatNum(tonumber(row.Prize_Euro))
		else
			currencydisplay.Euros = '<span style="font-style:italic;">' .. row.PrizeMarkup .. '</span>'
		end
	end
	local currencyCell = mw.html.create()
	for _, v in ipairs(self.CURRENCY_TOGGLE.order) do
		self:printOneCurrency(currencydisplay, currencyCell, v)
	end
	return currencyCell
end

function p:printOneCurrency(displays, currencyCell, this)
	local span = currencyCell:tag('span')
		:wikitext(displays[this])
	util_toggle.oflCellClasses(span, self.CURRENCY_TOGGLE, this)
end

function p:getRoster(row)
	if not row.RosterLinks then return nil end
	local teammates = {}
	local links = util_text.split(row.RosterLinks, sep)
	local roles = row.Roles and util_text.split(row.Roles, sep) or ''
	for i, link in ipairs(links) do
		local thisrole = util_map.splitAndConcat(roles[i] or '', nil, s.RoleSprite, nil) or ''
		teammates[#teammates+1] = ("%s&nbsp;%s"):format(thisrole, self:getOneMember(link, row))
	end
	return table.concat(teammates, " &#8226; ")
end

function p:getOneMember(link, row)
	return util_esports.playerLinked(link)
end

function p:introSentence(args)
	if args.show == 'overviewpage' and not Reload.isReload() then
		return "''" .. i18n.print('seeall', mw.title.getCurrentTitle().rootText) .. "''"
	end
	return ''
end

function p:intro(args)
	if util_vars.getBool('isLowContent') then return '' end
	return Reload.intro(
		'FilterTournamentResults',
		('%sResults'):format(self.queryType),
		args
	)
end

function p:makeOutput(result, subject)
	local output = Reload.wrapper()
	local tbl = output:tag('div'):tag('table')
		:addClass("wikitable sortable hoverable-rows")
		:css({ ["font-size"] = "90%" })
	util_html.printColspanHeader(tbl, self:makeHeaderText(subject), #self.COLUMNS)
	util_html.printHeaderFromI18n(tbl, self.COLUMNS)
	util_html.printRowsByList(tbl, result, self.COLUMNS)
	self:finalizeTable(tbl, result, subject)
	return output
end

function p:makeHeaderText(subject) end

function p:finalizeTable(tbl) end

function s.RoleSprite(id)
	if id == 'Player' then return '' end
	return Sprite{
		id,
		size = '15',
		type = 'Role',
		notext = true,
		nolink = true,
	}
end

return p
Advertisement