مودول:ب.ص.م/أدوات/منافسة رياضية

من ويكيپيديا

local p = {}
local item = require( 'وحدة:ب.ص.م/بيانات' ).item
local wikidata = require "Module:Wikidata/fr" 
--local countrymod = require "Module:Country data"

local typeofteam = {
	Q20639847 = 'فريق محترف',
	Q1756006 = '[[فريق قاري|قاري]]',
	Q382927 = '[[فريق قاري محترف|قاري محترف]]',
}

-- date de la course pour adapter les drapeaux et nationalités des participants
local raceDate = wikidata.formatStatements{
	entity = item, 
	property = {'P580', 'P585'}, 
	numval = 1, 
	displayformat = 'raw'
}

local function formatPerson(person) -- retourne le nom d'une personne précédé du ou des drapeaux appropriés

	local str = wikidata.formatEntity(person)

	-- récupère la nationalité telle que stockée dans P27 (personnes) ou P17 (équipes)
	local nationalities = wikidata.stringTable{entity = person, property = {'P27', 'P17'}, atdate = raceDate, displayformat = 'raw'}
	if not nationalities then
		return str
	end
	
	local flags = {}
	for i, nation in pairs(nationalities) do
		local flag, success -- = countrymod.standarddisplay(nation, {label = '-', date = 'default'})
		if success then
			str = flag .. ' ' .. str
		end 
                str = nation .. ' ' .. str
	end
	return str
end

function p.winnerRow(label, winnertype)
	
	local function wikidataval(winnertype)
		-- si l'on ne connait pas le qualificatif, ne pas utiliser Wikidata
		if not winnertype then
			return nil
		end
		local winners = wikidata.stringTable{
			entity = item,
			property = 'P1346',
			displayformat = 'raw',
			excludespecial = true,
			qualifier = 'P642',
			qualifiervalue = winnertype
		}
		if not winners then
			return nil
		end
		for i, winner in pairs(winners) do
			winners[i] = formatPerson(winner)
		end
		local str = table.concat(winners, '<br />')
		-- ajout rétrolien et cat
		str = wikidata.formatAndCat{value = str, entity = entity, property = 'P1346'}
		return str
	end
		 
	return {type = 'row', label = label, value = param, wikidata = function() return wikidataval(winnertype) end}
end

function p.winnerRow2(label, param, winnertype)
	
	local function wikidataval()
		-- si l'on ne connait pas le qualificatif, ne pas utiliser Wikidata
		if not winnertype then
			return nil
		end
		local winners = wikidata.stringTable{
			entity = item, 
			property = 'P1346', 
			displayformat = 'raw', 
			excludespecial = true, 
			qualifier = 'P642', 
			qualifiervalue = winnertype
		}
		if not winners then
			return nil
		end
		for i, winner in pairs(winners) do
			winners[i] = formatPerson(winner)
		end
		local str = table.concat(winners, '<br />')
		-- ajout rétrolien et cat
		str = wikidata.formatAndCat{value = str, entity = entity, property = 'P1346'}
		return str
	end
		 
	return {type = 'row', label = label, value = param, wikidata = wikidataval}
end

function p.typeofteam()
	return {
		type = 'row', 
		value = 'وضع',
		wikidata = {
			property = 'P31',
			showdate = true,
			conjtype = '<br />',
			sorttype = 'chronological',
			speciallabels = typeofteam,
		}, 
		label = 'الوضع القانوني',
		--plurallabel = 'Statuts'
	}
end

return p