Module:Card grid

From Sekaipedia

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

local getArgs   = require('Module:Arguments').getArgs
local yesno     = require('Module:Yesno')
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 = yesno(args['show name'], false)

	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
Cookies help us deliver our services. By using our services, you agree to our use of cookies.