Module:Songs: Difference between revisions

Jump to navigation Jump to search
177 bytes added ,  Thursday at 01:03
no edit summary
mNo edit summary
No edit summary
Line 64: Line 64:
local results = cargo.query('Album_Songs', table.concat(fields, ','), query)
local results = cargo.query('Album_Songs', table.concat(fields, ','), query)


local rows = {}
local groups = {}
local rowspans = {}
for _, result in ipairs(results) do
for _, row in ipairs(results) do
local singers = mw.text.split(result.singers, ",")
local singers = mw.text.split(row.singers, ",")


local type = nil
local type = nil
if row.type == "solover" then
if result.type == "solover" then
type = "'''" .. horseName .. " ver.'''"
type = "'''" .. horseName .. " ver.'''"
elseif #singers == 1 then
elseif #singers == 1 then
type = "'''Solo'''"
type = "'''Solo'''"
elseif not row.type then
elseif not result.type then
type = "Group"
type = "Group"
end
end


if type ~= nil then
if type ~= nil then
table.insert(rows, { song = row.song_title, album = row.album, type = type })
if not groups[result.song_title] then groups[result.song_title] = {} end
rowspans[row.song_title] = (rowspans[row.song_title] or 0) + 1
table.insert(groups[result.song_title], { album = result.album, type = type })
end
end
end
end


local text = '{| class="wikitable sortable mw-collapsible"\n! Song !! Album !! Type\n'
local text = '{| class="wikitable sortable mw-collapsible"\n! Song !! Album !! Type\n'
for _, row in ipairs(rows) do
for song, rows in ipairs(groups) do
local rowspan = #rows
local head = table.remove(rows, 1)
text = text ..
text = text ..
string.format('|-\n| rowspan=%d|[[%s]] || [[%s]] || %s\n', rowspans[row.song], row.song, row.album, row.type)
string.format('|-\n| rowspan=%d|[[%s]] || [[%s]] || %s\n', rowspan, song, head.album, head.type)
for _, row in ipairs(rows) do
text = text ..
string.format('|-\n| [[%s]] || %s\n', row.album, row.type)
end
end
end
text = text .. '|}'
text = text .. '|}'

Navigation menu