Module:Liste2 : Différence entre versions

 
(50 révisions intermédiaires par le même utilisateur non affichées)
Ligne 25 : Ligne 25 :
 
end
 
end
  
local tbl1,tbl2,tbl3,tbl4,tbl5,tbl6 = {},{},{},{},{},{},{}
+
local tbl = {}
 
for _, row in ipairs(result) do
 
for _, row in ipairs(result) do
if row['dateDebut'] and row['dateDebut'] ~= '' then
+
row['annee'] = tonumber(row['annee'])
if row['dateFin'] and row['dateFin'] ~= '' then
 
local a =  tonumber(string.sub(row['dateDebut'],1,4)) + tonumber(string.sub(row['dateFin'],1,4))
 
row['annee'] = (a-a%2)/2
 
else
 
row['annee'] = tonumber(string.sub(row['dateDebut'],1,4))
 
end
 
elseif row['dateFin'] then
 
row['annee'] = tonumber(string.sub(row['dateFin'],1,4))
 
else
 
row['annee'] = 2018
 
end
 
 
 
if row['video'] == '' then
 
if row['video'] == '' then
 
if supports[row['idSupport']] then row['video']=supports[row['idSupport']] end
 
if supports[row['idSupport']] then row['video']=supports[row['idSupport']] end
 
end
 
end
if row['annee'] then
+
end
if row['annee'] < 1930 then
+
tbl1[#tbl1+1] = frame:expandTemplate{ title = args.template, args = row }
+
local debut = 1904
table.sort(tbl1,function(a,b) return a.anne  < b.annee end)
+
local periode,nb = 7,0
elseif  row['annee'] >= 1930 and row['annee'] < 1940 then
+
local d,f = debut,debut+periode
tbl2[#tbl2+1] =  frame:expandTemplate{ title = args.template, args = row }
+
local texte_periode = '\n <div class="collapsible"> '..  d+1 ..'-'..f .. '</div><div class="content"> '
elseif row['annee'] >= 1940 and row['annee'] < 1950 then
+
local retour, tbl = '',{''}
tbl3[#tbl3+1] =  frame:expandTemplate{ title = args.template, args = row }
+
 
elseif  row['annee'] >= 1950 and row['annee'] < 1960 then
+
for _,row in ipairs(result) do
tbl4[#tbl4+1] =  frame:expandTemplate{ title = args.template, args = row }
+
if not tbl[2] then
elseif  row['annee'] >= 1960 and row['annee'] < 1970 then
+
retour = retour .. '\n <div class="collapsible"> '.. d+1 .. '-' .. f .. '</div><div class="content"><br> '
tbl5[#tbl5+1] = frame:expandTemplate{ title = args.template, args = row }
 
else
 
    tbl6[#tbl6+1] = frame:expandTemplate{ title = args.template, args = row }
 
 
end
 
end
 +
if row['annee'] >= f + 1 then
 +
while row['annee'] > f + periode do
 +
d,f = f,f+periode
 +
end
 +
retour = retour .. table.concat(tbl,args.delimiter or '') .. '</div><br>'
 +
tbl = {}
 +
d,f = f,f+periode
 
end
 
end
end
+
tbl[#tbl+1] = frame:expandTemplate{ title = args.template, args = row }
 +
end
 +
retour = retour .. table.concat(tbl,args.delimiter or '') .. '</div><br>'
 +
 
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 .. retour .. outro
end
+
 
 +
end  
 
return p
 
return p

Version actuelle datée du 12 décembre 2018 à 19:40

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 = {}
	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 debut = 1904
	local periode,nb = 7,0
	local d,f = debut,debut+periode
	local texte_periode = '\n <div class="collapsible"> '..  d+1 ..'-'..f .. '</div><div class="content"> '
	local retour, tbl = '',{''}

	for _,row in ipairs(result) do
		if not tbl[2] then
			retour = retour .. '\n <div class="collapsible"> '.. d+1 .. '-' .. f .. '</div><div class="content"><br> '
		end
		if row['annee'] >= f + 1 then
			while row['annee'] > f + periode do
				d,f = f,f+periode
			end
			retour = retour .. table.concat(tbl,args.delimiter or '') .. '</div><br>'
			tbl = {}
			d,f = f,f+periode
		end
		tbl[#tbl+1] = frame:expandTemplate{ title = args.template, args = row }
	end	
	retour = retour .. table.concat(tbl,args.delimiter or '') .. '</div><br>'
	
	local intro = frame:preprocess(args.intro or '')
	local outro = frame:preprocess(args.outro or '')

	return  intro .. retour .. outro

end 
return p