Module:Enfocajon/Calçotor
Apparence
La documentation pour ce module peut être créée à Module:Enfocajon/Calçotor/doc
local p = {}
local wd = require "Module:Entredoux Wikidata".fromLua
local countrymod = require "Module:Country data"
local frame = mw.getCurrentFrame()
function p._teams(teamtype, headers)
-- rècup de les balyês
local claims = wd.getClaims{
rank = 'valid',
property = 'P54',
sorttype = 'chronological',
condition = function(claim)
local v = wd.getmainid(claim)
return wd.isInstance(teamtype, v, 2)
end,
}
if not claims then
return nil
end
-- Crèacion de la trâbla et de les en-tétes
local tab = mw.html.create("tr")
headers = headers or {"Sêsons", "Clubes", "M (B.)"}
for i, j in pairs(headers) do
tab:tag("th"):wikitext(j):done()
end
tab:done()
-- Entègracion de les balyês
local function cleanLabel(id)
local label = wd.getLabel(id)
if not label then
return nil
end
local patterns = {
["[Èè]quipa de?s?'?u? ?"] = "",
["des muens de"] = "-",
["de soccer"] = "",
["de football"] = "",
["[Aa]ssociation [Ff]ootball [Cc]lub"] = "AFC",
["[Ff]ootball [Cc]lub ?d?e?u?"] = "FC ",
["Sporting Clube? ?d?e?u?"] = "SC ",
["Sports Club"] = "SC",
["Club Atlético "] = "CA ",
["Club Deportivo "] = "CD ",
["Associação Atlética "] = "AA ",
["Futebol Clube"] = "FC",
["Fútbol Club"] = "FC",
["Associação Desportiva "] = "AD ",
["Clube Desportivo "] = "CD ",
}
for i, j in pairs(patterns) do
label = mw.ustring.gsub(label, i, j)
end
return label
end
for i, j in pairs(claims) do
local teamid = wd.getmainid(j)
local period = wd.statementDate(j, {precision = 'year', textformat = 'infobox', linktopic = 'football'})
local matches = wd.getFormattedQualifiers(j, {'P1350'})
local goals = wd.getFormattedQualifiers(j, {'P1351'})
local condition = wd.getFormattedQualifiers(j, {'P1642'})
local teamname = wd.formatEntity(teamid, {labelformat = function(id) return cleanLabel(teamid) end} )
local atdate = wd.getFormattedQualifiers(j, {'P580'}, {displayformat = 'raw'}) -- dâta en fôrma -- por adaptar lo drapél en fonccion de la dâta
local teamcountry = wd.formatStatements{entity = teamid, property = 'P1532', displayformat = 'raw'} -- nacionalitât sportiva de l’èquipa, por lo drapél (sèlèccion)
if teamcountry == nil then -- se gins de nacionalitât sportivt, chèrchont lo payis (câs g·ènèrâl)
teamcountry = wd.formatStatements{entity = teamid, property = 'P17', displayformat = 'raw'}
end
if teamcountry == "Q145" then -- se payis=Reyômo-Uni, chèrchont la zona opèracionâla du ch·ampionat du clube, por adaptar lo drapél
local championat = wd.formatStatements{entity = teamid, property = 'P118', displayformat = 'raw', numval = 1}
local zona = wd.formatStatements{entity = championat, property = 'P2541', displayformat = 'raw', numval = 1}
if zona ~= nil then
teamcountry = zona
end
end
local flag = countrymod.standarddisplay(teamcountry, {label = '-', date = atdate or 'default'}) or ''
local formattedteam = flag .. ' ' .. teamname
if condicion then
if string.find (condicion, 'prèt') then
formattedteam = frame:expandTemplate{ title = 'prèt'} .. ' ' .. formattedteam
else
formattedteam = formattedteam .. ' <small>(' .. condicion .. ')</small>'
end
end
local stats = matches
if stats and goals then
goals = mw.text.trim(goals) -- cofieria de viua dedens Modulo:Wikidata a vêre
stats = stats .. "(" .. goals .. ")"
end
tab:tag('tr')
:tag('td'):addClass('data'):wikitext(period):done()
:tag('td'):addClass('data'):wikitext(formattedteam):done()
:tag('td'):addClass('data'):cssText( 'white-space:nowrap; text-align:center'):wikitext(stats):done()
:done()
end
tab:done()
return tostring(tab)
end
function p.teams(frame) -- por los clubes de calço ren que cen serêt Q476028, mas en atendent que wikidata seye complètament parfèt...
return p._teams('Q847017')
end
function p.selections(frame) -- por les sèlèccions g·eografiques
return p._teams('Q6979593', {"Ans", "Sèlèccion", "M (B.)"})
end
return p