|
7 | 7 |
|
8 | 8 | use SeattleWebCo\WPZoom\Cache;
|
9 | 9 |
|
| 10 | +/** |
| 11 | + * Return a DateTime object with the GMT end time |
| 12 | + * |
| 13 | + * @param string $datetime Date / time to get end. |
| 14 | + * @param integer $duration Duration in minutes. |
| 15 | + * @return DateTime |
| 16 | + */ |
| 17 | +function wp_zoom_end_date_time( string $datetime, int $duration ) { |
| 18 | + $gmt_timezone = new DateTimeZone( 'GMT' ); |
| 19 | + $gmt_datetime = new DateTime( trim( $datetime, 'Z' ), $gmt_timezone ); |
| 20 | + $gmt_datetime->add( DateInterval::createFromDateString( (string) $duration . 'minutes' ) ); |
| 21 | + |
| 22 | + return $gmt_datetime; |
| 23 | +} |
| 24 | + |
10 | 25 | /**
|
11 | 26 | * Format date / time string
|
12 | 27 | *
|
@@ -37,7 +52,7 @@ function wp_zoom_format_date_time( string $datetime, string $timezone = '', stri
|
37 | 52 | * @param integer $duration Duration in minutes.
|
38 | 53 | * @return string
|
39 | 54 | */
|
40 |
| -function wp_zoom_format_get_end_date_time( string $datetime, int $duration ) { |
| 55 | +function wp_zoom_format_end_date_time( string $datetime, int $duration ) { |
41 | 56 | $gmt_timezone = new DateTimeZone( 'GMT' );
|
42 | 57 |
|
43 | 58 | $gmt_datetime = new DateTime( trim( $datetime, 'Z' ), $gmt_timezone );
|
@@ -146,10 +161,11 @@ function( &$webinar ) use ( $wp_zoom ) {
|
146 | 161 | /**
|
147 | 162 | * Get all occurrences of meetings or webinars merged into an array
|
148 | 163 | *
|
149 |
| - * @param string $type Either webinars or meetings. |
| 164 | + * @param string $type Either webinars or meetings. |
| 165 | + * @param boolean $show_past Whether to show occurrences that have ended. |
150 | 166 | * @return array
|
151 | 167 | */
|
152 |
| -function wp_zoom_get_occurrences( $type = 'webinars' ) { |
| 168 | +function wp_zoom_get_occurrences( $type = 'webinars', $show_past = false ) { |
153 | 169 | global $wp_zoom;
|
154 | 170 |
|
155 | 171 | $occurrences = array();
|
@@ -180,6 +196,17 @@ function( $a, $b ) {
|
180 | 196 | }
|
181 | 197 | );
|
182 | 198 |
|
| 199 | + if ( ! $show_past ) { |
| 200 | + $occurrences = array_filter( |
| 201 | + $occurrences, |
| 202 | + function( $occurrence ) { |
| 203 | + $end = wp_zoom_end_date_time( (string) $occurrence['start_time'], (int) $occurrence['duration'] ); |
| 204 | + |
| 205 | + return $end->getTimestamp() > time(); |
| 206 | + } |
| 207 | + ); |
| 208 | + } |
| 209 | + |
183 | 210 | return $occurrences;
|
184 | 211 | }
|
185 | 212 |
|
|
0 commit comments