This module depends on the following other modules: |
To generate {{Gacha datatable}}, invoke using the main function.
local getArgs = require('Module:Arguments').getArgs
local DatatableBuilder = require('Module:DatatableBuilder')
local QueryBuilder = require('Module:QueryBuilder')
local DisplayFns = require('Module:DisplayFunctions')
local ProcessingFns = require('Module:ProcessingFunctions')
local p = {}
local function formatName(pageName, gachaName)
return string.format('[[%s|%s]]', pageName, gachaName)
end
local function formatRateUp(ids)
if ids == nil then return nil end
local qb = QueryBuilder.new()
qb
:setTables('cards')
:setFields([[
_pageName,
thumbnail
]])
:addWhereList('card_id', '=', ids, ',', 'OR')
:setOrderBy('card_id ASC')
local results = qb:query()
if results and #results > 0 then
local content = ''
for _, card in ipairs(results) do
content = content .. string.format(
'[[File:%s|80px|link=%s]] ',
card.thumbnail,
card._pageName
)
end
local wrapper = mw.html.create('div')
wrapper
:css({
['display'] = 'flex',
['flex-wrap'] = 'wrap',
['gap'] = '5px'
})
:wikitext(content)
return tostring(wrapper)
end
end
function p.main(frame)
local args = getArgs(frame)
local columns = args['columns']
local qb = QueryBuilder.new()
qb
:setTables('gachas, gacha_rate_up')
:setFields([[
gachas._pageName,
gachas.gacha_name,
gachas.logo,
DATE_FORMAT(DATE_ADD(gachas.start_date, INTERVAL 9 HOUR), "%Y/%m/%d, %H:%i JST") = start_date,
DATE_FORMAT(DATE_ADD(gachas.end_date, INTERVAL 9 HOUR), "%Y/%m/%d, %H:%i JST") = end_date,
gachas.seal,
gacha_rate_up.ids
]])
:setJoinOn('gachas._pageID = gacha_rate_up._pageID')
:addWhere('gachas.gacha_id', '>', 0)
:setOrderBy('gachas.start_date ASC, gachas.gacha_id ASC')
:setGroupBy('gachas._pageName')
:setLimit(200)
qb
:addWhere('start_date', '<', args['start before'])
:addWhere('start_date', '>', args['start after'])
:addWhere('end_date', '<', args['end before'])
:addWhere('end_date', '>', args['end after'])
:addWhereList(
'gacha_type',
'=',
args['type'],
',',
'OR'
)
:addWhereList(
'seal',
'=',
args['seal'],
',',
'OR'
)
local datatable = DatatableBuilder.new()
datatable
:setColumns{
{
name = 'logo',
header = 'Logo',
dataFields = { 'gachas.logo' },
fn = DisplayFns.image('192px'),
css = { ['width'] = '192px' },
sortable = false
},
{
name = 'name',
header = 'Gacha',
dataFields = { 'gachas._pageName', 'gachas.gacha_name' },
fn = formatName,
css = { ['min-width'] = '150px' },
},
{
name = 'start',
header = 'Start date',
dataFields = { 'start_date' },
css = { ['white-space'] = 'nowrap' },
visible = false
},
{
name = 'end',
header = 'End date',
dataFields = { 'end_date' },
css = { ['white-space'] = 'nowrap' },
visible = false
},
{
name = 'seal',
header = 'Seal type',
dataFields = { 'gachas.seal' },
visible = false
},
{
name = 'rate up',
header = 'Rate up cards',
dataFields = { 'gacha_rate_up.ids' },
fn = formatRateUp,
default = '',
css = { ['min-width'] = '275px' },
visible = false
}
}
:setData(qb:query())
columns = ProcessingFns.stringToArray(',')(columns)
if columns and #columns > 0 then
for _, column in ipairs(columns) do
datatable:setColumnVisibility(column, true)
end
end
return datatable:tostring()
end
return p