Module:Infobox/Fonctions/Bâtiment

De Lagny-sur-Marne Wiki
< Module:Infobox‎ | Fonctions
Révision datée du 7 janvier 2015 à 16:57 par Zolo (discussion) (améliorations de l'affichage pour les monuments classés)
Aller à : navigation, rechercher

La documentation pour ce module peut être créée à Module:Infobox/Fonctions/Bâtiment/doc

local p = {}
local wikidatamod = require 'Module:Wikidata'
local general = require 'Module:Infobox/Fonctions'
local coordfunctions = require 'Module:Infobox/Fonctions/Géolocalisation'

--Titre
function p.title()
	--	local class = en-tête par défaut à définir ici ?
	return general.title()
end

--Image
function p.mainimage(cat, defaultimage)
	if not cat then 
		cat = 'Article à illustrer Bâtiment divers'
	end
	return general.mainimage(cat, defaultimage)
end

function p.coordinates(coordspecs)
	return coordfunctions.coordinates(coordspecs)
end

function p.website() 
	return general.website()
end


function p.address()
	return	{
		type = 'mixed',
		label = 'Adresse',
		value = 'adresse',
		wikidata = function(localdata, item) return require('Module:Adresse').wikidataAddress(item) end,
	}
end

function p.transport()
	return {
		{type = 'table', title = 'Accès et transport', rows = {
				{type = 'mixed', label = 'Stationnement', value = 'stationnement'},
				{type = 'mixed', label = 'Gare', value = 'gare'},
				{type = 'mixed', label = 'Métro', value = 'métro'},
				{type = 'mixed', label = 'Tramway', value = 'bus'},
				{type = 'mixed', label = 'Autobus', value = 'gare'},
				},
		}
	}
end

function p.country(default)
 return	coordfunctions.country(default)	
end

function p.archistyle()
	return {
		type = 'mixed',
		label = 'Style architectural',
		value = 'style architectural',
		property = 'P149', 
	}
end

function p.architect()
	return {
		type = 'mixed',
		label = function(localdata, item) return localdata['titre architecte'] or 'Architecte' end,
		value = 'architecte', 
		wikidata = wikidatamod.formatAndCat{item = item, property = 'P84', showqualifiers = {'P518'}, showdate = true}
	}
end

function p.engineer()
	return {
		type = 'mixed',
		label = 'Ingénieur',
		value = 'ingénieur',
		property = 'P631'
	}
end

function p.owner()
	return {
		type = 'mixed',
		label = 'Propriétaire',
		value = 'propriétaire',
		property = 'P631'
	}
end

local function protectionline(localdata, item)
	local logos = require('Module:Logos classement')
	local texts = require('Module:Classement/Texte')
	local claims = wikidatamod.getClaims({item=item, property = 'P1435', exludespecial = true})
	if not claims then return nil end
	local statuses = {}-- nouvelle table pour ne pas afficher séparément deux statements décrivant le même statut
	for i, j in pairs(claims) do
		local pstatus = wikidatamod.getmainid(j)
		if not statuses[pstatus] then 
			statuses[pstatus] = {j}
		else
			table.insert(statuses[pstatus], j)
		end
	end
	local stringtable = {} -- liste des chaînes à retourner
	for i, j in pairs(statuses) do
		local mainstr = texts[i] or wikidatamod.formatEntity(i) -- nom de la protection
		
		local logostr = '' -- logo
		local logo = logos[i]
		if logo then 
			logostr = '[[File:' .. logo .. '|x18px]] ' 
		end

		local t = {} -- informations complémentaires sur les dates et les parties concernées
		for k, l in pairs(j) do
			local protectiondate = wikidatamod.getFormattedQualifiers(l, {'P580'}, {precision = 'year'})
			if protectiondate then
				table.insert(t, protectiondate)
			end
		end
		local details = table.concat(t, ", ")
		if details ~= '' then
			details = ' <small>(' .. details ..  ')</small>'
		else
			details = ''
		end
		table.insert(stringtable, logostr .. mainstr .. details)
	end
	return table.concat(stringtable, '<br />') .. '[[Catégorie:Page utilisant des données de Wikidata/P1435]]'
end

function p.protection(localdata, item)
	return {
		type = 'mixed',
		label = 'Protection',
		value = 'classement',
		wikidata = protectionline(locadata, item)
	}
end

function p.geoloc(params)
	return coordfunctions.geoloc(params)
end

return p