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
(test using new infobox)
Line 3: Line 3:
------------------------
------------------------
local getArgs = require('Module:Arguments').getArgs
local getArgs = require('Module:Arguments').getArgs
local builder = require('Module:InfoboxBuilder')
local InfoboxBuilder = require('Module:InfoboxBuilder new')
local utils = require('Module:Utilities')
local QueryBuilder = require('Module:QueryBuilder')
local icons = require('Module:Icons')._main
local utils = require('Module:Utilities')
local cargo = mw.ext.cargo
local icons = require('Module:Icons')._main
local cargo = mw.ext.cargo


local p = {}
local p = {}
local categories = ""
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)
local function formatImage(image_name)
Line 30: Line 61:


local function formatSongs(song_ids)
local function formatSongs(song_ids)
local idsArr = utils.split(song_ids, ',')
local qb = QueryBuilder.new()
qb
local queryArr = {}
:setTables('Songs')
for i,v in ipairs(idsArr) do
:setFields([[
table.insert(queryArr, 'song_id = ' .. v)
_pageName,
end
song_name,
]])
:setGroupBy('_pageName')
:addWhereList('song_id', '=', song_ids, ',', 'OR')
local tables = 'Songs'
local results = qb:query()
local fields = 'song_name, _pageName'
local args = {
where = table.concat(queryArr, " OR ")
}
local results = cargo.query( tables, fields, args )
if #results > 0 then
if #results > 0 then
Line 56: Line 86:
end
end
return table.concat(resArr, "<br>")
return formatList(resArr)
end
end
return nil
return nil
end

local function formatStampId(id)
end

local function formatTitleId(id)
end
end


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


infobox
infobox
Line 91: Line 129:
:addRow(
:addRow(
{
{
{ tag = 'th', content = 'Japanese', colspan = 12 },
{ tag = 'th', content = 'Japanese' },
{ tag = 'argtd', content = 'japanese', colspan = 18 }
{ tag = 'argtd', content = 'japanese' }
},
},
{ hideIfEmpty = { 'japanese' } }
{ hideIfEmpty = { 'japanese' } }
Line 98: Line 136:
:addRow(
:addRow(
{
{
{ tag = 'th', content = 'Romaji', colspan = 12 },
{ tag = 'th', content = 'Romaji' },
{ tag = 'argtd', content = 'romaji', colspan = 18 }
{ tag = 'argtd', content = 'romaji' }
},
},
{ hideIfEmpty = { 'romaji' } }
{ hideIfEmpty = { 'romaji' } }
Line 106: Line 144:
:addRow(
:addRow(
{
{
{ tag = 'th', content = 'From', colspan = 12 },
{ tag = 'th', content = 'From' },
{ tag = 'argtd', content = 'from', colspan = 18 }
{ tag = 'argtd', content = 'from' }
}
}
)
)
:addRow(
:addRow(
{
{
{ tag = 'th', content = 'Until', colspan = 12 },
{ tag = 'th', content = 'Until' },
{ tag = 'argtd', content = 'until', colspan = 18 }
{ tag = 'argtd', content = 'until' }
}
}
)
)
Line 119: Line 157:
:addRow(
:addRow(
{
{
{ tag = 'th', content = 'Featured Characters ', colspan = 12 },
{ tag = 'th', content = 'Featured Characters ' },
{ tag = 'argtd', content = 'characters', colspan = 18 }
{ tag = 'argtd', content = 'characters' }
}
}
)
)
:addRow(
:addRow(
{
{
{ tag = 'th', content = 'Featured Songs', colspan = 12 },
{ tag = 'th', content = 'Featured Songs' },
{ tag = 'argtd', content = 'song ids', colspan = 18 }
{ tag = 'argtd', content = 'song ids' }
}
}
)
)
Line 150: Line 188:
)
)


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



Revision as of 05:10, 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)
	
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' } }
		)
		: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.