Toggle menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Module:Card grid

From Sekaipedia
Revision as of 08:18, 5 January 2022 by ChaoticShadow (talk | contribs)

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()

	if #results > 0 then
		for k,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.