Toggle menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Module:Infobox virtual live

From Sekaipedia
Revision as of 20:57, 20 October 2021 by ChaoticShadow (talk | contribs) (created vlive infobox)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

To generate {{Infobox virtual live}}, invoke using the main function.


--------------------------
-- Module for [[Template:Infobox Virtual Live]]
------------------------
local getArgs   = require('Module:Arguments').getArgs
local builder   = require('Module:InfoboxBuilder')
local utils     = require('Module:Utilities')
local icons     = require('Module:Icons')._main
local cargo     = mw.ext.cargo

local p = {}
local categories = ""

local function formatImage(image_name)
	return string.format("[[File:%s|128px]]", image_name)
end

local function formatCharacters(characters)
	local characterArr = utils.split(characters, ',')
	local resArr = {}
	for i,v in ipairs(characterArr) do
		table.insert(resArr, icons({ v, size = '30px' }))
	end
	
	return table.concat(resArr, " ")
end

local function formatSongs(song_ids)
	local idsArr = utils.split(song_ids, ',')
	local queryArr = {}
	for i,v in ipairs(idsArr) do
		table.insert(queryArr, 'song_id = ' .. v)
	end
	
	local tables = 'Songs'
	local fields = 'song_name, _pageName'
	local args = {
        where = table.concat(queryArr, " OR ")
    }
    local results = cargo.query( tables, fields, args )
	
	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 table.concat(resArr, "<br>")
	end
	
	return nil
end


function p.main(frame)
	local args = getArgs(frame)
	local infobox = builder.new()
	
	infobox:setName('Infobox Virtual Live')
		:setWidth("330px")
		:setParams{
			{ name = 'vlive id' },
			{ name = 'vlive name', default = mw.title.getCurrentTitle().text },
			{ name = 'image', func = formatImage },
			{ name = 'japanese' },
			{ name = 'romaji' },
			{ name = 'start' },
			{ name = 'end' },
			{ name = 'characters', func = formatCharacters },
			{ name = 'song ids', func = formatSongs },
			{ name = 'stamp' },
			{ name = 'title' },
		}
		:setArgs(args)
		:setHeaderColors({
			['background-color'] = '#00cdba',
			['color'] = '#000'
		})

	infobox
		:addHeader({ tag = 'argth', content = 'vlive name' })
		:addImage({
			{ tag = 'argtd', content = 'image' },
		})
		:addRow(
			{
				{ tag = 'th', content = 'Japanese', colspan = 12 },
				{ tag = 'argtd', content = 'japanese', colspan = 18 }
			},
			{ hideIfEmpty = { 'japanese' } }
		)
		:addRow(
			{
				{ tag = 'th', content = 'Romaji', colspan = 12 },
				{ tag = 'argtd', content = 'romaji', colspan = 18 }
			},
			{ hideIfEmpty = { 'romaji' } }
		)
		:addHeader({ tag = 'th', content = 'Availability Period' }, { subheader = true })
		:addRow(
			{
				{ tag = 'th', content = 'From', colspan = 12 },
				{ tag = 'argtd', content = 'start', colspan = 18 }
			}
		)
		:addRow(
			{
				{ tag = 'th', content = 'Until', colspan = 12 },
				{ tag = 'argtd', content = 'end', colspan = 18 }
			}
		)
		:addHeader({ tag = 'th', content = 'Virtual Live Information' }, { subheader = true })
		:addRow(
			{
				{ tag = 'th', content = 'Featured Characters ', colspan = 12 },
				{ tag = 'argtd', content = 'characters', colspan = 18 }
			}
		)
		:addRow(
			{
				{ tag = 'th', content = 'Featured Songs', colspan = 12 },
				{ tag = 'argtd', content = 'song ids', colspan = 18 }
			}
		)

	
	if mw.title.getCurrentTitle().namespace == 0 then
		categories = "[[Category:Virtual lives]]" .. categories
		
		local procArgs = infobox:getArgs('processed')
		local rawArgs = infobox:getArgs('raw')
	end

	return infobox:tostring() .. categories
end

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