Jump to content

Help Please - Custom Block Upcoming Events Calendar Feed


Scott Allen
Go to solution Solved by bfarber,

Recommended Posts

Hello all!  Huge fan - long time listener, first time caller... Pretty new to customizing blocks for specific needs, and wondering if anyone can help me out here.

I have a small custom block for Calendar Feed Upcoming Events to notify our Admins of any upcoming 'unban' for banned players on our game server(s), and I successfully modified permissions for it to only show for our Admins groups (or higher) and the to only events within a 3 days...  But I am not sure how to modify it to not show any locked or hidden events, so that when we've unbanned a player, we can just lock the event, and it drops from being listed on the block (to save time/prevent other Admins from checking it all day to see if it's done already).

Also, after googling, was still not sure where I can find all this info for myself (all the various IPS specific methods/functions/classes I could use to make custom scripts like this from the ground up if desired), so any links would be greatly appreciated - my google-fu may be getting rusty.

Here's the code of what I have now - like I said, just want to add in an if-then-else to not show a particular event if it is hidden or if is locked (either, or both - doesn't matter):
 

<h3 class='ipsType_reset ipsWidget_title'>Upcoming Unbans</h3>
<div class='ipsWidget_inner'>
	{{if $orientation == 'vertical'}}
	<div class='ipsPad_half'>
		{{endif}}
		{{if !empty( $events ) }}
		<ul class='ipsDataList ipsDataList_reducedSpacing'>
			{{foreach $events as $event}}
			<li class='ipsDataItem ipsClearfix'>
				<div class='ipsDataItem_icon cCalendar_date_overlay'>
					{{if $event->nextOccurrence( $today, 'startDate' )}}
					<time datetime='{$event->nextOccurrence( $today, 'startDate' )->mysqlDatetime()}' class='ipsCalendarDate'>
					<span class='ipsCalendarDate_month' data-controller="core.global.core.datetime" data-time="{$event->nextOccurrence( $today, 'startDate' )->format('c')}" data-format="%b">{$event->nextOccurrence( $today, 'startDate' )->monthNameShort}</span>
					<span class='ipsCalendarDate_date' data-controller="core.global.core.datetime" data-time="{$event->nextOccurrence( $today, 'startDate' )->format('c')}" data-format="%d">{$event->nextOccurrence( $today, 'startDate' )->mday}</span>
					</time>
					{{else}}
					<time datetime='{$event->lastOccurrence( 'startDate' )->mysqlDatetime()}' class='ipsCalendarDate'>
					<span class='ipsCalendarDate_month' data-controller="core.global.core.datetime" data-time="{$event->lastOccurrence( 'startDate' )->format('c')}" data-format="%b">{$event->lastOccurrence( 'startDate' )->monthNameShort}</span>
					<span class='ipsCalendarDate_date' data-controller="core.global.core.datetime" data-time="{$event->lastOccurrence( 'startDate' )->format('c')}" data-format="%d">{$event->lastOccurrence( 'startDate' )->mday}</span>
					</time>
					{{endif}}
				</div>
				<div class='ipsDataItem_main cWidgetComments'>
					{{if $event->container()->allow_comments && $orientation == 'vertical'}}
					<div class="ipsCommentCount ipsPos_right {{if $event->comments === 0}}ipsFaded{{endif}}" data-ipsTooltip title='{lang="num_replies" pluralize="$event->comments"}'>{expression="$event->comments"}</div>
					{{endif}}
					<div class='ipsType_break ipsContained'>
						<a href="{$event->url()}" title='{lang="view_this_event" sprintf="$event->title"}'>{$event->title}</a>
					</div>
					<strong class='ipsType_small'>
						{{$sameDay = (bool) ( $event->nextOccurrence( $event->nextOccurrence( $today, 'startDate' ) ?: $today, 'endDate' ) and ( $event->nextOccurrence( $today, 'startDate' ) and $event->nextOccurrence( $today, 'startDate' )->calendarDate() == $event->nextOccurrence( $event->nextOccurrence( $today, 'startDate' ) ?: $today, 'endDate' )->calendarDate() ) );}}
						{{if $event->nextOccurrence( $today, 'startDate' )}}
						<span data-controller="core.global.core.datetime" data-time="{$event->nextOccurrence( $today, 'startDate' )->format('c')}" data-format="{expression="\IPS\calendar\Date::calendarDateFormat()"}{{if !$event->all_day}} {expression="\IPS\calendar\Date::localeTimeFormat( FALSE )"} {{endif}}">{$event->nextOccurrence( $today, 'startDate' )->calendarDate()}{{if !$event->all_day}} {$event->nextOccurrence( $today, 'startDate' )->localeTime( FALSE )} {{endif}}</span>
						{{if $event->nextOccurrence( $event->nextOccurrence( $today, 'startDate' ) ?: $today, 'endDate' ) }}
						{{if $orientation == 'vertical'}}<br>{{endif}}
						<span class='ipsType_light ipsType_unbold'>{lang="until"}</span>{{if $orientation == 'vertical' and !$sameDay}}<br>{{endif}}
						{{if !$sameDay}}<span data-controller="core.global.core.datetime" data-time="{$event->nextOccurrence( $event->nextOccurrence( $today, 'startDate' ) ?: $today, 'endDate' )->format('c')}" data-format="{expression="\IPS\calendar\Date::calendarDateFormat()"}{{if !$event->all_day}} {expression="\IPS\calendar\Date::localeTimeFormat( FALSE )"}{{endif}}">{$event->nextOccurrence( $event->nextOccurrence( $today, 'startDate' ) ?: $today, 'endDate' )->calendarDate()}{{endif}}{{if !$event->all_day}} {$event->nextOccurrence( $event->nextOccurrence( $today, 'startDate' ) ?: $today, 'endDate' )->localeTime( FALSE )}{{endif}}</span>
						{{endif}}
						{{else}}
						<span data-controller="core.global.core.datetime" data-time="{$event->lastOccurrence( 'startDate' )->format('c')}" data-format="{expression="\IPS\calendar\Date::calendarDateFormat()"}{{if !$event->all_day}} {expression="\IPS\calendar\Date::localeTimeFormat( FALSE )"} {{endif}}">{$event->lastOccurrence( 'startDate' )->calendarDate()}{{if !$event->all_day}} {$event->lastOccurrence( 'startDate' )->localeTime( FALSE )} </span>{{endif}}
						{{if $event->lastOccurrence( 'endDate' ) }}
						{{if $orientation == 'vertical'}}<br>{{endif}}
						<span class='ipsType_light ipsType_unbold'>{lang="until"}</span>{{if $orientation == 'vertical'}}<br>{{endif}}
						<span data-controller="core.global.core.datetime" data-time="{$event->lastOccurrence( 'endDate' )->format('c')}" data-format="{expression="\IPS\calendar\Date::calendarDateFormat()"}{{if !$event->all_day}} {expression="\IPS\calendar\Date::localeTimeFormat( FALSE )"}{{endif}}">{$event->lastOccurrence( 'endDate' )->calendarDate()}{{if !$event->all_day}} {$event->lastOccurrence( 'endDate' )->localeTime( FALSE )}{{endif}}</span>
						{{endif}}
						{{endif}}
					</strong>
					<br>
					{{if $event->container()->allow_comments && $orientation == 'horizontal'}}
					<span class="{{if $event->comments === 0}}ipsFaded{{endif}}" data-ipsTooltip title='{lang="num_replies" pluralize="$event->comments"}'><i class='fa fa-comment'></i> {expression="$event->comments"}</span>&nbsp;&nbsp;
					{{endif}}
					{{if $orientation == 'horizontal'}}
					<div class='ipsType_medium ipsType_richText' data-ipsTruncate data-ipsTruncate-type='remove' data-ipsTruncate-size='2 lines' data-ipsTruncate-watch='false'>
						{$event->truncated()|raw}
					</div>
					{{endif}}
				</div>
			</li>
			{{endforeach}}
		</ul>
		{{else}}
		<div class='ipsType_light ipsPad_half ipsType_center'>{lang="no_upcoming_events"}</div>
		{{endif}}
		{{if $orientation == 'vertical'}}
	</div>
	{{endif}}
