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

Module:Gacha datatable: Difference between revisions

From Sekaipedia
Content added Content deleted
m (second sort for ties)
No edit summary
 
(11 intermediate revisions by the same user not shown)
Line 2: Line 2:
local DatatableBuilder = require('Module:DatatableBuilder')
local DatatableBuilder = require('Module:DatatableBuilder')
local QueryBuilder = require('Module:QueryBuilder')
local QueryBuilder = require('Module:QueryBuilder')

local DisplayFns = require('Module:DisplayFunctions')
local ProcessingFns = require('Module:ProcessingFunctions')


local p = {}
local p = {}

local function formatLogo(logo)
if logo then
return string.format('[[File:%s|192px]]', logo)
end
return nil
end


local function formatName(pageName, gachaName)
local function formatName(pageName, gachaName)
Line 18: Line 13:


local function formatRateUp(ids)
local function formatRateUp(ids)
if ids and ids ~= nil then
if ids == nil then return nil end
local qb = QueryBuilder.new()
local qb = QueryBuilder.new()
qb
qb
:setTables('Cards')
:setTables('cards')
:setFields([[
:setFields([[
_pageName,
thumbnail
_pageName,
]])
thumbnail
]])
:addWhereList('card_id', '=', ids, ',', 'OR')
:setOrderBy('card_id ASC')
:addWhereList('card_id', '=', ids, ',', 'OR')
:setOrderBy('card_id ASC')
local results = qb:query()
if results and #results > 0 then
local content = ''
for _, card in ipairs(results) do
local results = qb:query()
content = content .. string.format(
'[[File:%s|80px|link=%s]] ',
if results and #results > 0 then
card.thumbnail,
local content = ''
card._pageName
)
for _, card in ipairs(results) do
content = content .. string.format(
'[[File:%s|80px|link=%s]] ',
card.thumbnail,
card._pageName
)
end
return content
end
end
end
local wrapper = mw.html.create('div')
wrapper
:css({
['display'] = 'flex',
['flex-wrap'] = 'wrap',
['gap'] = '5px'
})
:wikitext(content)
return nil
return tostring(wrapper)
end
end
end


Line 52: Line 54:
function p.main(frame)
function p.main(frame)
local args = getArgs(frame)
local args = getArgs(frame)
local columns = args['columns']
local qb = QueryBuilder.new()
local qb = QueryBuilder.new()
qb
qb
:setTables('Gachas, Gacha_Rate_Up')
:setTables('gachas, gacha_rate_up')
:setFields([[
:setFields([[
Gachas._pageName,
gachas._pageName,
Gachas.gacha_name,
gachas.gacha_name,
Gachas.logo,
gachas.logo,
DATE_FORMAT(DATE_ADD(Gachas.start, INTERVAL 9 HOUR), "%Y/%m/%d, %H:%i JST") = start,
DATE_FORMAT(DATE_ADD(gachas.start_date, INTERVAL 9 HOUR), "%Y/%m/%d, %H:%i JST") = start_date,
DATE_FORMAT(DATE_ADD(Gachas.end, INTERVAL 9 HOUR), "%Y/%m/%d, %H:%i JST") = end,
DATE_FORMAT(DATE_ADD(gachas.end_date, INTERVAL 9 HOUR), "%Y/%m/%d, %H:%i JST") = end_date,
gachas.seal,
Gacha_Rate_Up.ids
gacha_rate_up.ids
]])
]])
:setJoinOn('Gachas._pageID = Gacha_Rate_Up._pageID')
:setJoinOn('gachas._pageID = gacha_rate_up._pageID')
:addWhere('Gachas.gacha_id', '>', 0)
:addWhere('gachas.gacha_id', '>', 0)
:setOrderBy('Gachas.start ASC, Gachas.gacha_id ASC')
:setOrderBy('gachas.start_date ASC, gachas.gacha_id ASC')
:setGroupBy('Gachas._pageName')
:setGroupBy('gachas._pageName')
:setLimit(200)
:setLimit(200)
qb
qb
:addWhere('start', '<', args['start before'])
:addWhere('start_date', '<', args['start before'])
:addWhere('start', '>', args['start after'])
:addWhere('start_date', '>', args['start after'])
:addWhere('end', '<', args['end before'])
:addWhere('end_date', '<', args['end before'])
:addWhere('end', '>', args['end after'])
:addWhere('end_date', '>', args['end after'])
:addWhereList(
'gacha_type',
'=',
args['type'],
',',
'OR'
)
:addWhereList(
'seal',
'=',
args['seal'],
',',
'OR'
)
local datatable = DatatableBuilder.new()
local datatable = DatatableBuilder.new()
Line 81: Line 100:
name = 'logo',
name = 'logo',
header = 'Logo',
header = 'Logo',
dataFields = { 'Gachas.logo' },
dataFields = { 'gachas.logo' },
func = formatLogo,
fn = DisplayFns.image('192px'),
css = { ['width'] = '192px' },
css = { ['width'] = '192px' },
sortable = false
sortable = false
Line 89: Line 108:
name = 'name',
name = 'name',
header = 'Gacha',
header = 'Gacha',
dataFields = { 'Gachas._pageName', 'Gachas.gacha_name' },
dataFields = { 'gachas._pageName', 'gachas.gacha_name' },
func = formatName
fn = formatName,
css = { ['min-width'] = '150px' },
},
},
{
{
name = 'start',
name = 'start',
header = 'Start date',
header = 'Start date',
dataFields = { 'start' },
dataFields = { 'start_date' },
css = { ['white-space'] = 'nowrap' }
css = { ['white-space'] = 'nowrap' },
visible = false
},
},
{
{
name = 'end',
name = 'end',
header = 'End date',
header = 'End date',
dataFields = { 'end' },
dataFields = { 'end_date' },
css = { ['white-space'] = 'nowrap' }
css = { ['white-space'] = 'nowrap' },
visible = false
},
{
name = 'seal',
header = 'Seal type',
dataFields = { 'gachas.seal' },
visible = false
},
},
{
{
name = 'rate up',
name = 'rate up',
header = 'Rate up cards',
header = 'Rate up cards',
dataFields = { 'Gacha_Rate_Up.ids' },
dataFields = { 'gacha_rate_up.ids' },
func = formatRateUp,
fn = formatRateUp,
default = ''
default = '',
css = { ['min-width'] = '275px' },
visible = false
}
}
}
}
:setData(qb:query())
:setData(qb:query())
columns = ProcessingFns.stringToArray(',')(columns)
if columns and #columns > 0 then
for _, column in ipairs(columns) do
datatable:setColumnVisibility(column, true)
end
end
return datatable:tostring()
return datatable:tostring()

