Module:TempestTrialsTable

local Util = require 'Module:Util' local List = require 'Module:ListUtil' local Datetime = require 'Module:DatetimeUtil' local cargo = mw.ext.cargo local toboolean = require 'Module:Bool'.toboolean

local main = function (args, frame) local tts = cargo.query('TempestTrials', '_pageName,Name,BonusHeroes__full=bh,StartTime=t0,EndTime=t1,Maps', {		where = toboolean(args.past) and 'DATEDIFF(EndTime,NOW)<=0' or 'DATEDIFF(EndTime,NOW)>0',		orderBy = 't0',		limit = 100,	}) if #tts == 0 then return 'Currently none.' end for _, v in ipairs(tts) do		v.bh = mw.text.split(v.bh, '%s*,%s*') end

local ttRewards = List.group_by(cargo.query('TempestTrialsRewards=TTR,Units', "TTR._pageName=page,Item,IFNULL(CONCAT(Name,': ',Title),Name)=Unit,Rarity,SacredSeal,Accessory", { join = 'TTR.Unit=Units.WikiName', where = "NOT (Kind='item' AND (Item='Light\\'s Blessing' OR Item NOT LIKE '% Blessing') AND Item NOT LIKE 'Divine Code: %') AND NOT (TTR.Unit IS NOT NULL AND TTR.Kind!='unit')", orderBy = 'page,IF(Unit IS NOT NULL,1,IF(Item IS NOT NULL,2,3)),Score', limit = 5000, }), function (v) return v.page end)

local tbl = mw.html.create('table'):addClass('wikitable'):addClass('default'):css('text-align', 'center') local row = tbl:tag('tr') row:tag('th'):wikitext('Name') row:tag('th'):wikitext('Featured bonus Heroes') row:tag('th'):wikitext(frame:expandTemplate {title = 'Hover', args = {'Notable rewards', 'Rewarded Heroes, blessings, and Sacred Seals'}}) row:tag('th'):wikitext('Maps') row:tag('th'):wikitext('Event dates')

for _, tt in ipairs(tts) do		row = tbl:tag('tr') local cell = row:tag('td') cell:wikitext(frame:expandTemplate {title = 'Banner TT', args = {bannerName = tt.Name, link = tt._pageName}})

cell = row:tag('td') for i, hero in ipairs(tt.bh) do			if i > 1 then cell:wikitext(i % 4 == 1 and ' ' or ' ') end cell:wikitext(Util.getHeroIcon(hero, '40px')) end

local rewards = ttRewards[tt._pageName] or {} cell = row:tag('td') for i, v in ipairs(rewards) do			if i > 1 then cell:wikitext(i % 3 == 1 and ' ' or ' ') end if v.Unit ~= '' then cell:wikitext(frame:expandTemplate {title = 'IconFrame', args = {hero = v.Unit, rarity = v.Rarity}}) elseif v.SacredSeal ~= '' then cell:wikitext(frame:expandTemplate {title = 'SkillIcon', args = {v.SacredSeal, size = '40px'}}) elseif v.Item ~= '' then cell:wikitext(frame:expandTemplate {title = 'ItemIcon', args = {v.Item, size = '40px'}}) end end

cell = row:tag('td') cell:wikitext(tt.Maps)

cell = row:tag('td') cell:wikitext(Datetime.ht(tt.t0), ' – ', Datetime.ht(tt.t1)) -- or ht_range end

return tostring(tbl) end

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