Leaguepedia | League of Legends Esports Wiki
Advertisement
Leaguepedia | League of Legends Esports Wiki

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

local util_args = require('Module:ArgsUtil')
local util_cargo = require('Module:CargoUtil')
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_vars = require('Module:VarsUtil')
local Reload = require('Module:Reload')
local m_team = require('Module:Team')

local Placement = require('Module:Placement')
local i18n = require('Module:i18nUtil')

local COLUMNS = {
	'Date', 'PlaceDisplay', 'Event', 'Prize', 'Team', 'LastResult'
}

local h = {}
local p = {}
function p.main(frame)
	-- don't print 1v1 results in a reload, only 5v5 results which are in a sep module
	if Reload.isReload() then return '' end
	local args = util_args.merge()
	i18n.init('PlayerResults1v1')
	local player = args.link or mw.title.getCurrentTitle().baseText
	local result = h.makeAndRunQuery(player)
	if #result == 0 then return end
	util_map.rowsInPlace(result, h.processRow)
	return h.makeOutput(result, player)
end

function h.makeAndRunQuery(link)
	local query = {
		tables = 'TournamentResults1v1=TR, PlayerRedirects=PR',
		join = 'TR.PlayerLink=PR.AllName',
		where = ('PR._pageName="%s"'):format(link),
		fields = {
			'TR.Team',
			'TR.Prize_Markup=Prize',
			'TR.Place',
			'TR.Event',
			'TR.OverviewPage',
			'TR.LastResult',
			'TR.LastOpponent',
			'TR.LastOpponentLink',
			'TR.LastOpponentTeam=TeamVs',
			'TR.Date',
		},
		orderBy = 'TR.Date DESC',
	}
	return util_cargo.queryAndCast(query)
end

function h.processRow(row)
	local place = Placement(row.Place)
	row.PlaceDisplay = place:display()
	row.Event = util_text.intLink(row.OverviewPage, row.Event)
	row.Team = row.Team and m_team.rightshortlinked(row.Team) or ''
	row.LastResult = h.makeLastResult(row)
	row.classes = {
		PlaceDisplay = place:cssClass(),
	}
	row.attrs = {
		PlaceDisplay = {
			['data-sort-value'] = place:sortValue()
		}
	}
end

function h.makeLastResult(row)
	if not row.LastResult then return nil end
	local result = ('%s %s %s'):format(
		row.LastResult,
		row.TeamVs and m_team.onlyimagelinkedshort(row.TeamVs) or '',
		util_text.intLink(row.LastOpponentLink, row.LastOpponent) or ''
	)
	return result
end

function h.makeOutput(processed, player)
	local output = mw.html.create()
	local tbl = output:tag('table')
		:addClass('wikitable sortable')
	util_html.printColspanHeader(tbl, i18n.print('title', player), #COLUMNS)
	util_html.printHeaderFromI18n(tbl, COLUMNS)
	util_html.printRowsByList(tbl, processed, COLUMNS)
	return output
end

return p