Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Events: Swap out google maps on homepage for event list. #1133

Merged
merged 3 commits into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

<!-- wp:pattern {"slug":"wporg-events-2023/event-list-filters"} /-->

<!-- wp:wporg/google-map {"id":"all-upcoming-list","apiKey":"WORDCAMP_DEV_GOOGLE_MAPS_API_KEY","filterSlug":"all-upcoming","showMap":false,"showSearch":false,"listDisplayLimit":10} /-->
<!-- wp:wporg/event-list {"limit": "10"} /-->

<!-- wp:buttons {"style":{"spacing":{"margin":{"top":"var:preset|spacing|40"}}}} -->
<div class="wp-block-buttons" style="margin-top:var(--wp--preset--spacing--40)"><!-- wp:button {"className":"is-style-outline"} -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
"type": "string",
"default": "all-upcoming"
},
"groupByMonth": {
"type": "boolean",
"default": false
},
"limit": {
"type": "number",
"default": 100
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,43 +45,59 @@ function render( $attributes, $content, $block ) {
// Get all the filters that are currently applied.
$filtered_events = array_slice( filter_events( $events ), 0, (int) $attributes['limit'] );

// Group events by month year.
$grouped_events = array();
foreach ( $filtered_events as $event ) {
$event_month_year = gmdate('F Y', esc_html( $event->timestamp) );
$grouped_events[ $event_month_year ][] = $event;
}

foreach ( $grouped_events as $month_year => $events ) {
$content .= get_section_title( $month_year );
$content .= '<ul class="wporg-marker-list__container">';

foreach ( $events as $event ) {
$content .= '<li class="wporg-marker-list-item">';
$content .= '<h3 class="wporg-marker-list-item__title"><a class="external-link" href="' . esc_url($event->url) . '">' . esc_html($event->title) . '</a></h3>';
$content .= '<div class="wporg-marker-list-item__location">' . esc_html($event->location) . '</div>';
$content .= sprintf(
'<time class="wporg-marker-list-item__date-time" date-time="%1$s" title="%1$s"><span class="wporg-google-map__date">%2$s</span><span class="wporg-google-map__time">%3$s</span></time>',
gmdate( 'c', esc_html( $event->timestamp ) ),
gmdate( 'l, M j', esc_html( $event->timestamp ) ),
esc_html( gmdate('H:i', $event->timestamp) . ' UTC' ),
);
$content .= '</li>';
if ( (bool) $attributes['groupByMonth'] ) {
// Group events by month year.
$grouped_events = array();
foreach ( $filtered_events as $event ) {
$event_month_year = gmdate( 'F Y', esc_html( $event->timestamp ) );
$grouped_events[ $event_month_year ][] = $event;
}

$content .= '</ul>';
$content = '';
foreach ( $grouped_events as $month_year => $events ) {
$content .= get_section_title( $month_year );
$content .= get_list_markup( $events );
}
} else {
$content = get_list_markup( $filtered_events );
}

$wrapper_attributes = get_block_wrapper_attributes( array(
'class' => 'wp-block-wporg-google-map',
) );
$wrapper_attributes = get_block_wrapper_attributes();
return sprintf(
'<div %1$s>%2$s</div>',
$wrapper_attributes,
do_blocks( $content )
);
}

/**
* Returns the event-list markup.
*
* @param array $events Array of events.
*
* @return string
*/
function get_list_markup( $events ) {
$block_markup = '<ul class="wporg-marker-list__container">';

foreach ( $events as $event ) {
$block_markup .= '<li class="wporg-marker-list-item">';
$block_markup .= '<h3 class="wporg-marker-list-item__title"><a class="external-link" href="' . esc_url( $event->url ) . '">' . esc_html( $event->title ) . '</a></h3>';
$block_markup .= '<div class="wporg-marker-list-item__location">' . esc_html( $event->location ) . '</div>';
$block_markup .= sprintf(
'<time class="wporg-marker-list-item__date-time" date-time="%1$s" title="%1$s"><span class="wporg-google-map__date">%2$s</span><span class="wporg-google-map__time">%3$s</span></time>',
gmdate( 'c', esc_html( $event->timestamp ) ),
gmdate( 'l, M j', esc_html( $event->timestamp ) ),
esc_html( gmdate('H:i', $event->timestamp) . ' UTC' ),
);
$block_markup .= '</li>';
}

$block_markup .= '</ul>';

return $block_markup;
}

/**
* Get the query var facts and sanitize them.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<!-- /wp:group -->

<!-- wp:pattern {"slug":"wporg-events-2023/event-list-filters"} /-->
<!-- wp:wporg/event-list {"limit": "500"} /-->
<!-- wp:wporg/event-list {"groupByMonth":"true","limit":"500"} /-->
</div>
<!-- /wp:group -->
</main>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
style="padding-right:var(--wp--preset--spacing--edge-space);padding-bottom:var(--wp--preset--spacing--50);padding-left:var(--wp--preset--spacing--edge-space)">

<!-- wp:pattern {"slug":"wporg-events-2023/event-list-filters"} /-->
<!-- wp:wporg/event-list {"limit": "500"} /-->
<!-- wp:wporg/event-list {"groupByMonth":"true","limit":"500"} /-->
</div>
<!-- /wp:group -->
</main>
Expand Down
Loading