Fix for the YEARLY event that spans from one month to the next.
authorSteve Sutton <steve@gaslightmedia.com>
Fri, 24 Jun 2016 19:30:59 +0000 (15:30 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Fri, 24 Jun 2016 19:30:59 +0000 (15:30 -0400)
Had to break these out and create the custom date array and serialize
it.

models/admin/management/events.php

index 4c2ddd6..1a34a9b 100644 (file)
@@ -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 '<pre>$end_day: ' . print_r($end_day, true) . '</pre>';
                                         }
-                                        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 '<pre>$custom_dates_array: ' . print_r($custom_dates_array, true) . '</pre>';
+                                            }
+                                            $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++;