((by SublimeText.Mediawiker)) |
((by SublimeText.Mediawiker)) |
||
Line 64: | Line 64: | ||
} |
} |
||
-- util_cargo.logQuery(query) |
-- util_cargo.logQuery(query) |
||
− | return query |
+ | return util_cargo.queryAndCast(query) |
end |
end |
||
Revision as of 22:54, 2 July 2021
Documentation for this module may be created at Module:LFG/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_title = require("Module:TitleUtil")
local util_vars = require("Module:VarsUtil")
local i18n = require("Module:I18nUtil")
local ROWS = { 'Name', 'Country', 'Birthdate', 'Residency', 'Role' }
local h = {}
local p = {}
function p.main(frame)
local args = util_args.merge()
i18n.init('LFG')
local this_type
if args.type:lower() == "duo" then
this_type = "Duo"
elseif args.type:lower() == "trio" then
this_type = "Trio"
end
local data = h.queryPlayers(this_type)
h.formatData(data)
return h.makeOutput(data)
end
function h.queryPlayers(lfg_type)
local query = {
tables = {
'Players=P',
'PlayerRedirects=PR',
'PlayerImages=PI',
'Tournaments=T',
'Tenures=Ten',
},
join = {
'P.OverviewPage=PR.OverviewPage',
'PR.AllName=PI.Link',
'PI.Tournament=T.OverviewPage',
'P.OverviewPage=Ten.NameLeave',
},
where = {
('P.IsLookingFor%s IS TRUE'):format(lfg_type)
},
fields = {
'P.ID',
'P.Name',
'COALESCE(P.Nationality, P.Country)=Country [country]',
'P.Birthdate',
'P.Residency',
'P.Role',
'PR.AllName',
'COALESCE(P.Image, PI.FileName)=Image',
'Ten.IsCurrent',
'PI.FileName',
},
--[[oneToMany = {
groupBy = { 'Image', 'AllName', 'FileName', 'IsCurrent' }
},]]--
orderBy = 'Ten.IsCurrent DESC, COALESCE(PI.SortDate, T.Date) DESC, PR.AllName DESC',
}
-- util_cargo.logQuery(query)
return util_cargo.queryAndCast(query)
end
function h.formatData(data)
if data.Country then
data.Country = data.Country:flair()
end
end
function h.makeOutput(data)
local boxes = mw.html.create('div')
:addClass('inline-content')
local box = boxes
util_vars.log(data)
for _, player in pairs(data) do
local output = mw.html.create('div')
:addClass('tippingover-tooltip')
:addClass('tooltip-div')
:addClass('player-tooltip')
h.printImage(output, player.Image)
h.printRight(output, player)
h.printBottom(output, player)
box:tag('div'):addClass('inline-content')
end
box:tag('div'):attr('style', 'clear:left;')
return output
end
function h.printRight(output, data)
local div = output:tag('div')
:addClass('player-tooltip-info')
h.printPlayer(div, data)
h.printInfo(div, data)
end
function h.printPlayer(output, data)
output:tag('div')
:addClass('player-tooltip-player')
:wikitext(data.ID)
end
function h.printImage(output, image)
if not image or image == 'Unknown Infobox Image - Player.png' then return end
output:tag('div')
:addClass('player-tooltip-image')
:wikitext(('[[File:%s|250x200px|link=]]'):format(image))
end
function h.printInfo(div, data)
local tbl = div:tag('table')
:addClass('player-tooltip-info-table')
util_html.printVerticalData(tbl, data, ROWS)
end
function h.printBottom(div, data)
local ret = {
tables = { 'Tournaments=T', 'TournamentResults=Res', 'PlayerRedirects=PR' },
fields = { 'PRPoints' },
join = 'T._pageName = Res.OverviewPage, Res.RosterLinks HOLDS PR.AllName',
where = h.getWhere(data),
types = {
PRPoints = 'number'
}
}
end
function h.getWhere(data)
local tbl = {
('PR._pageName="%s"'):format(data.ID),
'Res.RosterLinks HOLDS PR.AllName',
'T.Date >= "2018-01-01" AND T.Date <= "2021-12-31"'
}
return util_cargo.concatWhere(tbl)
end
return p