Content added Content deleted
mNo edit summary |
mNo edit summary |
||
Line 35: | Line 35: | ||
local results = qb:query() |
local results = qb:query() |
||
local show_name = args['show name'] |
|||
if #results > 0 then |
if #results > 0 then |
||
for |
for _,v in ipairs(results) do |
||
local file = '[[File:' .. v.thumbnail .. '|center|130px]]' |
local file = '[[File:' .. v.thumbnail .. '|center|130px]]' |
||
Revision as of 08:21, 5 January 2022
Documentation for this module may be created at Module:Card grid/doc
local getArgs = require('Module:Arguments').getArgs
local QueryBuilder = require('Module:QueryBuilder')
local p = {}
function p.main(frame)
local args = getArgs(frame)
local qb = QueryBuilder.new()
qb:setTables('Cards')
:setFields([[
_pageName,
card_name,
thumbnail,
thumbnail_trained,
card_character
]])
:addWhere('Cards.card_id', '>', '0')
:setGroupBy('Cards.card_id')
qb
:setOrderBy(args['order by'] or 'Cards.card_id ASC')
:setLimit(args['limit'] or 300)
qb
:addWhereList(
'Cards.card_id',
'=',
args['ids'],
',',
'OR'
)
local root = mw.html.create('div')
:addClass('card-grid')
local results = qb:query()
local show_name = args['show name']
if #results > 0 then
for _,v in ipairs(results) do
local file = '[[File:' .. v.thumbnail .. '|center|130px]]'
if v.rarity and
v.rarity ~= '' and
(tonumber(v.rarity) == 3 or tonumber(v.rarity) == 4) then
file = file .. '[[File:' .. v.thumbnail_trained .. '|center|130px]]'
end
local box = root:tag('div')
:addClass('card-grid-item')
box:tag('div')
:css({
['display'] = 'flex',
})
:wikitext(file)
:done()
box:tag('div')
:wikitext(string.format('<b>[[%s|%s]]</b>', v._pageName, v.card_name))
:done()
if show_name then
box:tag('div')
:wikitext(string.format('[[%s]]', v.card_character))
:done()
end
end
end
return frame:extensionTag{
name = 'templatestyles', args = { src = 'Template:Card grid/styles.css' }
} .. tostring(root)
end
return p