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:Outils

De Commission Historique
Révision datée du 26 mars 2021 à 17:10 par L.strappazon (discussion | contributions) (Page créée avec « local p = {} function p.arbre(frame) local racine = frame.args['racine'] local cargo_table = frame.args['tables'] local field_branches = frame.args['field_branches']… »)
(diff) ← Version précédente | Voir la version actuelle (diff) | Version suivante → (diff)

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

local p = {}

function p.arbre(frame)
	local racine = frame.args['racine']
	local cargo_table = frame.args['tables']
	local field_branches = frame.args['field_branches']
	local field_noeuds = frame.args['field_noeuds']
	arbre = p.ramif('', racine,'*',cargo_table,field_branches)
	return(arbre)
end

function p.ramif(arbre, noeud, prof, cargo_table, field_branches)	
	local arguments = {
			where = field_branches .. '=' .. '"' .. noeud .. '"',
			groupBy = '_pageName',
			default = '',
		}
		liste_branches = mw.ext.cargo.query(cargo_table, '_pageName', arguments)
		for _,branche in ipairs(liste_branches) do
			if #branche['_pageName'] > 0 then
				arbre = arbre .. '\n'.. prof .. branche['_pageName'] 
				arbre = p.ramif(arbre,branche['_pageName'], prof .. '*', cargo_table, field_branches)
			end
		end
	return arbre
end


function p.requete(frame)
	local liste = ''
	local tables = frame.args['tables']
	local fields = frame.args['fields']
	local arguments = {
		join = frame.args['joinOn'],
		where = frame.args['where'],
		groupBy = frame.args['groupBy'],
		orderBy = frame.args['orderBy'],
		intro = frame.args['intro'],
		outro = frame.args['outro'],
	}
	local result = mw.ext.cargo.query(tables, fields, arguments)
	for _,row in ipairs(result) do
		for _, field in pairs(row) do
			if #field > 0 then
				liste = liste .. '\n' .. field
			end
		end
	end
	return liste
end

return p