This module depends on the following other modules: |
To generate {{Infobox connect live}}, invoke using the main function.
--------------------------
-- Module for [[Template:Infobox connect live]]
------------------------
local getArgs = require('Module:Arguments').getArgs
local InfoboxBuilder = require('Module:InfoboxBuilder')
local DisplayFns = require('Module:DisplayFunctions')
local ProcessingFns = require('Module:ProcessingFunctions')
local QueryBuilder = require('Module:QueryBuilder')
local cicon = require('Module:Character icon')._main
local p = {}
local function formatCharacters(characters)
if characters == nil then return nil end
local resArr = {}
for _,v in ipairs(characters) do
table.insert(resArr, cicon({ v, size = '30px' }))
end
return table.concat(resArr, " ")
end
local function formatSongs(songIds)
if songIds == nil or songIds == '' then return nil end
local qb = QueryBuilder.new()
qb
:setTables('Songs')
:setFields([[
_pageName,
song_name,
]])
:setGroupBy('_pageName')
:addWhereList('song_id', '=', songIds, ',', 'OR')
local results = qb:query()
if #results > 0 then
local resArr = {}
for i,v in ipairs(results) do
table.insert(
resArr,
string.format(
'[[%s|%s]]',
v._pageName,
v.song_name
)
)
end
return DisplayFns.list('unbulleted')(resArr)
end
return nil
end
local function formatPrevious(previousLive)
if previousLive and previousLive ~= '' then
return string.format('<b>← Previous</b> <br> [[%s]]', previousLive)
end
return ' '
end
local function formatNext(nextLive)
if nextLive and nextLive ~= '' then
return string.format('<b>Next →</b> <br> [[%s]] ', nextLive)
end
return ' '
end
function p.main(frame)
local args = getArgs(frame)
local infobox = InfoboxBuilder.new();
infobox:setName('Infobox connect live')
:setParams{
{ name = 'connect live name', default = mw.title.getCurrentTitle().text },
{ name = 'japanese' },
{ name = 'romaji' },
{ name = 'characters', fn = ProcessingFns.stringToArray(';') },
{ name = 'song ids' },
{ name = 'previous', default = '' },
{ name = 'next', default = '' }
}
:setArgs(args)
:processArgs()
infobox
:addHeader({ tag = 'argth', content = 'connect live name' })
:addRow(
{
{ tag = 'th', content = 'Japanese' },
{ tag = 'argtd', content = 'japanese' }
},
{ hideIfEmpty = { 'japanese' } }
)
:addRow(
{
{ tag = 'th', content = 'Romaji' },
{ tag = 'argtd', content = 'romaji' }
},
{ hideIfEmpty = { 'romaji' } }
)
:addHeader({ tag = 'th', content = 'Connect Live Information' }, { subheader = true })
:addRow(
{
{ tag = 'th', content = 'Featured characters ' },
{ tag = 'argtd', content = 'characters', fn = formatCharacters }
}
)
:addRow(
{
{ tag = 'th', content = 'Featured songs' },
{ tag = 'argtd', content = 'song ids', fn = formatSongs }
}
)
:addHeader({ tag = 'th', content = 'Chronology' }, { subheader = true })
:addRow(
{
{ tag = 'argtd', content = 'previous', fn = formatPrevious, colspan = 13 },
{ tag = 'td', content = '', colspan = 4 },
{ tag = 'argtd', content = 'next', fn = formatNext, colspan = 13 }
},
{ defaultCss = { ['text-align'] = 'center' } }
)
local categories = ""
if mw.title.getCurrentTitle().namespace == 0 then
categories = "[[Category:Connect Lives]]" .. infobox:getCategories()
end
return infobox:tostring() .. categories
end
return p