</div>

 

Edited by Scott Allen
typos/clarification
Link to comment
Share on other sites

Thank you! That was the example I needed - also finally found the guides, my own fault I had a pop-up blocker that was hiding the element of "More" and the entire upper line with links on this site - I'll be off to the races now!!

If anyone crawls this in future wanting to see the wrap-up, here it is:

<h3 class='ipsType_reset ipsWidget_title'>Upcoming Unbans</h3>
<div class='ipsWidget_inner'>
	{{if $orientation == 'vertical'}}
	<div class='ipsPad_half'>
		{{endif}}
		{{if !empty( $events ) }}
		<ul class='ipsDataList ipsDataList_reducedSpacing'>
			{{foreach $events as $event}}
				{{if !$event->mapped('locked') AND $event->hidden() === 0}}
				<li class='ipsDataItem ipsClearfix'>
					<div class='ipsDataItem_icon cCalendar_date_overlay'>
						{{if $event->nextOccurrence( $today, 'startDate' )}}
						<time datetime='{$event->nextOccurrence( $today, 'startDate' )->mysqlDatetime()}' class='ipsCalendarDate'>
						<span class='ipsCalendarDate_month' data-controller="core.global.core.datetime" data-time="{$event->nextOccurrence( $today, 'startDate' )->format('c')}" data-format="%b">{$event->nextOccurrence( $today, 'startDate' )->monthNameShort}</span>
						<span class='ipsCalendarDate_date' data-controller="core.global.core.datetime" data-time="{$event->nextOccurrence( $today, 'startDate' )->format('c')}" data-format="%d">{$event->nextOccurrence( $today, 'startDate' )->mday}</span>
						</time>
						{{else}}
						<time datetime='{$event->lastOccurrence( 'startDate' )->mysqlDatetime()}' class='ipsCalendarDate'>
						<span class='ipsCalendarDate_month' data-controller="core.global.core.datetime" data-time="{$event->lastOccurrence( 'startDate' )->format('c')}" data-format="%b">{$event->lastOccurrence( 'startDate' )->monthNameShort}</span>
						<span class='ipsCalendarDate_date' data-controller="core.global.core.datetime" data-time="{$event->lastOccurrence( 'startDate' )->format('c')}" data-format="%d">{$event->lastOccurrence( 'startDate' )->mday}</span>
						</time>
						{{endif}}
					</div>
					<div class='ipsDataItem_main cWidgetComments'>
						{{if $event->container()->allow_comments && $orientation == 'vertical'}}
						<div class="ipsCommentCount ipsPos_right {{if $event->comments === 0}}ipsFaded{{endif}}" data-ipsTooltip title='{lang="num_replies" pluralize="$event->comments"}'>{expression="$event->comments"}</div>
						{{endif}}
						<div class='ipsType_break ipsContained'>
							<a href="{$event->url()}" title='{lang="view_this_event" sprintf="$event->title"}'>{$event->title}</a>
						</div>
						<strong class='ipsType_small'>
							{{$sameDay = (bool) ( $event->nextOccurrence( $event->nextOccurrence( $today, 'startDate' ) ?: $today, 'endDate' ) and ( $event->nextOccurrence( $today, 'startDate' ) and $event->nextOccurrence( $today, 'startDate' )->calendarDate() == $event->nextOccurrence( $event->nextOccurrence( $today, 'startDate' ) ?: $today, 'endDate' )->calendarDate() ) );}}
							{{if $event->nextOccurrence( $today, 'startDate' )}}
							<span data-controller="core.global.core.datetime" data-time="{$event->nextOccurrence( $today, 'startDate' )->format('c')}" data-format="{expression="\IPS\calendar\Date::calendarDateFormat()"}{{if !$event->all_day}} {expression="\IPS\calendar\Date::localeTimeFormat( FALSE )"} {{endif}}">{$event->nextOccurrence( $today, 'startDate' )->calendarDate()}{{if !$event->all_day}} {$event->nextOccurrence( $today, 'startDate' )->localeTime( FALSE )} {{endif}}</span>
							{{if $event->nextOccurrence( $event->nextOccurrence( $today, 'startDate' ) ?: $today, 'endDate' ) }}
							{{if $orientation == 'vertical'}}<br>{{endif}}
							<span class='ipsType_light ipsType_unbold'>{lang="until"}</span>{{if $orientation == 'vertical' and !$sameDay}}<br>{{endif}}
							{{if !$sameDay}}<span data-controller="core.global.core.datetime" data-time="{$event->nextOccurrence( $event->nextOccurrence( $today, 'startDate' ) ?: $today, 'endDate' )->format('c')}" data-format="{expression="\IPS\calendar\Date::calendarDateFormat()"}{{if !$event->all_day}} {expression="\IPS\calendar\Date::localeTimeFormat( FALSE )"}{{endif}}">{$event->nextOccurrence( $event->nextOccurrence( $today, 'startDate' ) ?: $today, 'endDate' )->calendarDate()}{{endif}}{{if !$event->all_day}} {$event->nextOccurrence( $event->nextOccurrence( $today, 'startDate' ) ?: $today, 'endDate' )->localeTime( FALSE )}{{endif}}</span>
							{{endif}}
							{{else}}
							<span data-controller="core.global.core.datetime" data-time="{$event->lastOccurrence( 'startDate' )->format('c')}" data-format="{expression="\IPS\calendar\Date::calendarDateFormat()"}{{if !$event->all_day}} {expression="\IPS\calendar\Date::localeTimeFormat( FALSE )"} {{endif}}">{$event->lastOccurrence( 'startDate' )->calendarDate()}{{if !$event->all_day}} {$event->lastOccurrence( 'startDate' )->localeTime( FALSE )} </span>{{endif}}
							{{if $event->lastOccurrence( 'endDate' ) }}
							{{if $orientation == 'vertical'}}<br>{{endif}}
							<span class='ipsType_light ipsType_unbold'>{lang="until"}</span>{{if $orientation == 'vertical'}}<br>{{endif}}
							<span data-controller="core.global.core.datetime" data-time="{$event->lastOccurrence( 'endDate' )->format('c')}" data-format="{expression="\IPS\calendar\Date::calendarDateFormat()"}{{if !$event->all_day}} {expression="\IPS\calendar\Date::localeTimeFormat( FALSE )"}{{endif}}">{$event->lastOccurrence( 'endDate' )->calendarDate()}{{if !$event->all_day}} {$event->lastOccurrence( 'endDate' )->localeTime( FALSE )}{{endif}}</span>
							{{endif}}
							{{endif}}
						</strong>
						<br>
						{{if $event->container()->allow_comments && $orientation == 'horizontal'}}
						<span class="{{if $event->comments === 0}}ipsFaded{{endif}}" data-ipsTooltip title='{lang="num_replies" pluralize="$event->comments"}'><i class='fa fa-comment'></i> {expression="$event->comments"}</span>&nbsp;&nbsp;
						{{endif}}
						{{if $orientation == 'horizontal'}}
						<div class='ipsType_medium ipsType_richText' data-ipsTruncate data-ipsTruncate-type='remove' data-ipsTruncate-size='2 lines' data-ipsTruncate-watch='false'>
							{$event->truncated()|raw}
						</div>
						{{endif}}
					</div>
				</li>
				{{endif}}
			{{endforeach}}
		</ul>
		{{else}}
		<div class='ipsType_light ipsPad_half ipsType_center'>{lang="no_upcoming_events"}</div>
		{{endif}}
		{{if $orientation == 'vertical'}}
	</div>
	{{endif}}
