Chronos chronos left.png
Rusmed logo color.png
Chronos chronos right.png

A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

Module:Personne2

De Commission Historique

La documentation pour ce module peut être créée à Module:Personne2/doc

local pagetitle = tostring(mw.title.getCurrentTitle())

local p = {}
function p.main(frame)
	
	f = require("Module:Fonctions")
	
	local P, refer = {}, {}	
	local publications,sources, pers_pers, pers_inst, pers_act, pers_conc='','','','','',''
	local strong_links={"directeur_de_these","superieur_hierarchique","inf_hier","disciple","evaluateur","evalue_par","student","teacher"}
	local langue = frame:preprocess("{{int:lang}}")
	local lang = mw.getLanguage( langue )

-- Données personnelles

	for field, value in pairs(frame.args) do
		P[field] = value
	end
	for _,field in ipairs({'Naissance','Deces','Exercice_medecine','Annee_these','Exam'}) do
	    P[field] = f.afficheDate(lang, P[field])
	end
	for _,ref in ipairs(mw.text.split(P['RefPers'],'#')) do
		f.tableRef(ref,refer)
	end



--Nationalités, Localisations, Confessions

-- Relations personnes/personnes

	local tables = 'Pers_pers'
	local fields = '_pageName=Prel,RefBib=Ref,Date_debut=Debut,Date_debut__precision=DebutP,Date_fin=Fin,Date_fin__precision=FinP,Resume_fr=Resume_fr,Resume_de=Resume_de,Resume_en=Resume_en,Nature=Nature,Objet_1,Objet_2'
	local arguments = {
		where='Objet_1 IS NOT NULL and Objet_2 IS NOT NULL  and (Objet_1="' .. pagetitle .. '" or Objet_2="' .. pagetitle .. '")',
		groupBy='Nature,Objet_1,Objet_2,Debut,Fin',
		orderBy='Nature,Debut,Fin',
		intro=''
	}
	local result = mw.ext.cargo.query(tables, fields, arguments)
	if next(result) then
		pers_pers = '\r=={{int:Template-Relations}}==\r' 
		local relations = f.trie_relations(result,"Nature",langue,{["directeur_de_these"]="disciple",["superieur_hierarchique"]="inf_hier",["evaluateur"]="evalue_par",["student"]="teacher"})
		for nat, rels in pairs(relations) do
			pers_pers = pers_pers .. '\r===' .. f.translate(nat,langue) .. '===\r'
			for _,rel in ipairs(rels) do
				local rref = {}
				for _,ref in ipairs(mw.text.split(rel['Ref'],'#')) do
					f.tableRef(ref,rref)
				end
				pers_pers = pers_pers .. '* [[' .. rel["Objet_2"] .. ']] (' .. f.afficheDate(lang,rel["Debut"],rel["DebutP"]) .. ' - ' .. f.afficheDate(lang,rel["Fin"],rel["FinP"]) .. ')'  .. f.expandRef(frame,rref['Reference']).. '[[' .. rel["Prel"] .. '|→]]\n'
			end
		end
		
--Essai relations de second ordre - Début
	
		local lbn={}
		for _,link in ipairs(strong_links) do
			if relations[link] then
				for _,nom in ipairs(relations[link]) do
					lbn[nom["Objet_2"]]='_'
				end
			end
		end
		
		local lbn2={}
		pers_pers = pers_pers .. '\r====' .. f.translate("Relations de second ordre",langue) .. '====\r'
		for nom,_ in pairs(lbn) do
			tables = 'Pers_pers'
			fields = 'Nature=Nature,Objet_1,Objet_2'
			arguments = {
				where='(Objet_1="' .. nom .. '" or Objet_2="' .. nom .. '") and Nature != "ami" and Nature != "collegue" ' ,
				groupBy='Nature,Objet_1,Objet_2',
				orderBy='Objet_2,Nature',
				intro=''
			}
	
			result = mw.ext.cargo.query(tables, fields, arguments)
			if next(result) then
				for _,nom2 in ipairs(result) do
					lbn2[nom2["Objet_1"]] = nom
					lbn2[nom2["Objet_2"]] = nom
				end
			end
		end
		for nom, via in pairs(lbn2) do
			if nom ~= pagetitle and not f.contains_idx(lbn, nom) then pers_pers = pers_pers .. '[['..nom..']]'..'<small> ('..via..')</small>, ' end
		end
--Essai relations de second ordre - Fin

	end

	local fields = {'Prenom','Nom','Sexe','Naissance','Lieu_de_naissance','Deces','Lieu_de_deces','These','Exam','Dir_these','Annee_these','Lieu_these','Exercice_medecine','Profession','Nationalites','Titre'}
	for _,field in ipairs(fields) do
		if #P[field] > 0 then
			P[field] = P[field] .. f.expandRef(frame,refer[field])
		end
	end
	
	local text_fields, langs = {'Resume','Contexte','Commentaire'}, {langue,'en','fr','de'}
	f.afficheTexteLangue(text_fields,langs,P)	


