Jump to content

Module:KnowledgeLinks

From Conan Exiles Wiki
Revision as of 18:41, 14 July 2023 by imported>Testerle
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Documentation for this module may be created at Module:KnowledgeLinks/doc

local util_args = require("Module:ArgsUtil")
local util_cache = require("Module:CacheUtil")
local util_vars = require("Module:VarsUtil")
local cache = require('mw.ext.LuaCache')
local PREFIX = 'ITEMLINK_04'
local lang = mw.getLanguage('en')

local p = {}
local h = {}
local cargo = mw.ext.cargo

function p.KnowledgeLinks(frame)
	local args = util_args.mergeKeepEmpty()
	local inpItemid = tonumber(args[1])
	
	local text = ""
	
	local tables = 'Item,Recipes'
	local fields = 'Recipes._pageName,Recipes.name'
	local query = {
		join = 'Item.knowledge HOLDS Recipes.id',
		where = 'Item.id = ' .. inpItemid .. ' ',
		groupBy = 'Recipes._pageName,Recipes.name'
	}
	
	local result = cargo.query( tables, fields, query )
	if not result then
		return ''
	end
	
	for k, row in ipairs(result) do
		if text ~= "" then
			text = text .. ", "	
		end
		text = text .. "[[" .. row["Recipes._pageName"] .. "|" .. row["Recipes.name"] .. "]]"
	end
	
	return text
end

return p