Skip to content

Commit

Permalink
Merge branch 'TMS-964' into stage
Browse files Browse the repository at this point in the history
  • Loading branch information
aerkkilae committed Aug 29, 2023
2 parents 7663208 + bacd4c6 commit ba5e4e1
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 2 deletions.
63 changes: 63 additions & 0 deletions lib/Formatters/EventzFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
use TMS\Theme\Base\Logger;
use TMS\Theme\Base\Settings;
use TMS\Theme\Base\Localization;
use TMS\Plugin\ManualEvents\PostType;
use TMS\Plugin\ManualEvents\Taxonomy;

/**
* Class EventzFormatter
Expand Down Expand Up @@ -53,10 +55,26 @@ public function format( array $layout ) : array {

$events = $this->get_events( $query_params );

$manual_events = [];
if( ! empty( $layout['manual_event_categories'] ) ) {
$manual_events = self::get_manual_events ( $layout['manual_event_categories'] );
}

$events = array_merge( $events, $manual_events );

if ( empty( $events ) ) {
return $layout;
}

if( ! empty( $layout['manual_event_categories'] ) ) {
// Sort events by start datetime objects.
usort( $events, function( $a, $b ) {
return $a['start'] <=> $b['start'];
} );

$events = array_slice( $events, 0, $layout['page_size'] );
}

$layout['events'] = $this->format_events( $events, $layout['show_images'] );
$layout['classes'] = [
'event_item_bg' => apply_filters( 'tms/theme/layout_events/item_bg_class', 'has-background-secondary' ),
Expand Down Expand Up @@ -189,4 +207,49 @@ private function get_events( array $query_params ) : ?array {

return null;
}

public static function get_manual_events( array $category_ids = null ) : array {
$args = [
'post_type' => PostType\ManualEvent::SLUG,
'posts_per_page' => 200, // phpcs:ignore
'meta_query' => [
[
'key' => 'start_datetime',
'value' => date( 'Y-m-d' ),
'compare' => '>=',
'type' => 'DATE',
],
],
];

if ( ! empty( $category_ids ) ) {
$args['tax_query'] = [
[
'taxonomy' => Taxonomy\ManualEventCategory::SLUG,
'field' => 'term_id',
'terms' => array_values( $category_ids ),
'operator' => 'IN',
],
];
}

$query = new \WP_Query( $args );

if ( empty( $query->posts ) ) {
return [];
}

$events = array_map( function ( $e ) {
$id = $e->ID;
$event = (object) get_fields( $id );
$event->id = $id;
$event->title = get_the_title( $id );
$event->url = get_permalink( $id );
$event->image = has_post_thumbnail( $id ) ? get_the_post_thumbnail_url( $id, 'medium_large' ) : null;

return PostType\ManualEvent::normalize_event( $event );
}, $query->posts );

return $events;
}
}
2 changes: 0 additions & 2 deletions models/page-events-calendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
* Template Name: Tapahtumakalenteri
*/

use TMS\Theme\Base\Formatters\EventsFormatter;
use TMS\Theme\Base\Settings;
use TMS\Theme\Base\Traits\Components;
use TMS\Theme\Base\Traits\Pagination;
Expand Down Expand Up @@ -121,7 +120,6 @@ protected function get_events() : array {
$cache_group = 'page-events-calendar';
$cache_key = md5( wp_json_encode( $params ) );
$response = wp_cache_get( $cache_key, $cache_group );
$response = null;

if ( empty( $response ) ) {

Expand Down
34 changes: 34 additions & 0 deletions partials/views/single-dynamic-event/single-dynamic-event-info.dust
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,37 @@
</div>
</div>
{/event.normalized.links}

{?event.normalized.provider}
<div class="info-group mb-5 {template_classes.info_group|s}">
{>"views/single-dynamic-event/single-dynamic-event-group-title" title=event.normalized.provider_title template_classes=template_classes.info_group_title icon="bullhorn" /}

<div class="info-group__description pr-8 pb-3 pl-8">
<div>{event.normalized.provider.name|s}</div>

{?event.normalized.provider.email}
<div>
<a href="mailto:{event.normalized.provider.email}"
class="has-text-black">
{event.normalized.provider.email|s}
</a>
</div>
{/event.normalized.provider.email}

{?event.normalized.provider.phone}
<div>
<a href="tel:{event.normalized.provider.phone}"
class="has-text-black">
{event.normalized.provider.phone|s}
</a>
</div>
{/event.normalized.provider.phone}
</div>
</div>

{>"ui/button-link" link=event.normalized.provider.link classes="is-primary mt-3 {template_classes.info_button|s}" icon="chevron-right" icon_classes="icon--medium" /}
{/event.normalized.provider}

{?event.normalized.virtual_event_link}
{>"ui/button-link" link=event.normalized.virtual_event_link classes="is-primary mt-3 {template_classes.info_button|s}" icon="chevron-right" icon_classes="icon--medium" /}
{/event.normalized.virtual_event_link}

0 comments on commit ba5e4e1

Please sign in to comment.