Skip to content

Commit

Permalink
See #3 - adding access to MugoCalendarEvent objects
Browse files Browse the repository at this point in the history
  • Loading branch information
pkamps committed Feb 14, 2023
1 parent 235f53a commit 5a1bac1
Show file tree
Hide file tree
Showing 3 changed files with 133 additions and 14 deletions.
116 changes: 116 additions & 0 deletions classes/MugoCalendarEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,120 @@ public function isFullDayEvent()

return $return;
}

/*
* Access in templates
*/

public function attributes() : array
{
return array(
'start',
'end',
'id',
'object',
//TODO: support more attributes
// 'attribute',
// 'all_day_event',
// 'recurrence',
// 'type',
// 'parent_id',
// 'instance',
// 'data',
);
}

/**
* @param $attr
* @param bool $noFunction
* @return bool|eZContentObject|int
*/
public function attribute( $attr, $noFunction = false )
{
switch( $attr )
{
case 'start':
{
return is_object( $this->start ) ? $this->start->getTimestamp() : null;
}
break;

case 'end':
{
return is_object( $this->end ) ? $this->end->getTimestamp() : null;
}
break;

case 'object':
{
return $this->mugoCalendarEventDefinition->getContentObject();
}
break;

// case 'attribute':
// {
// return $this->objectAttribute;
// }
// break;

// case 'all_day_event':
// {
// return $this->isAllDay;
// }
// break;

// case 'recurrence':
// {
// return $this->recurrence;
// }
// break;

// case 'type':
// {
// $map = array(
// 0 => 'undefined',
// 1 => 'single',
// 2 => 'recurring',
// 3 => 'exception',
// );
//
// return $map[ $this->type ];
// }
// break;

// case 'instance':
// {
// return $this->instance;
// }
// break;

case 'id':
{
return $this->id;
}
break;

// case 'data':
// {
// return $this->data;
// }
// break;
}
}

/**
* @param $attr
* @return bool
*/
public function hasAttribute( $attr )
{
return in_array( $attr, $this->attributes() );
}

// optional
public function setAttribute( $attr, $value )
{
$this->$attr = $value;
}

}
5 changes: 2 additions & 3 deletions classes/MugoCalendarFunctions.php
Original file line number Diff line number Diff line change
Expand Up @@ -524,9 +524,8 @@ private static function excludeExceptions( array $events ) : array
$exceptionDefinition = $exceptions[0];
$exceptionDefinition->node = $exceptionNode;

$exception = MugoCalendarEvent::constructByCalendarEventDefinition(
$exceptionDefinition
);
//TODO: this will break for skip exceptions
$exception = new MugoCalendarEvent( $exceptionDefinition );

if( $exception->getStart() )
{
Expand Down
26 changes: 15 additions & 11 deletions design/standard/templates/includes/agenda.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,20 @@
{if $parent_node_id}
{def $events = fetch( 'mugo_calendar', 'events', $fetch_events_parameters)}

<ul class="{$css_classes}">
{foreach $events as $event}
<li>
{node_view_gui
content_node=$event.object.main_node
view=$view
event=$event
}
</li>
{/foreach}
</ul>
{if $events|count()}
<ul class="{$css_classes}">
{foreach $events as $event}
<li>
{node_view_gui
content_node=$event.object.main_node
view=$view
event=$event
}
</li>
{/foreach}
</ul>
{else}
No events found
{/if}
{/if}
{/if}

0 comments on commit 5a1bac1

Please sign in to comment.