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

Module:Infobox virtual live: Difference between revisions

From Sekaipedia
Content added Content deleted
mNo edit summary
(add stamp id)
Line 93: Line 93:


local function formatStampId(id)
local function formatStampId(id)
local qb = QueryBuilder.new()
qb
:setTables('Stamps')
:setFields([[
image,
japanese,
english
]])
:setLimit(1)
:addWhere('event_id', '=', id)
local result = qb:query()[1]
if result then
return string.format('[[File:%s]]<br>%s<br>%s', result.image, result.english, result.japanese)
end
return nil
end
end


Line 176: Line 193:
},
},
{ hideIfEmpty = { 'stamp' } }
{ hideIfEmpty = { 'stamp' } }
)
:addRow(
{
{ tag = 'argtd', content = 'stamp id' },
},
{ hideIfEmpty = { 'stamp id' } }
)
)
:addHeader(
:addHeader(

Revision as of 05:15, 27 March 2022

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


--------------------------
-- Module for [[Template:Infobox virtual live]]
------------------------
local getArgs   = require('Module:Arguments').getArgs
local InfoboxBuilder = require('Module:InfoboxBuilder new')
local QueryBuilder   = require('Module:QueryBuilder')
local utils  = require('Module:Utilities')
local icons  = require('Module:Icons')._main
local cargo  = mw.ext.cargo

local p = {}
local categories = ""

local function splitStringWithDelim(delim)
	return function(str)
		if str == nil then
			return nil
		end
		
		local list = mw.text.split(str, delim)
		for i=1,#list do
			list[i] = mw.text.trim(list[i])
		end
		
		return list
	end
end

local function formatList(list)
	if #list < 2 then
		return list[1]
	end
	
	local ul = mw.html.create('ul')
	
	for i=1,#list do
		ul:tag('li')
			:wikitext(list[i])
	end
	
	return tostring(ul)
end

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

local function formatRewardImage(image_name)
	return string.format("[[File:%s|150px]]", 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 qb = QueryBuilder.new()
	qb
		:setTables('Songs')
		:setFields([[
			_pageName,
			song_name,
		]])
		:setGroupBy('_pageName')
		:addWhereList('song_id', '=', song_ids, ',', '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 formatList(resArr)
	end
	
	return nil
end

local function formatStampId(id)
	local qb = QueryBuilder.new()
	qb
		:setTables('Stamps')
		:setFields([[
			image,
			japanese,
			english
		]])
		:setLimit(1)
		:addWhere('event_id', '=', id)
	
		local result = qb:query()[1]
	
	if result then
		return string.format('[[File:%s]]<br>%s<br>%s', result.image, result.english, result.japanese)
	end
	
	return nil
end

local function formatTitleId(id)
	
end


function p.main(frame)
	local args = getArgs(frame)
	local infobox = InfoboxBuilder.new()
	
	infobox:setName('Infobox virtual live')
		:setParams{
			{ name = 'vlive id' },
			{ name = 'vlive name', default = mw.title.getCurrentTitle().text },
			{ name = 'image', dFunc = formatImage },
			{ name = 'japanese' },
			{ name = 'romaji' },
			{ name = 'from' },
			{ name = 'until' },
			{ name = 'characters', dFunc = formatCharacters },
			{ name = 'song ids', dFunc = formatSongs },
			{ name = 'stamp', dFunc = formatRewardImage },
			{ name = 'title', dFunc = formatRewardImage },
		}
		:setArgs(args)
		:processArgs()

	infobox
		:addHeader({ tag = 'argth', content = 'vlive name' })
		:addImage({
			{ tag = 'argtd', content = 'image' },
		})
		: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 = 'Availability Period' }, { subheader = true })
		:addRow(
			{
				{ tag = 'th', content = 'From' },
				{ tag = 'argtd', content = 'from' }
			}
		)
		:addRow(
			{
				{ tag = 'th', content = 'Until' },
				{ tag = 'argtd', content = 'until' }
			}
		)
		:addHeader({ tag = 'th', content = 'Virtual Live Information' }, { subheader = true })
		:addRow(
			{
				{ tag = 'th', content = 'Featured characters ' },
				{ tag = 'argtd', content = 'characters' }
			}
		)
		:addRow(
			{
				{ tag = 'th', content = 'Featured songs' },
				{ tag = 'argtd', content = 'song ids' }
			}
		)
		:addHeader(
			{ tag = 'th', content = 'Reward Stamp' },
			{ hideIfEmpty = { 'stamp' }, subheader = true }
		)
		:addImage(
			{
				{ tag = 'argtd', content = 'stamp' },
			},
			{ hideIfEmpty = { 'stamp' } }
		)
		:addRow(
			{
				{ tag = 'argtd', content = 'stamp id' },
			},
			{ hideIfEmpty = { 'stamp id' } }
		)
		:addHeader(
			{ tag = 'th', content = 'Reward Title' },
			{ hideIfEmpty = { 'title' }, subheader = true }
		)
		:addImage(
			{
				{ tag = 'argtd', content = 'title' },
			},
			{ hideIfEmpty = { 'title' } }
		)

	if mw.title.getCurrentTitle().namespace == 0 then
		categories = "[[Category:Virtual lives]]" .. infobox:getCategories()
	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.