Module:Unit/MementoList

local p = {} local h = {}

local cargo = require('Module:CargoUtil') local render_memento_icon = require('Module:Render/Memento')._icon local model = require('Module:Data').model

function p.relatedMementoList(frame) local args = require('Module:Arguments').getArgs(frame, {		parentFirst = true,	}) local iname = args[1] return p._relatedMementoList(iname) end

function p._relatedMementoList(iname) if not iname then return 'Invalid parameter' end local data = mw.loadData("Module:Data/Extra/UnitMementoList") local mementoList = data[iname] if not mementoList then return '' end local output = {} local inames = {} for entry, count in pairs( mementoList ) do		inames[#inames+1] = entry end local rows = h.getMementos(inames) for i, memData in ipairs(rows) do		local icon = render_memento_icon{data=memData, size=64} table.insert(output, icon) end return ('== Related Mementos ==\n\n '..table.concat(output, ' ')..' ') end

function h.getMementos(inames) local rows = cargo.query{ tables = {'ConceptCard=CC', 'ConceptCardLoc=CCLoc', 'Pages'}, join = { 'CC.iname = Pages.iname', 'CC.iname = CCLoc.iname', },		fields = { 'Pages._pageName = _pageName', 'CC.iname = iname', 'CC.server = server', 'CC.rare = rare', 'CC.icon = icon', 'CCLoc.name = name', },		where = { 'Pages.type = "Memento"', ('CC.iname IN ("%s")'):format(table.concat(inames, '","')), 'CC.server = "gl"', 'CCLoc.lang = "english"', },	}	return rows end

return p