Diferencia entre revisiones de «Módulo:Wikidata»

Comprobación en filtroCalificadores()
Añadido filtrado por valor de la propiedad
Línea 249: Línea 249:
else
else
return ''
return ''
end
function split(inputstr, sep)
sep=sep or '%s'
local t={}
for field,s in string.gmatch(inputstr, "([^"..sep.."]*)("..sep.."?)") do
table.insert(t,field) 
if s=="" then
return t
end
end
end
end
if (opciones.filtroCalificador ~= nil and opciones.filtroCalificador ~= '') then
if (opciones.filtroCalificador ~= nil and opciones.filtroCalificador ~= '') then
function split(inputstr, sep)
sep=sep or '%s'
local t={}
for field,s in string.gmatch(inputstr, "([^"..sep.."]*)("..sep.."?)") do
table.insert(t,field) 
if s=="" then
return t
end
end
end
local opts = split(opciones.filtroCalificador, ';')
local opts = split(opciones.filtroCalificador, ';')
tablaOrdenada = p.filtroCalificadores(tablaOrdenada, opts[1], split(opts[2], ','))
tablaOrdenada = p.filtroCalificadores(tablaOrdenada, opts[1], split(opts[2], ','))
end
if (opciones.filtroValor ~= nil and opciones.filtroValor ~= '') then
tablaOrdenada = p.filtroValores(tablaOrdenada, split(opciones.filtroValor, ','))
end
end
Línea 565: Línea 569:
end
end
if counts then -- Si uno de los valores del cualificador dio true se inserta el elemento
if counts then -- Si uno de los valores del cualificador dio true se inserta el elemento
table.insert(f, v)
end
end
return f
end
--[[ =========================================================================
Función que filtra los valores de una propiedad y devuelve solo los que
tengan uno de los valores "values" 
========================================================================= `-- ]]
function p.filtroValores(t, values)
mw.logObject(t)
local f = {}  -- Tabla que se devolverá con el resultado del filtrado
for k,v in pairs(t) do
local counts = false
if(v["mainsnak"]["datavalue"]["value"]["id"] ~= nil) then
for k2,v2 in pairs(values) do
if (v2 == v["mainsnak"]["datavalue"]["value"]["id"])then 
counts = true -- Si está marcar como true
end
end
end
if counts then -- Si uno de los valores dio true se inserta el elemento
table.insert(f, v)
table.insert(f, v)
end
end