From 5a1bac1a3618c9edeb0fecfb11a2ba4e299759e8 Mon Sep 17 00:00:00 2001 From: pkamps Date: Tue, 14 Feb 2023 15:53:10 +0100 Subject: [PATCH] See #3 - adding access to MugoCalendarEvent objects --- classes/MugoCalendarEvent.php | 116 ++++++++++++++++++ classes/MugoCalendarFunctions.php | 5 +- design/standard/templates/includes/agenda.tpl | 26 ++-- 3 files changed, 133 insertions(+), 14 deletions(-) diff --git a/classes/MugoCalendarEvent.php b/classes/MugoCalendarEvent.php index aac2b35..77ff36f 100644 --- a/classes/MugoCalendarEvent.php +++ b/classes/MugoCalendarEvent.php @@ -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; + } + } diff --git a/classes/MugoCalendarFunctions.php b/classes/MugoCalendarFunctions.php index 478fa83..4b14c10 100644 --- a/classes/MugoCalendarFunctions.php +++ b/classes/MugoCalendarFunctions.php @@ -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() ) { diff --git a/design/standard/templates/includes/agenda.tpl b/design/standard/templates/includes/agenda.tpl index 7ee9003..422b6fe 100644 --- a/design/standard/templates/includes/agenda.tpl +++ b/design/standard/templates/includes/agenda.tpl @@ -39,16 +39,20 @@ {if $parent_node_id} {def $events = fetch( 'mugo_calendar', 'events', $fetch_events_parameters)} - + {if $events|count()} + + {else} + No events found + {/if} {/if} {/if}