Module:Event story chapters: Difference between revisions

From Sekaipedia
Content added Content deleted
mNo edit summary
(more formatting)
Line 5: Line 5:


local p = {}
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 chapter and pageName and chapterName then
return string.format('[[%s|%s: %s]]', pageName, chapter, chapterName)
end

return nil
end


local function formatCharacters(characters)
local function formatCharacters(characters)
Line 37: Line 53:
characters
characters
]])
]])
:addWhere('event_id', '=', event_id)
:addWhere('event_id', '=', eventId)


local results = qb:query()
local results = qb:query()
Line 47: Line 63:
root:tag('tr')
root:tag('tr')
:tag('td')
:tag('td')
:wikitext(row.image)
:wikitext(formatImage(row.image))
:done()
:done()
:tag('td')
:tag('td')
:wikitext(row.chapter)
:wikitext(formatChapter(
:wikitext(row._pageName)
row.chapter,
:wikitext(row.english)
row._pageName,
row.english
))
:done()
:done()
:tag('td')
:tag('td')

Revision as of 08:51, 16 April 2022

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 chapter and pageName and chapterName then
		return string.format('[[%s|%s: %s]]', pageName, chapter, chapterName)
	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,
			characters
		]])
		:addWhere('event_id', '=', eventId)

	local results = qb:query()
	
	local root = mw.html.create('table')
		:addClass('wikitable')
	
	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
				))
				:done()
			:tag('td')
				:wikitext(formatCharacters(row.characters))
				:done()
	end
	
	return tostring(root)
end

return p
Cookies help us deliver our services. By using our services, you agree to our use of cookies.