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 30, 2023
2 parents ed36405 + 811499e commit 4cf4821
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 55 deletions.
14 changes: 7 additions & 7 deletions lib/ACF/DynamicEventGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,28 +109,28 @@ protected function register_fields() : void {
*/
protected function get_event_tab( string $key ) : ?Field\Tab {
$strings = [
'tab' => 'Tapahtuma',
'text' => [
'tab' => 'Tapahtuma',
'text' => [
'label' => 'Hakusana',
'instructions' => '',
],
'category' => [
'category' => [
'label' => 'Kategoria',
'instructions' => '',
],
'area' => [
'area' => [
'label' => 'Alue',
'instructions' => '',
],
'target' => [
'target' => [
'label' => 'Kohderyhmä',
'instructions' => '',
],
'tag' => [
'tag' => [
'label' => 'Tag',
'instructions' => '',
],
'event' => [
'event' => [
'label' => 'Tapahtuma',
'instructions' => '',
],
Expand Down
8 changes: 4 additions & 4 deletions lib/ACF/Fields/EventsFields.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,19 @@ protected function sub_fields() : array {
'label' => 'Alkaa tänään',
'instructions' => 'Alkupäivämääränä käytetään kuluvaa päivää',
],
'category' => [
'category' => [
'label' => 'Kategoria',
'instructions' => '',
],
'area' => [
'area' => [
'label' => 'Alue',
'instructions' => '',
],
'target' => [
'target' => [
'label' => 'Kohderyhmä',
'instructions' => '',
],
'tag' => [
'tag' => [
'label' => 'Tag',
'instructions' => '',
],
Expand Down
2 changes: 1 addition & 1 deletion lib/ACF/PageEventsSearchGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ protected function register_fields() : void {
*/
protected function get_page_fields( string $key ) : Field\Tab {
$strings = [
'tab' => 'Tapahtumat',
'tab' => 'Tapahtumat',
'category' => [
'label' => 'Kategoria',
'instructions' => '',
Expand Down
66 changes: 35 additions & 31 deletions lib/Eventz.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ protected function admin_event_search_callback() : void {

if ( ! $events ) {
$lang_key = Localization::get_current_language();
$events = $client->search_events( $params, $lang_key );
$events = $client->search_events( $params, $lang_key );
wp_cache_set( $cache_key, $events, '', MINUTE_IN_SECONDS * 15 );
}

Expand Down Expand Up @@ -97,31 +97,34 @@ public static function normalize_event( $event ) : array {
}

return [
'name' => $event->name ?? null,
'short_description' => static::get_short_description( $event ) ?? null,
'description' => nl2br( $event->description ) ?? null,
'date_title' => __( 'Dates', 'tms-theme-tredu' ),
'date' => static::get_event_date( $event ),
'dates' => static::get_event_dates( $event ),
'recurring' => ! empty( $event->event->dates ),
'time_title' => __( 'Time', 'tms-theme-tredu' ),
'time' => static::get_event_time( $event ),
'location_title' => __( 'Location', 'tms-theme-tredu' ),
'location' => static::get_event_location( $event ),
'price_title' => __( 'Price', 'tms-theme-tredu' ),
'price' => static::get_event_price_info( $event, $lang_key ),
'area_title' => __( 'Area', 'tms-theme-tredu' ),
'areas' => static::get_area_info( $event ),
'target_title' => __( 'Target', 'tms-theme-tredu' ),
'targets' => static::get_target_info( $event ),
'tags_title' => __( 'Tags', 'tms-theme-tredu' ),
'tags' => static::get_tag_info( $event ),
'keywords' => $topics ?? null,
'primary_keyword' => empty( $topics ) ? null : $topics[0],
'links_title' => __( 'Links', 'tms-theme-tredu' ),
'links' => $event->links,
'image' => $image ?? null,
'url' => static::get_event_url( $event->_id ),
'name' => $event->name ?? null,
'short_description' => static::get_short_description( $event ) ?? null,
'description' => nl2br( $event->description ) ?? null,
'date_title' => __( 'Dates', 'tms-theme-tredu' ),
'date' => static::get_event_date( $event ),
'dates' => static::get_event_dates( $event ),
'recurring' => ! empty( $event->event->dates ),
'time_title' => __( 'Time', 'tms-theme-tredu' ),
'time' => static::get_event_time( $event ),
// Include raw dates for possible sorting.
'start_date_raw' => static::get_as_datetime( $event->event->start ),
'end_date_raw' => static::get_as_datetime( $event->event->end ),
'location_title' => __( 'Location', 'tms-theme-tredu' ),
'location' => static::get_event_location( $event ),
'price_title' => __( 'Price', 'tms-theme-tredu' ),
'price' => static::get_event_price_info( $event, $lang_key ),
'area_title' => __( 'Area', 'tms-theme-tredu' ),
'areas' => static::get_area_info( $event ),
'target_title' => __( 'Target', 'tms-theme-tredu' ),
'targets' => static::get_target_info( $event ),
'tags_title' => __( 'Tags', 'tms-theme-tredu' ),
'tags' => static::get_tag_info( $event ),
'keywords' => $topics ?? null,
'primary_keyword' => empty( $topics ) ? null : $topics[0],
'links_title' => __( 'Links', 'tms-theme-tredu' ),
'links' => $event->links,
'image' => $image ?? null,
'url' => static::get_event_url( $event->_id ),
];
}

Expand Down Expand Up @@ -207,7 +210,7 @@ public static function get_event_time( $event ) {
}

/**
* Get event location
* Get event location.
*
* @param object $event Event object.
*
Expand Down Expand Up @@ -258,7 +261,8 @@ public static function get_event_price_info( $event ) : ?array {

if ( empty( $price ) || $event->price->isFree ) {
$price = __( 'Free', 'tms-theme-tredu' );
} else {
}
else {
$min = $event->price->min;
$max = $event->price->max;

Expand All @@ -282,7 +286,7 @@ public static function get_event_price_info( $event ) : ?array {
'url' => null,
],
'description' => null,
]
],
];
}

Expand Down Expand Up @@ -329,7 +333,7 @@ public static function get_tag_info( object $event ) : string {
public static function get_event_dates( $event ) {
$dates = [];

if ( empty ( $event->event->dates ) ) {
if ( empty( $event->event->dates ) ) {
return $dates;
}

Expand Down Expand Up @@ -412,7 +416,7 @@ public static function compare_dates( $start, $end ) {
*/
public static function get_short_description( $event ) {

if ( empty ( $event->description ) ) {
if ( empty( $event->description ) ) {
return null;
}

Expand Down
3 changes: 2 additions & 1 deletion lib/EventzClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ class EventzClient {

/**
* Last request response.
* * @var ?Response
*
* @var mixed
*/
private ?Response $last_response = null;

Expand Down
25 changes: 18 additions & 7 deletions lib/Formatters/EventzFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,20 @@ public function format( array $layout ) : array {
$layout['targets'] = $layout['target'] ? array_values( $layout['target'] ) : [];
$layout['tags'] = $layout['tag'] ? array_values( $layout['tag'] ) : [];

$query_params = $this->format_query_params( $layout );
$query_params['language'] = function_exists( 'pll_current_language' )
$query_params = $this->format_query_params( $layout );
$query_params['language'] = function_exists( 'pll_current_language' )
? pll_current_language()
: get_locale();

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

if ( empty( $events ) ) {
$events = [];
}

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

$events = array_merge( $events, $manual_events );
Expand All @@ -66,7 +70,7 @@ public function format( array $layout ) : array {
return $layout;
}

if( ! empty( $layout['manual_event_categories'] ) ) {
if ( ! empty( $layout['manual_event_categories'] ) ) {
// Sort events by start datetime objects.
usort( $events, function( $a, $b ) {
return $a['start'] <=> $b['start'];
Expand Down Expand Up @@ -180,11 +184,11 @@ private function get_events( array $query_params ) : ?array {
// Force sort param
$query_params['sort'] = 'startDate';

if( ! empty ( $query_params['page_size'] ) ) {
if ( ! empty( $query_params['page_size'] ) ) {
$query_params['size'] = $query_params['page_size'];
}

$client = new EventzClient( PIRKANMAA_EVENTZ_API_URL, PIRKANMAA_EVENTZ_API_KEY );
$client = new EventzClient( PIRKANMAA_EVENTZ_API_URL, PIRKANMAA_EVENTZ_API_KEY );

try {
$lang_key = Localization::get_current_language();
Expand All @@ -206,6 +210,13 @@ private function get_events( array $query_params ) : ?array {
return null;
}

/**
* Get manual events by taxonomy.
*
* @param array $category_ids List of taxonomy ids.
*
* @return array
*/
public static function get_manual_events( array $category_ids = null ) : array {
$args = [
'post_type' => PostType\ManualEvent::SLUG,
Expand Down
4 changes: 2 additions & 2 deletions models/page-event.php
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,8 @@ protected function set_event() : void {

try {
$lang_key = Localization::get_current_language();
$client = new EventzClient( PIRKANMAA_EVENTZ_API_URL, PIRKANMAA_EVENTZ_API_KEY );
$event = $client->get_item( $event_id, $lang_key );
$client = new EventzClient( PIRKANMAA_EVENTZ_API_URL, PIRKANMAA_EVENTZ_API_KEY );
$event = $client->get_item( $event_id, $lang_key );

if ( ! empty( $event ) ) {
$this->event = $event;
Expand Down
4 changes: 2 additions & 2 deletions models/page-events-search.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ protected function get_events() : array {
$start_date = $today;
}

$end_date = get_query_var( self::EVENT_SEARCH_END_DATE );
$end_date = ! empty( $end_date ) ? $end_date : date( 'Y-m-d', strtotime( '+1 year' ) );
$end_date = get_query_var( self::EVENT_SEARCH_END_DATE );
$end_date = ! empty( $end_date ) ? $end_date : date( 'Y-m-d', strtotime( '+1 year' ) );

$paged = get_query_var( 'paged', 1 );
$skip = 0;
Expand Down

0 comments on commit 4cf4821

Please sign in to comment.