Documentation for this module may be created at Module:Event datatable/doc
local getArgs = require('Module:Arguments').getArgs
local DatatableBuilder = require('Module:DatatableBuilder')
local QueryBuilder = require('Module:QueryBuilder')
local icons = require('Module:Icons')._main
local p = {}
local function formatLogo(logo)
return string.format('[[File:%s|192px]]', logo)
end
local function formatName(pageName, eventName)
return string.format('[[%s|%s]]', pageName, eventName)
end
local function formatUnit(unit)
if unit and unit ~= 'Mixed' then
return string.format(
'%s %s',
icons({ unit, size = '25px' }),
unit
)
end
return unit
end
local function formatDuration(start_dt, end_dt)
if start_dt and end_dt then
return string.format(
'Start: %s <br> End: %s',
start_dt,
end_dt
)
end
end
local function formatCharacters(characters)
local characters = mw.text.split(characters, ',')
local icon_tbl = {}
for _,x in ipairs(characters) do
local _icon = icons({ mw.text.trim(x), size = '45px' })
if _icon then
table.insert(icon_tbl, _icon)
end
end
return table.concat(icon_tbl, '<br>')
end
local function formatAttribute(attribute)
if attribute then
return string.format(
'%s %s',
icons({ attribute, size = '25px' }),
attribute
)
end
end
function p.main(frame)
local args = getArgs(frame)
local qb = QueryBuilder.new()
qb
:setTables('Events')
:setFields([[
event_id,
_pageName,
image,
event_name,
DATE_FORMAT(DATE_ADD(start, INTERVAL 9 HOUR), "%Y/%m/%d, %H:%i JST") = start,
DATE_FORMAT(DATE_ADD(end, INTERVAL 9 HOUR), "%Y/%m/%d, %H:%i JST") = end,
unit_focus,
type,
characters,
attribute
]])
:addWhere('event_id', '>', 0)
:setOrderBy('event_id ASC')
:setGroupBy('_pageName')
:setLimit(200)
qb
:addWhere('type', '=', args['type'])
:addWhere('start', '<', args['start before'])
:addWhere('start', '>', args['start after'])
:addWhere('end', '<', args['end before'])
:addWhere('end', '>', args['end after'])
local datatable = DatatableBuilder.new()
datatable
:setColumns{
{ name = 'id', header = 'ID', data_fields = { 'event_id' } },
{ name = 'logo', header = 'Logo', data_fields = { 'image' }, func = formatLogo },
{ name = 'name', header = 'Event', data_fields = { '_pageName', 'event_name' }, func = formatName },
{ name = 'unit', header = 'Unit focus', data_fields = { 'unit_focus' }, func = formatUnit },
{ name = 'duration', header = 'Event period', data_fields = { 'start', 'end' }, func = formatDuration },
{ name = 'characters', header = 'Bonus characters', data_fields = { 'characters' }, func = formatCharacters },
{ name = 'attribute', header = 'Bonus attribute', data_fields = { 'attribute' }, func = formatAttribute },
{ name = 'type', header = 'Type', data_fields = { 'type' } },
}
:setHeaders{
'id',
'logo',
'name',
'unit',
'duration',
'characters',
'attribute',
'type'
}
:setData(qb:query())
return datatable:tostring()
end
return p