end
end



Latest revision as of 15:14, 2 May 2023


To generate {{Gacha datatable}}, invoke using the main function.


local getArgs          = require('Module:Arguments').getArgs
local DatatableBuilder = require('Module:DatatableBuilder')
local QueryBuilder     = require('Module:QueryBuilder')

local DisplayFns    = require('Module:DisplayFunctions')
local ProcessingFns = require('Module:ProcessingFunctions')

local p = {}

local function formatName(pageName, gachaName)
	return string.format('[[%s|%s]]', pageName, gachaName)
end

local function formatRateUp(ids)
	if ids == nil then return nil end
	
	local qb = QueryBuilder.new()
	qb
		:setTables('cards')
		:setFields([[
			_pageName,
			thumbnail
		]])
		:addWhereList('card_id', '=', ids, ',', 'OR')
		:setOrderBy('card_id ASC')
	
	local results = qb:query()
	
	if results and #results > 0 then
		local content = ''
		
		for _, card in ipairs(results) do
			content = content .. string.format(
				'[[File:%s|80px|link=%s]] ',
				card.thumbnail,
				card._pageName
			)
		end
		
		local wrapper = mw.html.create('div')
		wrapper
			:css({
				['display'] = 'flex',
				['flex-wrap'] = 'wrap',
				['gap'] = '5px'
			})
			:wikitext(content)
	
		return tostring(wrapper)
	end
end


function p.main(frame)
	local args = getArgs(frame)
	
	local columns = args['columns']	
	
	local qb = QueryBuilder.new()
	qb
		:setTables('gachas, gacha_rate_up')
		:setFields([[
			gachas._pageName,
			gachas.gacha_name,
			gachas.logo,
			DATE_FORMAT(DATE_ADD(gachas.start_date, INTERVAL 9 HOUR), "%Y/%m/%d, %H:%i JST") = start_date,
			DATE_FORMAT(DATE_ADD(gachas.end_date, INTERVAL 9 HOUR), "%Y/%m/%d, %H:%i JST") =  end_date,
			gachas.seal,
			gacha_rate_up.ids
		]])
		:setJoinOn('gachas._pageID = gacha_rate_up._pageID')
		:addWhere('gachas.gacha_id', '>', 0)
		:setOrderBy('gachas.start_date ASC, gachas.gacha_id ASC')
		:setGroupBy('gachas._pageName')
		:setLimit(200)
	qb
   		:addWhere('start_date', '<', args['start before'])
		:addWhere('start_date', '>', args['start after'])
		:addWhere('end_date', '<', args['end before'])
		:addWhere('end_date', '>', args['end after'])
		:addWhereList(
			'gacha_type',
			'=',
			args['type'],
			',',
			'OR'
		)
		:addWhereList(
			'seal',
			'=',
			args['seal'],
			',',
			'OR'
		)
        
	local datatable = DatatableBuilder.new()
	datatable
		:setColumns{
			{ 
				name = 'logo',
				header = 'Logo',
				dataFields = { 'gachas.logo' },
				fn = DisplayFns.image('192px'),
				css = { ['width'] = '192px' },
				sortable = false
			},
			{
				name = 'name',
				header = 'Gacha',
				dataFields = { 'gachas._pageName', 'gachas.gacha_name' },
				fn = formatName,
				css = { ['min-width'] = '150px' },
			},
			{
				name = 'start',
				header = 'Start date',
				dataFields = { 'start_date' },
				css = { ['white-space'] = 'nowrap' },
				visible = false
			},
			{
				name = 'end',
				header = 'End date',
				dataFields = { 'end_date' },
				css = { ['white-space'] = 'nowrap' },
				visible = false
			},
			{
				name = 'seal',
				header = 'Seal type',
				dataFields = { 'gachas.seal' },
				visible = false
			},
			{
				name = 'rate up',
				header = 'Rate up cards',
				dataFields = { 'gacha_rate_up.ids' },
				fn = formatRateUp,
				default = '',
				css = { ['min-width'] = '275px' },
				visible = false
			}
		}
		:setData(qb:query())
		
	columns = ProcessingFns.stringToArray(',')(columns)
	if columns and #columns > 0 then
		for _, column in ipairs(columns) do
			datatable:setColumnVisibility(column, true)
		end
	end
	
	return datatable:tostring()
end

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