Jump to content

Module:Current Weekly Events/Draft

From SPS Wiki

This is the draft page for Module:Current Weekly Events.

It implements the template {{Current Weekly Events/Draft }}.


local p = {}

local util = require('Module:Module Util')

local gallAttributes = {
	["hideaddbutton"] = "true",
	["widths"] = "225px",
	["bordersize"] = "none",
	["spacing"] = "small",
	["captionalign"] = "center",
	["captionsize"] = "large",
	["position"] = "center",
	["navigation"] = "true"
}

--uses the template as a wrapper, grabbing any arguments passed to the template
function p.main(frame)
	local args = require('Module:Arguments').getArgs(frame, {
		wrapper="Template:Current Weekly Events/Draft"
	})
	return p._main(args, frame)
end

function p._main(args, frame)
	frame = frame or mw.getCurrentFrame()
	local platform = args["platform"] or "pc"
	local eventCategory = (platform == "mobile") and "*Mobile LTE Events" or "Weekly Girl Events¦Weekly Pinup Events¦Weekly Outfit Events"

	
	--find name and image file of all current weekly events, and split into array
    local dpl = frame:callParserFunction( "#dpl:category = "..eventCategory, 
    	{
    		uses = "Template:Event",
    		include = "{Event}:name,{Event}:image,{Event}:time_start,{Event}:time_end",
    		ordermethod="titlewithoutnamespace",
    		allowcachedresults=true,
    		cacheperiod=86400, --86400 secs = 1 day refresh rate
	    	listseparators = ",,,",
	    	secseparators = ",||,"..
	    	",||%TITLE%||,"..
	    	",||,"..--time_start [4]
	    	",;,"--time_end [5]
    	} )
    local killLastCharacter = string.sub(dpl, 1, -2)
	local eventSplit = mw.text.split(killLastCharacter, ';', true)
	local detailsSplit = {}
	for k,v in ipairs(eventSplit) do --split event details
		local vArray = mw.text.split(v, '||', true) --split string on the bars
		local arrayV = {
			["title"] = vArray[1],
			["image"] = vArray[2],
			["link"] = vArray[3],
			["startDate"] = vArray[4],
			["endDate"] = vArray[5]
		}
		table.insert(detailsSplit, arrayV)
	end
	
	--construct gallery content input
	local gallery = ""
	for _,event in ipairs(detailsSplit) do
		--insert dates into solo arrays because date comparator is designed to check multiples
		local startArr = {}
		table.insert(startArr, event.startDate)
		local endArr = {}
		table.insert(endArr, event.endDate)
		if util._isPast(endArr)==false and util._isUpcoming(startArr)==false then
			gallery=gallery..event.image.."|link="..event.link.."|[["..event.link.."|"..event.title.."]]<br />"..util._presentWrittenDate(event.startDate, "no hours", true).." – "..util._presentWrittenDate(event.endDate, "no hours", true).."\n"
		end
	end

	local output = mw.html.create() --create html frame
	if gallery=="" then
		gallery = "Q-Pernikiss Sprite Encounter.png|link=Weekly Event|No weekly events ongoing"
		gallAttributes["widths"] = "150px"
	end
	output:tag('div'):wikitext(frame:extensionTag( 'gallery', gallery, gallAttributes )) --create gallery as HTML object

    return output
end

return p