Module:Liste2 : Différence entre versions

Ligne 25 : Ligne 25 :
 
end
 
end
  
local tbl1,tbl2,tbl3,tbl4,tbl5,tbl6 = {},{},{},{},{},{},{}
+
local tbl,tbl2,tbl3,tbl4,tbl5,tbl6 = {},{},{},{},{},{},{},{}
 
for _, row in ipairs(result) do
 
for _, row in ipairs(result) do
 
row['annee'] = tonumber(row['annee'])
 
row['annee'] = tonumber(row['annee'])
Ligne 31 : Ligne 31 :
 
if supports[row['idSupport']] then row['video']=supports[row['idSupport']] end
 
if supports[row['idSupport']] then row['video']=supports[row['idSupport']] end
 
end
 
end
 
 
end
 
end
 
+
 +
local an1 = result[1]['annee']
 +
local periode = 7
 +
local texte_periode, msg = 'Texte période \n\n', 1
 +
local retour = ''
 
for _,row in ipairs(result) do
 
for _,row in ipairs(result) do
if row['annee'] then
+
if (row['annee'] - an1) % periode == 0 and msg then
if row['annee'] < 1930 then
+
retour = retour .. table.concat(tbl,args.delimiter or '') .. texte_periode
tbl1[#tbl1+1] = frame:expandTemplate{ title = args.template, args = row }
+
an1,tbl,msg = row['annee'],{},nil
elseif  row['annee'] >= 1930 and row['annee'] < 1940 then  
+
else
tbl2[#tbl2+1] = frame:expandTemplate{ title = args.template, args = row }
+
tbl[#t+1] = row
elseif row['annee'] >= 1940 and row['annee'] < 1950 then
+
end
tbl3[#tbl3+1] =  frame:expandTemplate{ title = args.template, args = row }
 
elseif  row['annee'] >= 1950 and row['annee'] < 1960 then
 
tbl4[#tbl4+1] =  frame:expandTemplate{ title = args.template, args = row }
 
elseif  row['annee'] >= 1960 and row['annee'] < 1970 then
 
tbl5[#tbl5+1] =  frame:expandTemplate{ title = args.template, args = row }
 
else
 
    tbl6[#tbl6+1] = frame:expandTemplate{ title = args.template, args = row }
 
end
 
end
 
 
end
 
end
 +
 
local intro = frame:preprocess(args.intro or '')
 
local intro = frame:preprocess(args.intro or '')
 
local outro = frame:preprocess(args.outro or '')
 
local outro = frame:preprocess(args.outro or '')
  
return intro .. table.concat(tbl1,args.delimiter or '') .. table.concat(tbl2,args.delimiter or '') .. table.concat(tbl3,args.delimiter or '') .. table.concat(tbl4,args.delimiter or '') .. table.concat(tbl5,args.delimiter or '') .. table.concat(tbl6,args.delimiter or '') .. outro
+
return intro .. table.concat(retour,args.delimiter or '') .. outro
 +
 
 
end
 
end
 
return p
 
return p

Version du 11 décembre 2018 à 12:46

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

local p = {}
function p.main(frame)
	if frame == mw.getCurrentFrame() then
		args = require('Module:ProcessArgs').merge(true)
	else
		frame = mw.getCurrentFrame()
	end
	
	local query = {}
	for k, v in pairs(args) do
		if string.sub(k, 0, 2) == 'q?' then
			query[string.sub(k, 3)] = v
		end
	end

	supports={}	
	local result = mw.ext.cargo.query('Supports','idSupport,video',{groupBy = 'idSupport',limit=3000})
	for d, row in ipairs(result) do
		supports[row['idSupport']] = row['video']
	end
	
	result = mw.ext.cargo.query(query.tables, query.fields, query)
	if not next(result) then
		return frame:preprocess(args.default or '')
	end

	local tbl,tbl2,tbl3,tbl4,tbl5,tbl6 = {},{},{},{},{},{},{},{}
	for _, row in ipairs(result) do
		row['annee'] = tonumber(row['annee'])
		if row['video'] == '' then
			if supports[row['idSupport']] then row['video']=supports[row['idSupport']] end
		end
	end
	
	local an1 = result[1]['annee']
	local periode = 7
	local texte_periode, msg = 'Texte période \n\n', 1
	local retour = ''
	for _,row in ipairs(result) do
		if (row['annee'] - an1) % periode == 0 and msg then
			retour = retour .. table.concat(tbl,args.delimiter or '') .. texte_periode
			an1,tbl,msg = row['annee'],{},nil
		else
			tbl[#t+1] = row
		end
	end
		
	local intro = frame:preprocess(args.intro or '')
	local outro = frame:preprocess(args.outro or '')

	return intro .. table.concat(retour,args.delimiter or '') .. outro

end
return p