From b9d9df6407ef6348be1a9238a51738d6c0e69ab5 Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Fri, 24 Jun 2016 15:30:59 -0400 Subject: [PATCH] Fix for the YEARLY event that spans from one month to the next. Had to break these out and create the custom date array and serialize it. --- models/admin/management/events.php | 47 +++++++++++++++++++++++------- 1 file changed, 36 insertions(+), 11 deletions(-) diff --git a/models/admin/management/events.php b/models/admin/management/events.php index 4c2ddd6..1a34a9b 100644 --- a/models/admin/management/events.php +++ b/models/admin/management/events.php @@ -1101,7 +1101,7 @@ class GlmMembersAdmin_management_events extends GlmDataEventsManagement AND post_status = 'publish'"; //$sql .= " AND ID IN ( SELECT post_id FROM " . $this->wpdb->prefix . "ai1ec_events //WHERE end >= " . time() . " )"; - //$sql .= " AND ID IN ( 2469, 1640 )"; + //$sql .= " AND ID IN ( 1647 )"; $sql .= " LIMIT $limit OFFSET $start"; $results = $this->wpdb->get_results( $sql, ARRAY_A ); @@ -1409,18 +1409,43 @@ class GlmMembersAdmin_management_events extends GlmDataEventsManagement if ( $debug ) { echo '
$end_day: ' . print_r($end_day, true) . '
'; } - for ( $index = ( $start_day - 1); $index <= ( $end_day -1 ); ++$index ) { - $ints = pow( 2, $index ); - $day_of_month += $ints; - } - - if($day_of_month){ - $by_day_of_month = 1; + if ( $start_day == $end_day ) { + for ( $index = ( $start_day - 1); $index <= ( $end_day -1 ); ++$index ) { + $ints = pow( 2, $index ); + $day_of_month += $ints; + } + if($day_of_month){ + $by_day_of_month = 1; + } + $ending_datetime = new DateTime( $to_date ); + $ending_date = $ending_datetime->modify('2 years'); + $to_date = $ending_date->format( 'Y-m-d' ); + } else { + $serialized_custom_times = null; + $custom_dates_array = array(); + $this_datetime = null; + // if the dates span more than one day need to build the custom dates array + $starting_datetime = new DateTime( $from_date ); + $ending_datetime = new DateTime( $to_date ); + // loop through for the next 2 years + for ( $year_index = 0; $year_index <= 2; ++$year_index ) { + if ( $year_index !== 0 ) { + // adjust the datetimes plus one year + $starting_datetime->modify( '+ 1 year' ); + $ending_datetime->modify( '+ 1 year' ); + } + $starting_time = $starting_datetime->format( 'U' ); + $ending_time = $ending_datetime->format( 'U' ); + for ($index = $starting_time; $index <= $ending_time; $index += 86400 ) { + $custom_dates_array[] = date( 'Y-m-d', $index ); + } + } + if ( $debug ) { + echo '
$custom_dates_array: ' . print_r($custom_dates_array, true) . '
'; + } + $serialized_custom_times = serialize( $custom_dates_array ); } } - $ending_datetime = new DateTime( $to_date ); - $ending_date = $ending_datetime->modify('2 years'); - $to_date = $ending_date->format( 'Y-m-d' ); break; case "MONTHLY": $monthly_events++; -- 2.17.1