Documentation for this module may be created at Module:Event story chapters/doc
local getArgs = require('Module:Arguments').getArgs
local QueryBuilder = require('Module:QueryBuilder')
local utils = require('Module:Utilities')
local cicon = require('Module:Character icon')._main
local p = {}
local function formatImage(image)
if image then
return string.format('[[File:%s|125px]]', image)
end
return nil
end
local function formatChapter(chapter, pageName, chapterName)
if pageName then
return string.format(
'[[%s|Chapter %s: %s]]',
pageName,
chapter or '?',
chapterName or '?'
)
end
return nil
end
local function formatCharacters(characters)
local charArr = utils.splitWithDelim(';')(characters)
local icon_tbl = {}
if charArr then
for _,v in ipairs(charArr) do
local _icon = cicon({ v, size = '45px' })
if _icon then
table.insert(icon_tbl, _icon)
end
end
end
return table.concat(icon_tbl, ' ')
end
function p.main(frame)
local args = getArgs(frame)
local eventId = args['event id']
local qb = QueryBuilder.new()
qb
:setTables('event_story_chapters')
:setFields([[
image,
chapter,
_pageName,
english,
japanese,
characters
]])
:addWhere('event_id', '=', eventId)
local results = qb:query()
local root = mw.html.create('table')
:addClass('wikitable')
root:tag('tr')
:tag('th')
:wikitext('Image')
:done()
:tag('th')
:wikitext('Chapter')
:done()
:tag('th')
:wikitext('Featured characters')
:done()
for _,row in ipairs(results) do
root:tag('tr')
:tag('td')
:wikitext(formatImage(row.image))
:done()
:tag('td')
:wikitext(formatChapter(
row.chapter,
row._pageName,
row.english or row.japanese
))
:done()
:tag('td')
:wikitext(formatCharacters(row.characters))
:done()
end
return tostring(root)
end
return p