Module:EventAppearances

local cargo = mw.ext.cargo local List = require 'Module:ListUtil' local Datetime = require 'Module:DatetimeUtil' local escq = require 'Module:EscQ'.main1

local main = function (args) local unit = args[1] or mw.title.getCurrentTitle.rootText

local vg = cargo.query('VotingGauntlets', "_pageName=page,CONCAT('Voting Gauntlet: ',Name)=name,StartTime=t0,EndTime=t1", {		where = ("Heroes HOLDS '%s'"):format(escq(unit)),	}) local tb = {} -- todo local gc = cargo.query('GrandConquests=GC,GrandConquestsLeaders=GCL,Units=U', "GC._pageName=page,GC._pageName=name,StartTime=t0,EndTime=t1", {		join = 'GC._pageName=GCL._pageName,GCL.Hero=U.WikiName',		where = ("U._pageName='%s'"):format(escq(unit)),	}) local fb = cargo.query('ForgingBonds=FB,ForgingBondsHeroes=FBH,Units=U', "FB._pageName=page,CONCAT('Forging Bonds: ',FB.Name)=name,StartTime=t0,EndTime=t1", {		join = 'FB._pageName=FBH._pageName,FBH.Hero=U.WikiName',		where = ("U._pageName='%s'"):format(escq(unit)),	}) local rs = cargo.query('RokkrSieges', "_pageName=page,_pageName=name,StartTime=t0,EndTime=t1", {		where = ("Rokkrs HOLDS '%s'"):format(escq(unit)),	}) local hf = cargo.query('HallOfForms', "_pageName=page,_pageName=name,StartTime=t0,EndTime=t1", {		where = ("Forma HOLDS '%s'"):format(escq(unit)),	}) local ms = cargo.query('MjolnirsStrike', "_pageName=page,_pageName=name,StartTime=t0,EndTime=t1", {		where = ("Leader='%s'"):format(escq(unit)),	}) local fp = cargo.query('FrontlinePhalanx=FP,FrontlinePhalanx__Heroes=FPH,FrontlinePhalanx__Bosses=FPB', "_pageName=page,_pageName=name,StartTime=t0,EndTime=t1", {		join = 'FP._ID=FPH._rowID,FP._ID=FPB._rowID',		where = ("'%s' IN (FPH._value,FPB._value)"):format(escq(unit)),		groupBy = 'FP._ID',	})

local all_events = List.reduce({vg, tb, gc, fb, rs, hf, ms, fp}, List.concat_self, {}) if #all_events == 0 then return ' Event appearances This Hero has not been featured in any events.' end table.sort(all_events, function (x, y) return x.t0 < y.t0 or (x.t0 == y.t0 and x.t1 < y.t1) end)

local ul = mw.html.create('ul') for _, v in ipairs(all_events) do		local li = ul:tag('li') li:wikitext(('[%s – %s] %s'):format( os.date('%Y-%m-%d', Datetime.from_cargo(v.t0)), os.date('%Y-%m-%d', Datetime.from_cargo(v.t1)), --			Datetime.ht(v.t0), --			Datetime.ht(v.t1), v.page, v.name)) end return (' Event appearances %s'):format(tostring(ul)) end

return require 'Module:MakeMWModule'.makeMWModule {main = main}