From 0cb75a945ee48025dea61f6e071ba4335d52025a Mon Sep 17 00:00:00 2001 From: ash-f Date: Sat, 18 Sep 2021 09:54:22 -0700 Subject: [PATCH 1/5] Showing multiday events on the calendar widget --- classes/class-eo-calendar-widget.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/classes/class-eo-calendar-widget.php b/classes/class-eo-calendar-widget.php index f2b6e085..20c8d1ba 100644 --- a/classes/class-eo-calendar-widget.php +++ b/classes/class-eo-calendar-widget.php @@ -376,6 +376,11 @@ static function generate_output( $month, $args = array() ) { $link, $cell - $offset ); + if( in_array( 'eo-multi-day', $class ) ){ $mdevent = $calendar_events[$formated_date]; $mdclass = $class; $mdtitle = $titles; } + } elseif ( isset($mdevent) ) { + $classes = implode( ' ', $mdclass ); $classes = str_replace( ' eo-multi-day', '', $classes); + $body .= sprintf( " %s ", esc_attr( $classes ), esc_attr( $mdtitles ), $cell - $offset ); + if( $mdevent[0]->EndDate==$formated_date ){ unset($mdevent); } } else { $classes = implode( ' ',$class ); $body .= sprintf( " %s ", esc_attr( $classes ), $cell - $offset ); From 6a3b84a9a257565201683f1b76ab325ee3da7501 Mon Sep 17 00:00:00 2001 From: ash-f Date: Wed, 22 Sep 2021 18:16:54 -0700 Subject: [PATCH 2/5] Update class-eo-calendar-widget.php Small change --- classes/class-eo-calendar-widget.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/classes/class-eo-calendar-widget.php b/classes/class-eo-calendar-widget.php index 20c8d1ba..a9f71df2 100644 --- a/classes/class-eo-calendar-widget.php +++ b/classes/class-eo-calendar-widget.php @@ -376,9 +376,9 @@ static function generate_output( $month, $args = array() ) { $link, $cell - $offset ); - if( in_array( 'eo-multi-day', $class ) ){ $mdevent = $calendar_events[$formated_date]; $mdclass = $class; $mdtitle = $titles; } + if( in_array( 'eo-multi-day', $class ) ){ $mdevent = $calendar_events[$formated_date]; $mdclass = $class; $mdtitles = $titles; } } elseif ( isset($mdevent) ) { - $classes = implode( ' ', $mdclass ); $classes = str_replace( ' eo-multi-day', '', $classes); + $classes = implode( ' ', $mdclass ); $body .= sprintf( " %s ", esc_attr( $classes ), esc_attr( $mdtitles ), $cell - $offset ); if( $mdevent[0]->EndDate==$formated_date ){ unset($mdevent); } } else { From db833f6847f2265a7d98b02352bc3ffaeade3a0d Mon Sep 17 00:00:00 2001 From: ash-f Date: Fri, 24 Sep 2021 17:37:10 -0700 Subject: [PATCH 3/5] improvement for multiple events improved logic to handle multiple events on the same day. --- classes/class-eo-calendar-widget.php | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/classes/class-eo-calendar-widget.php b/classes/class-eo-calendar-widget.php index a9f71df2..275cb11d 100644 --- a/classes/class-eo-calendar-widget.php +++ b/classes/class-eo-calendar-widget.php @@ -376,11 +376,28 @@ static function generate_output( $month, $args = array() ) { $link, $cell - $offset ); - if( in_array( 'eo-multi-day', $class ) ){ $mdevent = $calendar_events[$formated_date]; $mdclass = $class; $mdtitles = $titles; } - } elseif ( isset($mdevent) ) { - $classes = implode( ' ', $mdclass ); - $body .= sprintf( " %s ", esc_attr( $classes ), esc_attr( $mdtitles ), $cell - $offset ); - if( $mdevent[0]->EndDate==$formated_date ){ unset($mdevent); } + if( in_array( 'eo-multi-day', $class ) ){ + $mdevents[] = $calendar_events[$formated_date]; + $mdclasses[] = $class; + $mdtitles[] = $titles; + } + } elseif ( isset( $mdevents[0] ) ){ + $unset = 0; + $cnt = count($mdevents); + for( $i = 0; $i < $cnt; $i++ ){ + $classes = implode( ' ', $mdclasses[$i] ); + $titles = $mdtitles[$i]; + if( $mdevents[$i][0]->EndDate == $formated_date ) { + unset( $mdevents[$i], $mdclasses[$i], $mdtitles[$i] ); + $unset = 1; + } + } + if ( $unset == 1 ) { + $mdevents = array_values( $mdevents ); + $mdclasses = array_values( $mdclasses ); + $mdtitles = array_values( $mdtitles ); + } + $body .= sprintf( " %s ", esc_attr( $classes ), esc_attr( $titles ), $cell - $offset ); } else { $classes = implode( ' ',$class ); $body .= sprintf( " %s ", esc_attr( $classes ), $cell - $offset ); From 34f64320af5569718cd4ba1130defe13b172b145 Mon Sep 17 00:00:00 2001 From: ash-f Date: Sun, 26 Sep 2021 19:24:57 -0700 Subject: [PATCH 4/5] further improvement with multiple events --- classes/class-eo-calendar-widget.php | 47 +++++++++++++++++----------- 1 file changed, 28 insertions(+), 19 deletions(-) diff --git a/classes/class-eo-calendar-widget.php b/classes/class-eo-calendar-widget.php index 275cb11d..9b72f314 100644 --- a/classes/class-eo-calendar-widget.php +++ b/classes/class-eo-calendar-widget.php @@ -376,31 +376,40 @@ static function generate_output( $month, $args = array() ) { $link, $cell - $offset ); - if( in_array( 'eo-multi-day', $class ) ){ + if ( in_array( 'eo-multi-day', $class ) ){ $mdevents[] = $calendar_events[$formated_date]; $mdclasses[] = $class; $mdtitles[] = $titles; } - } elseif ( isset( $mdevents[0] ) ){ - $unset = 0; - $cnt = count($mdevents); - for( $i = 0; $i < $cnt; $i++ ){ - $classes = implode( ' ', $mdclasses[$i] ); - $titles = $mdtitles[$i]; - if( $mdevents[$i][0]->EndDate == $formated_date ) { - unset( $mdevents[$i], $mdclasses[$i], $mdtitles[$i] ); - $unset = 1; + } else { + if ( isset( $mdevents[0] ) ){ + $unset = 0; + $cnt = count( $mdevents ); + $class[] = 'event'; + for( $i = 0; $i < $cnt; $i++ ) { + if( $mdevents[$i]->StartDate == $mdevents[$i]->EndDate ) { + unset( $mdevents[$i] ); + $unset = 1; + } else { + $class = array_merge( $class, eo_get_event_classes( $mdevents[$i]->ID, $mdevents[$i]->occurrence_id ) ); + if ( $mdevents[$i]->EndDate == $formated_date ) { + unset( $mdevents[$i] ); + $unset = 1; + } + } } + if ( $unset == 1 ) { + $mdevents = array_values( $mdevents ); + } + if ( count($class) > 1 ) { + $classes = implode( ' ',$class ); + $titles = implode( ' ', array_map( 'get_the_title', $mdevents ) ); + $body .= sprintf( " %s ", esc_attr( $classes ), esc_attr( $titles ), $cell - $offset ); + } + } else { + $classes = implode( ' ',$class ); + $body .= sprintf( " %s ", esc_attr( $classes ), $cell - $offset ); } - if ( $unset == 1 ) { - $mdevents = array_values( $mdevents ); - $mdclasses = array_values( $mdclasses ); - $mdtitles = array_values( $mdtitles ); - } - $body .= sprintf( " %s ", esc_attr( $classes ), esc_attr( $titles ), $cell - $offset ); - } else { - $classes = implode( ' ',$class ); - $body .= sprintf( " %s ", esc_attr( $classes ), $cell - $offset ); } //Proceed to next day From 7835cfb5a92d9626ed8b32899675ba49d4a05bdb Mon Sep 17 00:00:00 2001 From: ash-f Date: Sun, 26 Sep 2021 21:37:01 -0700 Subject: [PATCH 5/5] bugfix --- classes/class-eo-calendar-widget.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/classes/class-eo-calendar-widget.php b/classes/class-eo-calendar-widget.php index 9b72f314..d7b93fa7 100644 --- a/classes/class-eo-calendar-widget.php +++ b/classes/class-eo-calendar-widget.php @@ -383,29 +383,29 @@ static function generate_output( $month, $args = array() ) { } } else { if ( isset( $mdevents[0] ) ){ - $unset = 0; - $cnt = count( $mdevents ); + $unsetevents = array(); + $cnt = count($mdevents); $class[] = 'event'; for( $i = 0; $i < $cnt; $i++ ) { if( $mdevents[$i]->StartDate == $mdevents[$i]->EndDate ) { - unset( $mdevents[$i] ); - $unset = 1; + array_splice( $mdevents, $i, 1 ); } else { $class = array_merge( $class, eo_get_event_classes( $mdevents[$i]->ID, $mdevents[$i]->occurrence_id ) ); if ( $mdevents[$i]->EndDate == $formated_date ) { - unset( $mdevents[$i] ); - $unset = 1; + $unsetevents[] = $i; } } } - if ( $unset == 1 ) { - $mdevents = array_values( $mdevents ); - } if ( count($class) > 1 ) { $classes = implode( ' ',$class ); $titles = implode( ' ', array_map( 'get_the_title', $mdevents ) ); $body .= sprintf( " %s ", esc_attr( $classes ), esc_attr( $titles ), $cell - $offset ); } + if ( count($unsetevents) > 0 ) { + foreach( $unsetevents as $ue ){ + array_splice( $mdevents, $ue, 1 ); + } + } } else { $classes = implode( ' ',$class ); $body .= sprintf( " %s ", esc_attr( $classes ), $cell - $offset );