Module:Fonctions

De Mythemes

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

local p = {}

function p.ListeMythemes(frame)
	local liste = ''
	local tables = 'Analyses1'
	local fields = 'mytheme'
	local arguments = {
		where='oeuvre="' .. string.gsub(frame.args[1],'_',' ') .. '"',
		groupBy='mytheme',
		orderBy='mytheme',
		limit=1000,
		intro=''
	}
	local result = mw.ext.cargo.query(tables, fields, arguments)
	for _,row in ipairs(result) do
		liste = liste .. ';' .. row['mytheme']
	end
	return liste
end

function p.Last(str,sep)
	return string.gsub(str,'(.*' .. sep .. ')',"")
	end

function p.ListValues(frame)
	local liste = ''
	local tables = frame.args[1]
	local fields = frame.args[2]
	local arguments = {
		where=frame.args[3] .. ' LIKE "' .. frame.args[4] .. '%"',
		groupBy=fields,
		orderBy=fields,
		limit=1000,
		intro=''
	}
	local result = mw.ext.cargo.query(tables, fields, arguments)
	for _,row in ipairs(result) do
		liste = liste .. ';' .. row[fields]
	end
	return liste
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, value in pairs(row) do
			liste = liste .. ';' .. value 
		end
	end
	liste = string.gsub(liste,'^;','')
	return liste
end

function p.cat_field(frame)
	local liste, l = '', {} 
	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 _,w in pairs(mw.text.split(row['neighbors'], ',' )) do
				w = string.gsub(w,'^%s*(.-)%s*$','%1')
				if #w > 1 then l[w]=true; end
			end
	end
	a = {}
	for u,v in pairs(l) do
		if v then table.insert(a,u) end
	    end
	table.sort(a)
			
	for i,v in ipairs(a) do 
			liste = liste .. ', ' .. '[[mytheme:' .. v .. '|' .. v .. ']]'
		end
	return string.sub(liste,3)
end


--local tables,fields,arguments = 'Mythemes','_pageName',{groupBy ='_pageName'}
--local LM = mw.ext.cargo.query(tables,fields,arguments)
--LMT = {}
--for i,j in pairs(LM) do
--	LMT[j['_pageName']] = i
--end

function p.Classe(frame)

		result = '{{#formlink:form=Trace|link type=link|link text=' .. frame.args[3] .. '|target=Traces:{{PAGEID:' .. frame.args[1] .. '}}-{{PAGEID:Ref:' .. frame.args[2] .. '}}-' .. frame.args[3] .. '|query string=Trace[mytheme]=' .. frame.args[1] .. '&Trace[oeuvre]={{urlencode:Ref:' .. frame.args[2] .. '}}&Trace[mot]=' .. frame.args[3] .. '|popup }}'

	return(result)
end

function p.Orphan(frame)
	local oeuvreId, mythemeId = frame.args[1], frame.args[2]
	local tablesO, tablesM = 'Oeuvres2', 'Mythemes2'
	local fields = '_pageName'
	local argumentsO =  {
		where='oeuvreId="' .. oeuvreId .. '"',
		groupby='_pageName',
		default='',
	}
	local argumentsM = {
		where='mythemeId="' .. mythemeId .. '"',
		groupby='_pageName',
		default='',
	}
	local oe = mw.ext.cargo.query(tablesO,fields,argumentsO)
	local my = mw.ext.cargo.query(tablesM,fields,argumentsM)
	
	
	return #oe + #my
	
	

	
end

local per = {
	["X"] = 900,
	["XI"] = 1000
	}


function p.Borne_basse(frame)
	local mod = {
		["Première moitié"] = 0,
		["Deuxième moitié"] = 50,
		["Premier tiers"] = 0,
		["Deuxième tiers"] = 33,
		["Troisième tiers"] = 66
	}
	if frame.args[2] and mod[frame.args[2]] then
		return per[frame.args[1]] + mod[frame.args[2]]
	else
		return per[frame.args[1]]
	end
end

function p.Borne_haute(frame)
	local mod = {
		["Première moitié"] = 50,
		["Deuxième moitié"] = 0,
		["Premier tiers"] = 66,
		["Deuxième tiers"] = 33,
		["Troisième tiers"] = 0
	}
	if frame.args[2] and mod[frame.args[2]] then
		return per[frame.args[1]] - mod[frame.args[2]] + 99
	else
		return per[frame.args[1]] + 99
	end
end

return p