</div>



Cheers from VETERANS-GAMING!

Edited by Scott Allen
Link to comment
Share on other sites

Took another whack it this -- since the rule to 'Hide this block when there are no results to display' would still see events worth displaying, and I want to hide the entire block (including the titlebar) when no 'unlocked/unhidden' events are available, I had to add some logic to the beginning of the block, and not inside it as shown above.

Here's what the final draft looks like - and it's working well:
 

{{if !empty( $events ) }}
	{{foreach $events as $event}}
		{{if !$event->mapped('locked') AND $event->hidden() === 0}}
			{{$canShow = true;}}
		{{endif}}
	{{endforeach}}
{{endif}}
{{if ( $canShow ) }}
<h3 class='ipsType_reset ipsWidget_title'>Upcoming Unbans</h3>
<div class='ipsWidget_inner'>
	{{if $orientation == 'vertical'}}
	<div class='ipsPad_half'>
		{{endif}}
		{{if !empty( $events ) }}
		<ul class='ipsDataList ipsDataList_reducedSpacing'>
			{{foreach $events as $event}}
			<li class='ipsDataItem ipsClearfix'>
				<div class='ipsDataItem_icon cCalendar_date_overlay'>
					{{if $event->nextOccurrence( $today, 'startDate' )}}
					<time datetime='{$event->nextOccurrence( $today, 'startDate' )->mysqlDatetime()}' class='ipsCalendarDate'>
					<span class='ipsCalendarDate_month' data-controller="core.global.core.datetime" data-time="{$event->nextOccurrence( $today, 'startDate' )->format('c')}" data-format="%b">{$event->nextOccurrence( $today, 'startDate' )->monthNameShort}</span>
					<span class='ipsCalendarDate_date' data-controller="core.global.core.datetime" data-time="{$event->nextOccurrence( $today, 'startDate' )->format('c')}" data-format="%d">{$event->nextOccurrence( $today, 'startDate' )->mday}</span>
					</time>
					{{else}}
					<time datetime='{$event->lastOccurrence( 'startDate' )->mysqlDatetime()}' class='ipsCalendarDate'>
					<span class='ipsCalendarDate_month' data-controller="core.global.core.datetime" data-time="{$event->lastOccurrence( 'startDate' )->format('c')}" data-format="%b">{$event->lastOccurrence( 'startDate' )->monthNameShort}</span>
					<span class='ipsCalendarDate_date' data-controller="core.global.core.datetime" data-time="{$event->lastOccurrence( 'startDate' )->format('c')}" data-format="%d">{$event->lastOccurrence( 'startDate' )->mday}</span>
					</time>
					{{endif}}
				</div>
				<div class='ipsDataItem_main cWidgetComments'>
					{{if $event->container()->allow_comments && $orientation == 'vertical'}}
					<div class="ipsCommentCount ipsPos_right {{if $event->comments === 0}}ipsFaded{{endif}}" data-ipsTooltip title='{lang="num_replies" pluralize="$event->comments"}'>{expression="$event->comments"}</div>
					{{endif}}
					<div class='ipsType_break ipsContained'>
						<a href="{$event->url()}" title='{lang="view_this_event" sprintf="$event->title"}'>{$event->title}</a>
					</div>
					<strong class='ipsType_small'>
						{{$sameDay = (bool) ( $event->nextOccurrence( $event->nextOccurrence( $today, 'startDate' ) ?: $today, 'endDate' ) and ( $event->nextOccurrence( $today, 'startDate' ) and $event->nextOccurrence( $today, 'startDate' )->calendarDate() == $event->nextOccurrence( $event->nextOccurrence( $today, 'startDate' ) ?: $today, 'endDate' )->calendarDate() ) );}}
						{{if $event->nextOccurrence( $today, 'startDate' )}}
						<span data-controller="core.global.core.datetime" data-time="{$event->nextOccurrence( $today, 'startDate' )->format('c')}" data-format="{expression="\IPS\calendar\Date::calendarDateFormat()"}{{if !$event->all_day}} {expression="\IPS\calendar\Date::localeTimeFormat( FALSE )"} {{endif}}">{$event->nextOccurrence( $today, 'startDate' )->calendarDate()}{{if !$event->all_day}} {$event->nextOccurrence( $today, 'startDate' )->localeTime( FALSE )} {{endif}}</span>
						{{if $event->nextOccurrence( $event->nextOccurrence( $today, 'startDate' ) ?: $today, 'endDate' ) }}
						{{if $orientation == 'vertical'}}<br>{{endif}}
						<span class='ipsType_light ipsType_unbold'>{lang="until"}</span>{{if $orientation == 'vertical' and !$sameDay}}<br>{{endif}}
						{{if !$sameDay}}<span data-controller="core.global.core.datetime" data-time="{$event->nextOccurrence( $event->nextOccurrence( $today, 'startDate' ) ?: $today, 'endDate' )->format('c')}" data-format="{expression="\IPS\calendar\Date::calendarDateFormat()"}{{if !$event->all_day}} {expression="\IPS\calendar\Date::localeTimeFormat( FALSE )"}{{endif}}">{$event->nextOccurrence( $event->nextOccurrence( $today, 'startDate' ) ?: $today, 'endDate' )->calendarDate()}{{endif}}{{if !$event->all_day}} {$event->nextOccurrence( $event->nextOccurrence( $today, 'startDate' ) ?: $today, 'endDate' )->localeTime( FALSE )}{{endif}}</span>
						{{endif}}
						{{else}}
						<span data-controller="core.global.core.datetime" data-time="{$event->lastOccurrence( 'startDate' )->format('c')}" data-format="{expression="\IPS\calendar\Date::calendarDateFormat()"}{{if !$event->all_day}} {expression="\IPS\calendar\Date::localeTimeFormat( FALSE )"} {{endif}}">{$event->lastOccurrence( 'startDate' )->calendarDate()}{{if !$event->all_day}} {$event->lastOccurrence( 'startDate' )->localeTime( FALSE )} </span>{{endif}}
						{{if $event->lastOccurrence( 'endDate' ) }}
						{{if $orientation == 'vertical'}}<br>{{endif}}
						<span class='ipsType_light ipsType_unbold'>{lang="until"}</span>{{if $orientation == 'vertical'}}<br>{{endif}}
						<span data-controller="core.global.core.datetime" data-time="{$event->lastOccurrence( 'endDate' )->format('c')}" data-format="{expression="\IPS\calendar\Date::calendarDateFormat()"}{{if !$event->all_day}} {expression="\IPS\calendar\Date::localeTimeFormat( FALSE )"}{{endif}}">{$event->lastOccurrence( 'endDate' )->calendarDate()}{{if !$event->all_day}} {$event->lastOccurrence( 'endDate' )->localeTime( FALSE )}{{endif}}</span>
						{{endif}}
						{{endif}}
					</strong>
					<br>
					{{if $event->container()->allow_comments && $orientation == 'horizontal'}}
					<span class="{{if $event->comments === 0}}ipsFaded{{endif}}" data-ipsTooltip title='{lang="num_replies" pluralize="$event->comments"}'><i class='fa fa-comment'></i> {expression="$event->comments"}</span>&nbsp;&nbsp;
					{{endif}}
					{{if $orientation == 'horizontal'}}
					<div class='ipsType_medium ipsType_richText' data-ipsTruncate data-ipsTruncate-type='remove' data-ipsTruncate-size='2 lines' data-ipsTruncate-watch='false'>
						{$event->truncated()|raw}
					</div>
					{{endif}}
				</div>
			</li>
			{{endforeach}}
		</ul>
		{{else}}
		<div class='ipsType_light ipsPad_half ipsType_center'>{lang="no_upcoming_events"}</div>
		{{endif}}
		{{if $orientation == 'vertical'}}
	</div>
	{{endif}}
</div>
{{endif}}

Thanks again!!

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...