Module:NHClothingCargoQuery
From Nookipedia, the Animal Crossing wiki
Revision as of 20:15, June 23, 2024 by PanchamBro (talk | contribs)
Module documentation (view)
Usage
This page is used to display the cargo information from cargo table nh_clothing and its dependent nh_clothing_variation.
local p = {}
local cargo = mw.ext.cargo
local getArgs = require('Module:Arguments').getArgs
local currency = require("Module:Currency")
local availability = require("Module:Availability")
local formatnum = require("Module:Formatnum")
local sentenceCase = require('Module:SentenceCase').firstToUpper
function p.main(frame)
local args = getArgs(frame)
local where = args['where'] or ''
local showVariants = args['show-variants'] or ''
local groupBy = args['group by'] or ''
local currency2 = args['show-second-currency'] or ''
local limit = args['limit'] or ''
local orderBy = args['order by'] or ''
local offset = args['offset'] or ''
local noImage = args['no image'] or ''
return p.outputClothingCargo(where, showVariants, groupBy, currency2, limit, orderBy, offset, noImage)
end
function p.outputClothingCargo(where, showVariants, groupBy, currency2, limit, orderBy, offset, noImage)
local function isEmpty(s)
return s == nil or s == ''
end
local print = ''
local disableImage = ''
local tables = 'nh_clothing,nh_clothing_variation'
local fields = "nh_clothing._pageName=pagename,nh_clothing.en_name=name,nh_clothing.catalog_num=catalognum,nh_clothing_variation.image=image,nh_clothing.buy1_price=buy1price,nh_clothing.buy1_currency=buy1currency,nh_clothing.buy2_price=buy2price,nh_clothing.buy2_currency=buy2currency,nh_clothing.sell=sell,nh_clothing.availability1=availability1,nh_clothing.availability2=availability2,nh_clothing.style1=style1,nh_clothing.style2=style2,nh_clothing.label1=label1,nh_clothing.label2=label2,nh_clothing.label3=label3,nh_clothing.label4=label4,nh_clothing.label5=label5"
local args = {
join = 'nh_clothing_variation.en_name = nh_clothing.en_name',
where = where,
groupBy = groupBy,
orderBy = orderBy,
limit = limit,
offset = offset,
default = ''
}
if not isEmpty(noImage) then
disableImage = "yes"
end
local results = cargo.query( tables, fields, args )
for r = 1, #results do
local toAppend = ''
toAppend = toAppend .. "| data-sort-value=\"" .. results[r].catalognum .. "\" | "
if not isEmpty(results[r].catalognum) then
toAppend = toAppend .. formatnum.formatNum(results[r].catalognum,"en")
else
toAppend = toAppend .. "-"
end
toAppend = toAppend .. "\n"
toAppend = toAppend .. "| [[" .. results[r].pagename .. "|" .. sentenceCase(results[r].name) .. "]]"
if not isEmpty(showVariants) and not isEmpty(results[r].variation) then
toAppend = toAppend .. " (".. results[r].variation .. ")"
end
toAppend = toAppend .. "\n"
toAppend = toAppend .. "| [[File:" .. results[r].image .. "|64px|" .. results[r].name .. "]]\n"
toAppend = toAppend .. "| data-sort-value=\"" .. results[r].buy1price .. "\" | "
if not isEmpty(results[r].buy1price) then
toAppend = toAppend .. currency.outputCurrency(results[r].buy1currency,results[r].buy1price, '', '', '', '', '', disableImage)
if not isEmpty(currency2) and not isEmpty(results[r].buy2price) then
toAppend = toAppend .. "<br>" .. currency.outputCurrency(results[r].buy2currency,results[r].buy2price, '', '', '', '', '', disableImage)
end
else
toAppend = toAppend .. "Not for sale"
end
toAppend = toAppend .. "\n"
toAppend = toAppend .. "| data-sort-value=\"" .. results[r].sell .. "\" | "
if not isEmpty(results[r].sell) then
toAppend = toAppend .. currency.outputCurrency("Bells",results[r].sell, '', '', '', '', '', disableImage)
else
toAppend = toAppend .. "Cannot be sold"
end
toAppend = toAppend .. "\n"
toAppend = toAppend .. "| " .. availability.outputAvailability(results[r].availability1, '', '', '', '', '', '', '', disableImage)
if not isEmpty(results[r].availability2) then
toAppend = toAppend .. " " .. availability.outputAvailability(results[r].availability2, '', '', '', '', '', '', '', disableImage)
end
if not isEmpty(results[r].availability3) then
toAppend = toAppend .. " " .. availability.outputAvailability(results[r].availability3)
end
toAppend = toAppend .. "\n"
toAppend = toAppend .. "| "
if not isEmpty(results[r].style1) then
toAppend = toAppend .. results[r].style1
if not isEmpty(results[r].style2) then
toAppend = toAppend .. '<br>' .. results[r].style2
end
end
toAppend = toAppend .. "\n"
toAppend = toAppend .. "| "
if not isEmpty(results[r].label1) then
toAppend = toAppend .. results[r].label1
if not isEmpty(results[r].label2) then
toAppend = toAppend .. " / " .. results[r].label2
end
if not isEmpty(results[r].label3) then
toAppend = toAppend .. " / " .. results[r].label3
end
if not isEmpty(results[r].label4) then
toAppend = toAppend .. " / " .. results[r].label4
end
if not isEmpty(results[r].label5) then
toAppend = toAppend .. " / " .. results[r].label5
end
else
toAppend = toAppend .. "-"
end
toAppend = toAppend .. "\n"
print = print .. toAppend .. "|-\n"
end
return print
end
return p