Module:CountdownBanner: Difference between revisions

From 20R1
No edit summary
No edit summary
 
(36 intermediate revisions by the same user not shown)
Line 3: Line 3:
function p.show( frame )
function p.show( frame )
     local currentTime = os.time()
     local currentTime = os.time()
    local lb = ' [['
    local rb = ']] '
    local query = '{{#ask: '..lb..'Club Name::+'..rb..lb..'Start Date::> '..os.date("!%Y-%m-%d", currentTime)..rb
                .. '|?Start Date'
                .. '|?Event Name=Name'
                .. '|?Event Location=Location'
                .. '|?Event Flyer=Flyer'
                .. '|sort=Start Date'
                .. '|order=asc'
                .. '|limit=1'
                .. '|}}'


-- Use the normal DPL-style SMW query instead of mw.smw.ask
    local result = frame:preprocess( query )
local query = '{{#ask: [[Category:Events]] [[Event Date::>' .. os.date("!%Y-%m-%d", currentTime) .. ']]'
              .. '|?Event Date'
              .. '|?Event Name=Name'
              .. '|?Event Location=Location'
              .. '|?Event Flyer=Flyer'
              .. '|sort=Event Date'
              .. '|order=asc'
              .. '|limit=1'
              .. '|format=template'
              .. '|template=CountdownBannerHelper'
              .. '}}'


local result = frame:preprocess( query )
    if result == '' or result:match'^%s*$' then
        local banner = '<div style="background:#b22234;color:white;padding:20px;text-align:center;font-size:18px;">No upcoming events scheduled</div>'
    banner = 'QUERY:'..query..'<br><pre>RESULT:'..result..'<hr>'..banner
    return query
    end


-- If nothing returned, show friendly message
    return frame:preprocess( '{{CountdownBannerDisplay|' .. query .. '}}' )
if result == '' or result:match'^%s*$' then
end
  return '<pre>'..query..'</pre><div style="background:#b22234;color:white;padding:20px;text-align:center;font-size:18px;">No immediate upcoming events scheduled</div>'
end


return result
function p.query( frame )
    local currentTime = os.time()
    local lb = '[[' --' &#91;&#91;'
    local rb = ']]' --'&#93;&#93; '
    local query = '{{#ask: '..lb..'Club Name::+'..rb..' '..lb..'Start Date::> '..os.date("!%Y-%m-%d", currentTime)..rb
                .. '|?Start Date'
                .. '|?Event Name=Name'
                .. '|?Event Location=Location'
                .. '|?Event Photo=Flyer'
                .. '|sort=Start Date'
                .. '|order=asc'
                .. '|limit=1'
                .. '|}}'
 
    return '<pre>'..query..'</pre>'
    --return frame:preprocess( '{{CountdownBannerDisplay|' .. query .. '}}' )
end
end


function p.result( frame )
    local currentTime = os.time()
    local lb = '[[' --' &#91;&#91;'
    local rb = ']]' --'&#93;&#93; '
    local filter = lb..'Club Name::+'..rb..' '..lb..'Start Date::> '..os.date("!%Y-%m-%d", currentTime)..rb
    local query = --'{{#ask: '..
                '\n|?Start Date'
                .. '\n|?Event Name=Name'
                .. '\n|?Event Location=Location'
                .. '\n|?Event Flyer=Flyer'
                .. '\n|sort=Start Date'
                .. '\n|order=asc'
                .. '\n|limit=1'
                --.. '\n||}}'
local result=frame:preprocess( '{{Query|query=' .. query .. '|filter='..filter..'|}}' )
return frame:preprocess( '{{CountdownBannerDisplay|'..result..'|}}' )
end
return p
return p

Latest revision as of 04:19, 20 November 2025

Documentation for this module may be created at Module:CountdownBanner/doc

local p = {}

function p.show( frame )
    local currentTime = os.time()
    local lb = ' &#91;&#91;'
    local rb = '&#93;&#93; '
    local query = '{{#ask: '..lb..'Club Name::+'..rb..lb..'Start Date::> '..os.date("!%Y-%m-%d", currentTime)..rb
                .. '|?Start Date'
                .. '|?Event Name=Name'
                .. '|?Event Location=Location'
                .. '|?Event Flyer=Flyer'
                .. '|sort=Start Date'
                .. '|order=asc'
                .. '|limit=1'
                .. '|}}'

    local result = frame:preprocess( query )

    if result == '' or result:match'^%s*$' then
        local banner = '<div style="background:#b22234;color:white;padding:20px;text-align:center;font-size:18px;">No upcoming events scheduled</div>'
    	banner = 'QUERY:'..query..'<br><pre>RESULT:'..result..'<hr>'..banner
    	return query
    end

    return frame:preprocess( '{{CountdownBannerDisplay|' .. query .. '}}' )
end

function p.query( frame )
    local currentTime = os.time()
    local lb = '[[' --' &#91;&#91;'
    local rb = ']]' --'&#93;&#93; '
    local query = '{{#ask: '..lb..'Club Name::+'..rb..' '..lb..'Start Date::> '..os.date("!%Y-%m-%d", currentTime)..rb
                .. '|?Start Date'
                .. '|?Event Name=Name'
                .. '|?Event Location=Location'
                .. '|?Event Photo=Flyer'
                .. '|sort=Start Date'
                .. '|order=asc'
                .. '|limit=1'
                .. '|}}'

    return '<pre>'..query..'</pre>'
    --return frame:preprocess( '{{CountdownBannerDisplay|' .. query .. '}}' )
end

function p.result( frame )
    local currentTime = os.time()
    local lb = '[[' --' &#91;&#91;'
    local rb = ']]' --'&#93;&#93; '
    local filter = lb..'Club Name::+'..rb..' '..lb..'Start Date::> '..os.date("!%Y-%m-%d", currentTime)..rb
    local query = --'{{#ask: '..
                '\n|?Start Date'
                .. '\n|?Event Name=Name'
                .. '\n|?Event Location=Location'
                .. '\n|?Event Flyer=Flyer'
                .. '\n|sort=Start Date'
                .. '\n|order=asc'
                .. '\n|limit=1'
                --.. '\n||}}'

	local result=frame:preprocess( '{{Query|query=' .. query .. '|filter='..filter..'|}}' )
	return frame:preprocess( 	'{{CountdownBannerDisplay|'..result..'|}}' )
	end
return p