-- Relations personnes/institutions

	local tables = 'Pers_inst, Personnes=Pa'
	local fields = 'Pa._pageName=nomA,Pers_inst._pageName=Prel,Pers_inst.RefBib=Ref,Pers_inst.Date_debut=Debut,Pers_inst.Date_fin=Fin,Pers_inst.Resume_fr=Resume_fr,Pers_inst.Resume_de=Resume_de,Pers_inst.Resume_en=Resume_en,Pers_inst.Nature=Nature,Pers_inst.Objet_1=Objet_1,Pers_inst.Objet_2=Objet_2'
	local arguments = {
		join='Pa._pageName=Pers_inst.Objet_1',
		where='Pers_inst.Objet_2 IS NOT NULL and Pa._pageName=Pers_inst.Objet_1 and Pers_inst.Objet_1="' .. pagetitle .. '"',
		groupBy='Pers_inst.Nature,nomA,Pers_inst.Objet_2',
		orderBy='Debut,Fin,Pers_inst.Nature,nomA,Pers_inst.Objet_2',
		intro=''
	}
	local result = mw.ext.cargo.query(tables, fields, arguments)
	if next(result) then
		pers_inst = '\r=={{int:Template-Liens_institutions}}==\r' 
		local relations = f.trie_relations(result,"Objet_2",langue)
		for inst, rels in pairs(relations) do
			pers_inst = pers_inst .. '\r===' .. inst .. '===\r'
			for _,rel in ipairs(rels) do
				local rref = {}
				for _,ref in ipairs(mw.text.split(rel['Ref'],'#')) do
					f.tableRef(ref,rref)
				end
				 pers_inst = pers_inst .. '* [[' .. rel["Nature"] .. ']]' .. f.expandRef(frame,rref['Reference']).. '[[' .. rel["Prel"] .. '|&rarr;]]\n'
			end
		end	
	end
	
-- Relations personnes/concepts

	local tables = 'Pers_conc, Personnes=Pa'
	local fields = 'Pa._pageName=nomA,Pers_conc._pageName=Prel,Pers_conc.RefBib=Ref,Pers_conc.Date_debut=Debut,Pers_conc.Date_fin=Fin,Pers_conc.Resume_fr=Resume_fr,Pers_conc.Resume_de=Resume_de,Pers_conc.Resume_en=Resume_en,Pers_conc.Nature=Nature,Pers_conc.Objet_1=Objet_1,Pers_conc.Objet_2=Objet_2'
	local arguments = {
		join='Pa._pageName=Pers_conc.Objet_1',
		where='Pers_conc.Objet_2 IS NOT NULL and Pa._pageName=Pers_conc.Objet_1 and Pers_conc.Objet_1="' .. pagetitle .. '"',
		groupBy='Pers_conc.Nature,nomA,Pers_conc.Objet_2',
		orderBy='Pers_conc.Nature,Debut,Fin,nomA,Pers_conc.Objet_2',
		intro=''
	}
	local result = mw.ext.cargo.query(tables, fields, arguments)
	if next(result) then
		pers_conc = '\r=={{int:Template-Liens_concepts}}==\r' 
		local relations = f.trie_relations(result,"Objet_2",langue)
		for conc, rels in pairs(relations) do
			pers_conc = pers_conc .. '\r===' .. conc .. '===\r'
			for _,rel in ipairs(rels) do
				local rref = {}
				for _,ref in ipairs(mw.text.split(rel['Ref'],'#')) do
					f.tableRef(ref,rref)
				end
				pers_conc = pers_conc .. '* [[' .. rel["Nature"] .. ']]' .. f.expandRef(frame,rref['Reference']).. '[[' .. rel["Prel"] .. '|&rarr;]]\n'
			end
		end	
	end	
	
-- Relations personnes/actions

	local tables = 'Pers_act, Personnes=Pa'
	local fields = 'Pa._pageName=nomA,Pers_act._pageName=Prel,Pers_act.RefBib=Ref,Pers_act.Date_debut=Debut,Pers_act.Date_fin=Fin,Pers_act.Resume_fr=Resume_fr,Pers_act.Resume_de=Resume_de,Pers_act.Resume_en=Resume_en,Pers_act.Nature=Nature,Pers_act.Objet_1=Objet_1,Pers_act.Objet_2=Objet_2'
	local arguments = {
		join='Pa._pageName=Pers_act.Objet_1',
		where='Pers_act.Objet_2 IS NOT NULL and Pa._pageName=Pers_act.Objet_1 and Pers_act.Objet_1="' .. pagetitle .. '"',
		groupBy='Pers_act.Nature,nomA,Pers_act.Objet_2',
		orderBy='Pers_act.Nature,Debut,Fin,nomA,Pers_act.Objet_2',
		intro=''
	}
	local result = mw.ext.cargo.query(tables, fields, arguments)
	if next(result) then
		pers_act = '\r=={{int:Template-Liens_actions}}==\r' 
		local relations = f.trie_relations(result,"Objet_2",langue)
		for act, rels in pairs(relations) do
			pers_act = pers_act .. '\r===' .. act .. '===\r'
			for _,rel in ipairs(rels) do
				local rref = {}
				for _,ref in ipairs(mw.text.split(rel['Ref'],'#')) do
					f.tableRef(ref,rref)
				end
				pers_act = pers_act .. '* [[' .. rel["Nature"] .. ']]' .. f.expandRef(frame,rref['Reference']).. '[[' .. rel["Prel"] .. '|&rarr;]]\n'
			end
		end	
	end		
	
	cartouche = frame:expandTemplate({ title = "Cartouche", args = P})
	biographie = frame:expandTemplate({ title = "Biographie", args = P })
	publications = '\r===' .. f.translate('Publications',langue) .. '===\r' .. f.expandRef(frame,refer['Publication'],'ref')

	references =  '\r==' .. f.translate('References',langue) .. '==\r' .. f.expandRef(frame,refer['Reference'],'ref')

	page = frame:preprocess(cartouche .. biographie .. publications .. pers_pers .. pers_inst .. pers_conc .. pers_act .. references)


	return page
end
return p