diff --git a/wp-content/themes/clarity/functions.php b/wp-content/themes/clarity/functions.php index 4617a649b..16b1cc0eb 100644 --- a/wp-content/themes/clarity/functions.php +++ b/wp-content/themes/clarity/functions.php @@ -52,8 +52,6 @@ require_once 'inc/api/get-campaign-posts-api.php'; require_once 'inc/api/get-news-rest-api.php'; require_once 'inc/api/get-campaign-news-api.php'; -require_once 'inc/api/get-events-api.php'; -require_once 'inc/api/add-eventsdates-rest-api.php'; require_once 'inc/api/get-category-news-api.php'; require_once 'inc/api/intranet-v1-api.php'; require_once 'inc/api/register-api-fields.php'; diff --git a/wp-content/themes/clarity/inc/api/add-eventsdates-rest-api.php b/wp-content/themes/clarity/inc/api/add-eventsdates-rest-api.php deleted file mode 100644 index 32e161db7..000000000 --- a/wp-content/themes/clarity/inc/api/add-eventsdates-rest-api.php +++ /dev/null @@ -1,381 +0,0 @@ -[a-zA-Z0-9-]+)/', - array( - 'methods' => 'GET', - 'callback' => 'add_custom_events_endpoint', - 'permission_callback' => function ( WP_REST_Request $request ) { - return true; - }, - ) - ); - - // Events by search (keywords) - register_rest_route( - 'intranet/v2/', - 'future-events/(?P[a-zA-Z0-9-]+)/(?P[a-z0-9]+(?:-[a-z0-9]+)*)/', - array( - 'methods' => 'GET', - 'callback' => 'add_custom_events_endpoint', - 'args' => array( - 'search' => array( - 'required' => true, - ), - 'agency' => array( - 'required' => true, - ), - ), - 'permission_callback' => function ( WP_REST_Request $request ) { - return true; - }, - ) - ); - - // Events by regions - register_rest_route( - 'intranet/v2/', - 'region-events/(?P[a-zA-Z0-9-]+)/(?P[a-z0-9]+(?:-[a-z0-9]+)*)', - array( - 'methods' => 'GET', - 'callback' => 'add_region_events_endpoint', - 'args' => array( - 'agency' => array( - 'required' => true, - ), - 'region' => array( - 'required' => true, - ), - ), - 'permission_callback' => function ( WP_REST_Request $request ) { - return true; - }, - ) - ); - - // Events by regions - register_rest_route( - 'intranet/v2/', - 'region-events/(?P[a-zA-Z0-9-]+)/(?P[a-z0-9]+(?:-[a-z0-9]+)*)/(?P[a-z0-9]+(?:-[a-z0-9]+)*)', - array( - 'methods' => 'GET', - 'callback' => 'add_region_events_endpoint', - 'args' => array( - 'agency' => array( - 'required' => true, - ), - 'region' => array( - 'required' => true, - ), - 'postcount' => array( - 'required' => true, - ), - ), - 'permission_callback' => function ( WP_REST_Request $request ) { - return true; - }, - ) - ); - // Events by campaigns - register_rest_route( - 'intranet/v2/', - 'campaign-events/(?P[a-zA-Z0-9-]+)/(?P[a-z0-9]+(?:-[a-z0-9]+)*)/', - array( - 'methods' => 'GET', - 'callback' => 'add_campaign_events_endpoint', - 'args' => array( - 'agency' => array( - 'required' => true, - ), - 'campaign' => array( - 'required' => true, - ), - ), - 'permission_callback' => function ( WP_REST_Request $request ) { - return true; - }, - ) - ); - } -); - -function add_campaign_events_endpoint( WP_REST_Request $request ) { - // Order By - $options['search_orderby'] = array( - '_event-start-date' => 'ASC', - '_event-end-date' => 'ASC', - 'title' => 'ASC', - ); - - // Get events that are for today onwards - $options['meta_query'] = array( - array( - 'relation' => 'OR', - array( - 'key' => '_event-start-date', - 'value' => date( 'Y-m-d' ), - 'type' => 'date', - 'compare' => '>=', - ), - array( - 'key' => '_event-end-date', - 'value' => date( 'Y-m-d' ), - 'type' => 'date', - 'compare' => '>=', - ), - ), - ); - - // request the query given in the url - $campaign = $request['campaign']; - $agency = $request['agency']; - - $args = array( - 'orderby' => $options['search_orderby'], - 'meta_query' => $options['meta_query'], - 'post_type' => 'event', - 'posts_per_page' => -1, - 'nopaging' => true, - 'tax_query' => array( - array( - 'taxonomy' => 'agency', - 'field' => 'term_id', - 'terms' => $agency, - ), - array( - 'taxonomy' => 'campaign_category', - 'field' => 'term_id', - 'terms' => $campaign, - ), - ), - ); - - $events = get_posts( $args ); - - $i = 0; - - foreach ( $events as $event ) { - $events[ $i ]->event_start_date = get_post_meta( $event->ID, '_event-start-date', true ); - $events[ $i ]->event_end_date = get_post_meta( $event->ID, '_event-end-date', true ); - $events[ $i ]->event_start_time = get_post_meta( $event->ID, '_event-start-time', true ); - $events[ $i ]->event_end_time = get_post_meta( $event->ID, '_event-end-time', true ); - $events[ $i ]->event_location = get_post_meta( $event->ID, '_event-location', true ); - $events[ $i ]->event_allday = get_post_meta( $event->ID, '_event-allday', true ); - - $events[ $i ]->agency = wp_get_post_terms( $event->ID, 'agency' ); - $events[ $i ]->region = wp_get_post_terms( $event->ID, 'region', true ); - $events[ $i ]->campaign = wp_get_post_terms( $event->ID, 'campaign_category', true ); - - $events[ $i ]->url = get_post_permalink( $event->ID ); - - $i ++; - } - - if ( empty( $events ) ) { - return null; - } - - // count number of posts - $total_post_count = count( $events ); - - // display url parameters on json api. - $url_query = array( - 'agency' => $agency, - 'campaign' => $campaign, - 'post_count' => $total_post_count, - ); - - return $arrayJson = array( - 'url' => $url_query, - 'events' => $events, - ); -} - -function add_region_events_endpoint( WP_REST_Request $request ) { - // Order By - $options['search_orderby'] = array( - '_event-start-date' => 'ASC', - '_event-end-date' => 'ASC', - 'title' => 'ASC', - ); - - // Get events that are for today onwards - $options['meta_query'] = array( - array( - 'relation' => 'OR', - array( - 'key' => '_event-start-date', - 'value' => date( 'Y-m-d' ), - 'type' => 'date', - 'compare' => '>=', - ), - array( - 'key' => '_event-end-date', - 'value' => date( 'Y-m-d' ), - 'type' => 'date', - 'compare' => '>=', - ), - ), - ); - - // request the query given in the url - $region = $request['region']; - $agency = $request['agency']; - $postcount = $request['postcount']; - - $args = array( - 'orderby' => $options['search_orderby'], - 'meta_query' => $options['meta_query'], - 'post_type' => 'event', - 'posts_per_page' => $postcount, - 'nopaging' => false, - 'tax_query' => array( - array( - 'taxonomy' => 'agency', - 'field' => 'term_id', - 'terms' => $agency, - ), - array( - 'taxonomy' => 'region', - 'field' => 'term_id', - 'terms' => $region, - ), - ), - ); - - $events = get_posts( $args ); - - $i = 0; - - foreach ( $events as $event ) { - $events[ $i ]->event_start_date = get_post_meta( $event->ID, '_event-start-date', true ); - $events[ $i ]->event_end_date = get_post_meta( $event->ID, '_event-end-date', true ); - $events[ $i ]->event_start_time = get_post_meta( $event->ID, '_event-start-time', true ); - $events[ $i ]->event_end_time = get_post_meta( $event->ID, '_event-end-time', true ); - $events[ $i ]->event_location = get_post_meta( $event->ID, '_event-location', true ); - $events[ $i ]->event_allday = get_post_meta( $event->ID, '_event-allday', true ); - - $events[ $i ]->agency = wp_get_post_terms( $event->ID, 'agency' ); - $events[ $i ]->region = wp_get_post_terms( $event->ID, 'region', true ); - $events[ $i ]->campaign = wp_get_post_terms( $event->ID, 'campaign_category', true ); - - $events[ $i ]->url = get_post_permalink( $event->ID ); - - $i ++; - } - - if ( empty( $events ) ) { - return null; - } - - // count number of posts - $total_post_count = count( $events ); - - // display url parameters on json api. - $url_query = array( - 'agency' => $agency, - 'region' => $region, - 'post_count_input' => $postcount, - 'total_posts' => $total_post_count, - ); - - return $arrayJson = array( - 'url' => $url_query, - 'events' => $events, - ); -} - -function add_custom_events_endpoint( WP_REST_Request $request ) { - // Order By - $options['search_orderby'] = array( - '_event-start-date' => 'ASC', - '_event-end-date' => 'ASC', - 'title' => 'ASC', - ); - - // Get events that are for today onwards - $options ['meta_query'] = array( - array( - 'relation' => 'OR', - array( - 'key' => '_event-start-date', - 'value' => date( 'Y-m-d' ), - 'type' => 'date', - 'compare' => '>=', - ), - array( - 'key' => '_event-end-date', - 'value' => date( 'Y-m-d' ), - 'type' => 'date', - 'compare' => '>=', - ), - ), - ); - - // request the query given in the url - $search = $request['search']; - $agency = $request['agency']; - - $args = array( - 'orderby' => $options['search_orderby'], - 'meta_query' => $options['meta_query'], - 'post_type' => 'event', - 's' => $search, - 'posts_per_page' => -1, - 'nopaging' => true, - 'tax_query' => array( - array( - 'taxonomy' => 'agency', - 'field' => 'term_id', - 'terms' => $agency, - ), - ), - ); - - $events = get_posts( $args ); - - $i = 0; - - foreach ( $events as $event ) { - $events[ $i ]->event_start_date = get_post_meta( $event->ID, '_event-start-date', true ); - $events[ $i ]->event_end_date = get_post_meta( $event->ID, '_event-end-date', true ); - $events[ $i ]->event_start_time = get_post_meta( $event->ID, '_event-start-time', true ); - $events[ $i ]->event_end_time = get_post_meta( $event->ID, '_event-end-time', true ); - $events[ $i ]->event_location = get_post_meta( $event->ID, '_event-location', true ); - $events[ $i ]->event_allday = get_post_meta( $event->ID, '_event-allday', true ); - - $events[ $i ]->agency = wp_get_post_terms( $event->ID, 'agency' ); - $events[ $i ]->region = wp_get_post_terms( $event->ID, 'region', true ); - $events[ $i ]->campaign = wp_get_post_terms( $event->ID, 'campaign_category', true ); - - $events[ $i ]->url = get_post_permalink( $event->ID ); - - $i ++; - } - - if ( empty( $events ) ) { - return null; - } - - // count number of posts - $total_post_count = count( $events ); - - // display url parameters on json api. - $url_query = array( - 'agency' => $agency, - 'search' => $search, - 'post_count' => $total_post_count, - ); - - return $arrayJson = array( - 'url' => $url_query, - 'events' => $events, - ); -} diff --git a/wp-content/themes/clarity/inc/api/get-events-api.php b/wp-content/themes/clarity/inc/api/get-events-api.php deleted file mode 100644 index edc577639..000000000 --- a/wp-content/themes/clarity/inc/api/get-events-api.php +++ /dev/null @@ -1,94 +0,0 @@ -getCurrentAgency(); - $agency_name = $activeAgency['wp_tag_id']; - - /* - * A temporary measure so that API calls do not get blocked by - * changing IPs not whitelisted. All calls are within container. - */ - $siteurl = 'http://127.0.0.1'; - - if ( $taxonomy === 'search' ) { - $response = wp_remote_get( $siteurl . '/wp-json/intranet/v2/future-events/' . $agency_name ); - } elseif ( $taxonomy === 'region' ) { - $response = wp_remote_get( $siteurl . '/wp-json/intranet/v2/region-events/' . $agency_name . '/' . $tax_id . '/' . '30' ); - } elseif ( $taxonomy === 'region_landing' ) { - $response = wp_remote_get( $siteurl . '/wp-json/intranet/v2/region-events/' . $agency_name . '/' . $tax_id . '/' . '4' ); - } elseif ( $taxonomy === 'campaign' ) { - $response = wp_remote_get( $siteurl . '/wp-json/intranet/v2/campaign-events/' . $agency_name . '/' . $tax_id . '/' ); - } - - if ( is_wp_error( $response ) ) { - return; - } - - $pagetotal = wp_remote_retrieve_header( $response, 'x-wp-totalpages' ); - $posts = json_decode( wp_remote_retrieve_body( $response ), true ); - $response_code = wp_remote_retrieve_response_code( $response ); - $response_message = wp_remote_retrieve_response_message( $response ); - - if ( 200 == $response_code && $response_message == 'OK' ) : - - if ( $posts ) : - echo '
'; - echo '

Events

'; - foreach ( $posts['events'] as $key => $post ) : - $event_start_date = $post['event_start_date']; - $event_end_date = $post['event_end_date']; - $start_date = date( 'd M Y', strtotime( $event_start_date ) ); - $end_date = date( 'd M Y', strtotime( $event_end_date ) ); - $get_year = date( 'Y', strtotime( $event_start_date ) ); - $get_month = date( 'M', strtotime( $event_start_date ) ); - $get_day = date( 'F', strtotime( $event_start_date ) ); - $get_day_num = date( 'd', strtotime( $event_start_date ) ); - $multiday = $event_start_date != $event_end_date; - $start_time = $post['event_start_time']; - $end_time = $post['event_end_time']; - $location = $post['event_location']; - ?> - -
- - -

- -
- -

Date:

- - -

Time:

- - -
- - -
-

Location:

-
-
- - - -
- - getCurrentAgency(); - $agency_name = $activeAgency['wp_tag_id']; - $datevalueselected = sanitize_text_field( $_POST['valueSelected'] ); + $agency_term_id = $activeAgency['wp_tag_id']; + $date_filter = sanitize_text_field( $_POST['valueSelected'] ); $post_id = get_the_ID(); $query = sanitize_text_field( $_POST['query'] ); - if ( isset( $_POST['termID'] ) ) : - $tax_id = sanitize_text_field( $_POST['termID'] ); - endif; + $filter_options = ['keyword_search' => $query]; - /* - * A temporary measure so that API calls do not get blocked by - * changing IPs not whitelisted. All calls are within container. - */ - $siteurl = 'http://127.0.0.1'; + if($date_filter != 'all'){ + $filter_options['date_filter'] = $date_filter; + } + + $EventsHelper = new EventsHelper(); + + if ( isset( $_POST['termID'] ) ) { + $tax_id = sanitize_text_field($_POST['termID']); + + $filter_options['region_filter'] = $tax_id; + + $events = $EventsHelper->get_events($agency_term_id, $filter_options); + } + else { + $events = $EventsHelper->get_events($agency_term_id, $filter_options); + } + + if ( $events ) { + + echo '
'; + + foreach ( $events as $key => $event ) : + + $event_id = $event->ID; + $post_url = $event->url; + $event_title = $event->post_title; + + $start_date = $event->event_start_date; + $end_date = $event->event_end_date; + $start_time = $event->event_start_time; + $end_time = $event->event_end_time; + $location = $event->event_location; + $date = $event->event_start_date; + $day = date( 'l', strtotime( $start_date ) ); + $month = date( 'M', strtotime( $start_date ) ); + $year = date( 'Y', strtotime( $start_date ) ); + $all_day = $event->event_allday; + + if ( $all_day == true ) { + $all_day = 'all_day'; + } + + echo '
'; + + include locate_template( 'src/components/c-calendar-icon/view.php' ); + + include locate_template( 'src/components/c-events-item-byline/view.php' ); + + echo '
'; - // HMCTS taxonomy ID = 100 becuase right now we only use HMCTS for regions - if ( $agency_name === 100 ) : - $response = wp_remote_get( $siteurl . '/wp-json/intranet/v2/region-events/' . $agency_name . '/' . $tax_id . '/' ); else : - $response = wp_remote_get( $siteurl . '/wp-json/intranet/v2/future-events/' . $agency_name . '/' . $query . '/' ); - endif; - - if ( is_wp_error( $response ) ) : - return; - endif; - - $pagetotal = wp_remote_retrieve_header( $response, 'x-wp-totalpages' ); - $posts = json_decode( wp_remote_retrieve_body( $response ), true ); - $response_code = wp_remote_retrieve_response_code( $response ); - $response_message = wp_remote_retrieve_response_message( $response ); - - if ( $posts ) : - if ( 200 == $response_code && $response_message == 'OK' ) : - echo '
'; - foreach ( $posts['events'] as $key => $post ) : - $start_date = $post['event_start_date']; - $end_date = $post['event_end_date']; - $event_id = $post['ID']; - $post_url = $post['url']; - $event_title = $post['post_title']; - $start_time = $post['event_start_time']; - $end_time = $post['event_end_time']; - $start_date = $post['event_start_date']; - $end_date = $post['event_end_date']; - $location = $post['event_location']; - $date = $post['event_start_date']; - $year = date( 'Y', strtotime( $start_date ) ); - $month = date( 'M', strtotime( $start_date ) ); - $day = date( 'l', strtotime( $start_date ) ); - $all_day = get_post_meta( $post_id, '_event-allday', true ); - $strip_start_date = substr( $start_date, 0, 7 ); - - if ( $all_day == true ) : - $all_day = 'all_day'; - endif; - - if ( $datevalueselected === $strip_start_date ) : - echo '
'; - include locate_template( 'src/components/c-calendar-icon/view.php' ); - include locate_template( 'src/components/c-events-item-byline/view.php' ); - echo '
'; elseif ( $datevalueselected === 'all' ) : - echo '
'; - include locate_template( 'src/components/c-calendar-icon/view.php' ); - include locate_template( 'src/components/c-events-item-byline/view.php' ); - echo '
'; - endif; - endforeach; - endif; else : - echo 'No events found during this date range :('; - endif; - die(); + endforeach; + } + else { + echo 'No events found during this date range :('; + } + die(); } add_action( 'wp_ajax_load_search_results', 'load_search_results' ); @@ -249,7 +243,6 @@ function load_page_total() { $current_page = '&page=' . $nextPageToRetrieve; $search = '&search=' . $query; $agency_name = '&agency=' . $activeAgency['wp_tag_id']; - $onlyshow_todays_onwards = ( $postType == 'event' ) ? '&order=asc&after=' . current_time( 'Y-m-d h:i:s' ) : ''; $news_category_name = ( ! empty( $newsCategory_ID ) ? '&news_category=' . $newsCategory_ID : '' ); /* @@ -258,7 +251,7 @@ function load_page_total() { */ $siteurl = 'http://127.0.0.1'; - $response = wp_remote_get( $siteurl . '/wp-json/wp/v2/' . $postType . '/?' . $post_per_page . $current_page . $agency_name . $valueSelected . $onlyshow_todays_onwards . $search . $news_category_name ); + $response = wp_remote_get( $siteurl . '/wp-json/wp/v2/' . $postType . '/?' . $post_per_page . $current_page . $agency_name . $valueSelected . $search . $news_category_name ); $pagetotal = wp_remote_retrieve_header( $response, 'x-wp-totalpages' ); diff --git a/wp-content/themes/clarity/inc/event.php b/wp-content/themes/clarity/inc/event.php deleted file mode 100644 index a99fe0417..000000000 --- a/wp-content/themes/clarity/inc/event.php +++ /dev/null @@ -1,49 +0,0 @@ -getCurrentAgency(); - $agency_name = $activeAgency['wp_tag_id']; - - /* - * A temporary measure so that API calls do not get blocked by - * changing IPs not whitelisted. All calls are within container. - */ - $siteurl = 'http://127.0.0.1'; - - if ( $taxonomy === 'search' ) { - $response = wp_remote_get( $siteurl . '/wp-json/intranet/v2/future-events/' . $agency_name ); - } elseif ( $taxonomy === 'region' ) { - $response = wp_remote_get( $siteurl . '/wp-json/intranet/v2/region-events/' . $agency_name . '/' . $tax_id . '/' ); - } elseif ( $taxonomy === 'campaign' ) { - $response = wp_remote_get( $siteurl . '/wp-json/intranet/v2/campaign-events/' . $agency_name . '/' . $tax_id . '/' ); - } - - if ( is_wp_error( $response ) ) { - return; - } - - $pagetotal = wp_remote_retrieve_header( $response, 'x-wp-totalpages' ); - $posts = json_decode( wp_remote_retrieve_body( $response ), true ); - $response_code = wp_remote_retrieve_response_code( $response ); - $response_message = wp_remote_retrieve_response_message( $response ); - - if ( 200 == $response_code && $response_message == 'OK' ) { - $event_list = $posts['events']; - return $event_list; - } - } -} diff --git a/wp-content/themes/clarity/inc/events.php b/wp-content/themes/clarity/inc/events.php deleted file mode 100644 index fba0b996c..000000000 --- a/wp-content/themes/clarity/inc/events.php +++ /dev/null @@ -1,88 +0,0 @@ -searchHelper = new HelperSearch(); - } - - - /** Get a list of events - * @param {Array} $options Options and filters (see search model for details) - * @return {Array} Formatted and sanitized results - */ - public function getEvents($options = array()) { - $options['search_orderby'] = array( - '_event-start-date' => 'ASC', - '_event-end-date' => 'ASC', - 'title' => 'ASC', - ); - $options['meta_fields'] = array('_event-start-date', '_event-end-date'); - $options['post_type'] = 'event'; - $options['date'] = get_array_value($options, 'date', 'today'); - - if (!empty($options['tax_query']) && !has_taxonomy($options['tax_query'], 'region')) { - $term_slugs = get_term_slugs('region'); - - $options['tax_query'][] = [ - 'taxonomy' => 'region', - 'field' => 'slug', - 'terms' => $term_slugs, - 'operator' => 'NOT IN' - ]; - } - - $data = $this->searchHelper->get_raw($options); - $data = $this->format_data($data); - - return $data; - } - - /** Format and trim the raw results - * @param {Object} $data Raw results object - * @return {Array} Formatted results - */ - private function format_data($data) { - $results = array (); - - foreach($data['raw']->posts as $post) { - $results[] = $this->format_row($post); - } - - unset($data['raw']); - - return $results; - } - - /** Format a single results row - * @param {Object} $post Post object - * @return {Array} Formatted and trimmed post - */ - private function format_row($post) { - $id = $post->ID; - - $start_date = get_post_meta($id, '_event-start-date', true); - $end_date = get_post_meta($id, '_event-end-date', true); - - return array( - 'id' => $id, - 'title' => (string) get_the_title($id), - 'url' => (string) get_the_permalink($id), - 'slug' => (string) $post->post_name, - 'location' => (string) get_post_meta($id, '_event-location', true), - 'description' => (string) get_the_content_by_id($id), - 'start_date' => (string) $start_date, - 'start_time' => (string) get_post_meta($id, '_event-start-time', true), - 'end_date' => (string) $end_date, - 'end_time' => (string) get_post_meta($id, '_event-end-time', true), - 'all_day' => get_post_meta($id, '_event-allday', true) == true, - 'multiday' => (string) $start_date !== $end_date - ); - } -} diff --git a/wp-content/themes/clarity/inc/eventshelper.php b/wp-content/themes/clarity/inc/eventshelper.php new file mode 100644 index 000000000..549340f9f --- /dev/null +++ b/wp-content/themes/clarity/inc/eventshelper.php @@ -0,0 +1,176 @@ + 'event', + 'posts_per_page' => 1, + 'p' => $event_id, + ); + + $event = get_posts( $args ); + + if(is_array($event) && count($event) == 1){ + $event[0]->event_start_date = get_post_meta( $event[0]->ID, '_event-start-date', true ); + $event[0]->event_end_date = get_post_meta( $event[0]->ID, '_event-end-date', true ); + $event[0]->event_start_time = get_post_meta( $event[0]->ID, '_event-start-time', true ); + $event[0]->event_end_time = get_post_meta( $event[0]->ID, '_event-end-time', true ); + $event[0]->event_location = get_post_meta( $event[0]->ID, '_event-location', true ); + $event[0]->event_allday = get_post_meta( $event[0]->ID, '_event-allday', true ); + + $event[0]->agency = wp_get_post_terms( $event[0]->ID, 'agency' ); + $event[0]->region = wp_get_post_terms( $event[0]->ID, 'region', true ); + $event[0]->campaign = wp_get_post_terms( $event[0]->ID, 'campaign_category', true ); + + $event[0]->url = get_post_permalink( $event[0]->ID ); + + return $event[0]; + + } + else { + return false; + } + } + + function get_events($agency, $filter_options = false){ + + // Order By + $orderby = array( + 'start_date_clause' => 'ASC', + 'start_time_clause' => 'ASC', + ); + + $args = array( + 'orderby' => $orderby, + 'post_type' => 'event', + 'posts_per_page' => -1, + 'nopaging' => true, + ); + + //set taxonomy query + $tax_query = array( + array( + 'taxonomy' => 'agency', + 'field' => 'term_id', + 'terms' => $agency, + ), + ); + + if(is_array($filter_options)){ + + if( key_exists('campaign_filter', $filter_options ) && is_numeric($filter_options['campaign_filter']) ) { + $tax_query[] = array( + 'taxonomy' => 'campaign_category', + 'field' => 'term_id', + 'terms' => $filter_options['campaign_filter'], + ); + } + + if( key_exists('region_filter', $filter_options ) && is_numeric($filter_options['region_filter']) ) { + $tax_query[] = array( + 'taxonomy' => 'region', + 'field' => 'term_id', + 'terms' => $filter_options['region_filter'], + ); + } + + } + + $args['tax_query'] = $tax_query; + + + // Set meta query + $meta_query = array( + array( + 'relation' => 'OR', + array( + 'key' => '_event-start-date', + 'value' => date('Y-m-d'), + 'type' => 'date', + 'compare' => '>=', + ), + array( + 'key' => '_event-end-date', + 'value' => date('Y-m-d'), + 'type' => 'date', + 'compare' => '>=', + ), + ), + array( + 'start_date_clause' => array( + 'key' => '_event-start-date', + 'compare' => 'EXISTS', + ), + ), + array( + 'start_time_clause' => array( + 'key' => '_event-start-time', + 'compare' => 'EXISTS', + ), + ) + ); + + if(is_array($filter_options) && key_exists('date_filter', $filter_options ) && strlen($filter_options['date_filter']) > 0 ){ + + $month_start_date = $filter_options['date_filter'] . '-' . '1'; + $month_end_date = date("Y-m-t", strtotime($month_start_date)); + $meta_query[] = array( + 'relation' => 'AND', + array( + 'key' => '_event-start-date', + 'value' => $month_end_date, + 'type' => 'date', + 'compare' => '<=', + ), + array( + 'key' => '_event-end-date', + 'value' => $month_start_date, + 'type' => 'date', + 'compare' => '>=', + ), + ); + } + + $args['meta_query'] = $meta_query; + + + if(is_array($filter_options) && key_exists('keyword_search', $filter_options ) && strlen($filter_options['keyword_search']) > 0 ){ + $args['s'] = $filter_options['keyword_search']; + } + + $events = get_posts( $args ); + + $i = 0; + + foreach ( $events as $event ) { + $events[ $i ]->event_start_date = get_post_meta( $event->ID, '_event-start-date', true ); + $events[ $i ]->event_end_date = get_post_meta( $event->ID, '_event-end-date', true ); + $events[ $i ]->event_start_time = get_post_meta( $event->ID, '_event-start-time', true ); + $events[ $i ]->event_end_time = get_post_meta( $event->ID, '_event-end-time', true ); + $events[ $i ]->event_location = get_post_meta( $event->ID, '_event-location', true ); + $events[ $i ]->event_allday = get_post_meta( $event->ID, '_event-allday', true ); + + $events[ $i ]->agency = wp_get_post_terms( $event->ID, 'agency' ); + $events[ $i ]->region = wp_get_post_terms( $event->ID, 'region', true ); + $events[ $i ]->campaign = wp_get_post_terms( $event->ID, 'campaign_category', true ); + + $events[ $i ]->url = get_post_permalink( $event->ID ); + + $i ++; + } + + if ( empty( $events ) ) { + return null; + } + else { + return $events; + } + + + } + +} diff --git a/wp-content/themes/clarity/inc/search.php b/wp-content/themes/clarity/inc/search.php deleted file mode 100644 index 437fae9a2..000000000 --- a/wp-content/themes/clarity/inc/search.php +++ /dev/null @@ -1,305 +0,0 @@ -getCurrentAgency(); - - $agency_name = $activeAgency['wp_tag_id']; - $datevalueselected = $_POST['valueSelected']; - $query = $_POST['query']; - /* - * A temporary measure so that API calls do not get blocked by - * changing IPs not whitelisted. All calls are within container. - */ - $siteurl = 'http://127.0.0.1'; - $response = wp_remote_get($siteurl.'/wp-json/intranet/v2/future-events/' . $agency_name . '/' . $query . '/'); - - if (is_wp_error($response)) { - return; - } - - $pagetotal = wp_remote_retrieve_header($response, 'x-wp-totalpages'); - $posts = json_decode(wp_remote_retrieve_body($response), true); - $response_code = wp_remote_retrieve_response_code($response); - $response_message = wp_remote_retrieve_response_message($response); - - if (200 == $response_code && $response_message == 'OK') { - echo '
'; - - foreach ($posts['events'] as $key => $post) { - $start_date = $post['event_start_date']; - $end_date = $post['event_end_date']; - $event_id = $post['ID']; - $post_url = $post["url"]; - $event_title = $post["post_title"]; - $start_time = $post['event_start_time']; - $end_time = $post['event_end_time']; - $start_date = $post['event_start_date']; - $end_date = $post['event_end_date']; - $location = $post['event_location']; - $date = $post['event_start_date']; - $year = date('Y', strtotime($start_date)); - $month = date('M', strtotime($start_date)); - $day = date('l', strtotime($start_date)); - $all_day = get_post_meta($post_id, '_event-allday', true); - $strip_start_date = substr($start_date, 0, 7); - - if ($all_day == true) { - $all_day = 'all_day'; - } - - if ($datevalueselected === $strip_start_date) { - echo '
'; - include(locate_template('src/components/c-calendar-icon/view.php')); - include(locate_template('src/components/c-events-item-byline/view.php')); - echo '
'; - } elseif ($datevalueselected === 'all') { - echo '
'; - include(locate_template('src/components/c-calendar-icon/view.php')); - include(locate_template('src/components/c-events-item-byline/view.php')); - echo '
'; - } - } - } - die(); -} - -function load_search_results() -{ - $query = $_POST['query']; - $valueSelected = $_POST['valueSelected']; - $postType = $_POST['postType']; - - $oAgency = new Agency(); - $activeAgency = $oAgency->getCurrentAgency(); - - $post_per_page = 'per_page=10'; - $search = (!empty($query) ? '&search=' . $query : ''); - $agency_name = '&agency=' . $activeAgency['wp_tag_id']; - - /* - * A temporary measure so that API calls do not get blocked by - * changing IPs not whitelisted. All calls are within container. - */ - $siteurl = 'http://127.0.0.1'; - - $response = wp_remote_get($siteurl.'/wp-json/wp/v2/'.$postType.'/?' . $post_per_page . $agency_name . $valueSelected . $search); - - $post_total = wp_remote_retrieve_header($response, 'x-wp-total'); - $posts = json_decode(wp_remote_retrieve_body($response), true); - - $response_code = wp_remote_retrieve_response_code($response); - $response_message = wp_remote_retrieve_response_message($response); - - if (200 == $response_code && $response_message == 'OK') { - echo '
'; - foreach ($posts as $key => $post) { - ?> - - getCurrentAgency(); - - $post_per_page = 'per_page=10'; - $current_page = '&page='. $nextPageToRetrieve; - - $search = (!empty($query) ? '&search=' . $query : ''); - $agency_name = '&agency=' . $activeAgency['wp_tag_id']; - - /* - * A temporary measure so that API calls do not get blocked by - * changing IPs not whitelisted. All calls are within container. - */ - $siteurl = 'http://127.0.0.1'; - - $response = wp_remote_get($siteurl.'/wp-json/wp/v2/'.$postType.'/?' . $post_per_page . $current_page . $agency_name . $valueSelected . $search); - - $pagetotal = wp_remote_retrieve_header($response, 'x-wp-totalpages'); - - $posts = json_decode(wp_remote_retrieve_body($response), true); - - $response_code = wp_remote_retrieve_response_code($response); - $response_message = wp_remote_retrieve_response_message($response); - - if (200 == $response_code && $response_message == 'OK') { - echo '
'; - foreach ($posts as $key => $post) { - ?> - - getCurrentAgency(); - - $post_per_page = 'per_page=10'; - $search = (!empty($query) ? '&search=' . $query : ''); - $agency_name = '&agency=' . $activeAgency['wp_tag_id']; - - /* - * A temporary measure so that API calls do not get blocked by - * changing IPs not whitelisted. All calls are within container. - */ - $siteurl = 'http://127.0.0.1'; - - $response = wp_remote_get($siteurl.'/wp-json/wp/v2/'.$postType.'/?' . $post_per_page . $agency_name . $valueSelected . $search); - $post_total = wp_remote_retrieve_header($response, 'x-wp-total'); - - echo $post_total . ' search results'; - - die(); -} -add_action('wp_ajax_load_search_results_total', 'load_search_results_total'); -add_action('wp_ajax_nopriv_load_search_results_total', 'load_search_results_total'); - -function load_page_total() -{ - $nextPageToRetrieve = $_POST['nextPageToRetrieve']; - $query = $_POST['query']; - $valueSelected = $_POST['valueSelected']; - $postType = $_POST['postType']; - - $oAgency = new Agency(); - $activeAgency = $oAgency->getCurrentAgency(); - - $post_per_page = 'per_page=10'; - $current_page = '&page='. $nextPageToRetrieve; - $search = '&search=' . $query; - $agency_name = '&agency=' . $activeAgency['wp_tag_id']; - $onlyshow_todays_onwards = ($postType == 'event') ? '&order=asc&after='. current_time('Y-m-d h:i:s') : ''; - - /* - * A temporary measure so that API calls do not get blocked by - * changing IPs not whitelisted. All calls are within container. - */ - $siteurl = 'http://127.0.0.1'; - - $response = wp_remote_get($siteurl.'/wp-json/wp/v2/'.$postType.'/?' . $post_per_page . $current_page . $agency_name . $valueSelected . $onlyshow_todays_onwards . $search); - - $pagetotal = wp_remote_retrieve_header($response, 'x-wp-totalpages'); - - $response_code = wp_remote_retrieve_response_code($response); - $response_message = wp_remote_retrieve_response_message($response); - - if (200 != $response_code && ! empty($response_message)) { - echo ''; - echo 'No Results'; - echo ''; - } else { - if ($nextPageToRetrieve == $pagetotal) { - echo ''; - echo 'No More Results'; - echo ''; - } elseif ($pagetotal <= 1) { - echo ''; - } else { - echo ''; - } - } - - die(); -} -add_action('wp_ajax_load_page_total', 'load_page_total'); -add_action('wp_ajax_nopriv_load_page_total', 'load_page_total'); diff --git a/wp-content/themes/clarity/page_campaign_landing.php b/wp-content/themes/clarity/page_campaign_landing.php index 7eeb491e4..2128df78b 100644 --- a/wp-content/themes/clarity/page_campaign_landing.php +++ b/wp-content/themes/clarity/page_campaign_landing.php @@ -1,5 +1,6 @@ getCurrentAgency(); + + $agency_term_id = $activeAgency['wp_tag_id']; + $filter_options = ['campaign_filter' => $campaign_id]; + + $EventsHelper = new EventsHelper(); + $events = $EventsHelper->get_events($agency_term_id, $filter_options); + + if ( $events ) { + echo '

Events

'; + include locate_template( 'src/components/c-events-list/view.php' ); + } ?> diff --git a/wp-content/themes/clarity/page_events.php b/wp-content/themes/clarity/page_events.php index 04b3907cd..a82961893 100644 --- a/wp-content/themes/clarity/page_events.php +++ b/wp-content/themes/clarity/page_events.php @@ -1,13 +1,9 @@ get_event_list( 'search' ); - get_header(); ?>
@@ -19,10 +15,18 @@
getCurrentAgency(); + + $agency_term_id = $activeAgency['wp_tag_id']; + + $EventsHelper = new EventsHelper(); + $events = $EventsHelper->get_events($agency_term_id); + + if ( $events ) : echo '

Upcoming events

'; echo '
'; - get_template_part( 'src/components/c-events-list/view' ); + include locate_template( 'src/components/c-events-list/view.php' ); echo '
'; else : echo 'No events are currently listed :('; diff --git a/wp-content/themes/clarity/page_regional_archive_events.php b/wp-content/themes/clarity/page_regional_archive_events.php index 8033985e6..f0316d1b8 100644 --- a/wp-content/themes/clarity/page_regional_archive_events.php +++ b/wp-content/themes/clarity/page_regional_archive_events.php @@ -1,4 +1,6 @@
-
+
'; - get_events_api( 'region', $region_id ); - echo '
'; + $oAgency = new Agency(); + $activeAgency = $oAgency->getCurrentAgency(); + + $agency_term_id = $activeAgency['wp_tag_id']; + $filter_options = ['region_filter' => $region_id]; + + $EventsHelper = new EventsHelper(); + $events = $EventsHelper->get_events($agency_term_id, $filter_options); + if ( $events ) { + echo '

Events

'; + echo '
'; + include locate_template( 'src/components/c-events-list/view.php' ); + echo '
'; + } + else { + echo 'No events are currently listed :('; + } + ?> -
+
diff --git a/wp-content/themes/clarity/page_regional_landing.php b/wp-content/themes/clarity/page_regional_landing.php index a85efebee..c07b08841 100644 --- a/wp-content/themes/clarity/page_regional_landing.php +++ b/wp-content/themes/clarity/page_regional_landing.php @@ -1,4 +1,6 @@ '; echo '
'; - get_events_api( 'region_landing', $region_id ); + + $oAgency = new Agency(); + $activeAgency = $oAgency->getCurrentAgency(); + + $agency_term_id = $activeAgency['wp_tag_id']; + $filter_options = ['region_filter' => $region_id]; + + $EventsHelper = new EventsHelper(); + $events = $EventsHelper->get_events($agency_term_id, $filter_options); + if ( $events ) { + echo '

Events

'; + include locate_template( 'src/components/c-events-list/view.php' ); + } echo '
'; ?>
diff --git a/wp-content/themes/clarity/src/components/c-calendar-icon/style.styl b/wp-content/themes/clarity/src/components/c-calendar-icon/style.styl index 932bdb1ed..e13ceaf28 100644 --- a/wp-content/themes/clarity/src/components/c-calendar-icon/style.styl +++ b/wp-content/themes/clarity/src/components/c-calendar-icon/style.styl @@ -74,6 +74,10 @@ column(1/3); } + .page-template-page_campaign_landing & { + column(1/3); + } + .regional_page-template & { column(1/3); } diff --git a/wp-content/themes/clarity/src/components/c-event-listing/view.php b/wp-content/themes/clarity/src/components/c-event-listing/view.php index 4d4275eb8..131808bf5 100644 --- a/wp-content/themes/clarity/src/components/c-event-listing/view.php +++ b/wp-content/themes/clarity/src/components/c-event-listing/view.php @@ -1,6 +1,4 @@ get_event_list( 'search' ); - -if ( isset( $event ) ) : +if ( isset( $events ) ) : // Limit events listed on page to one for homepage display if ( is_front_page() ) { - $event = array_splice( $event, 0, 1 ); + $events = array_splice( $events, 0, 1 ); } - foreach ( $event as $key => $post ) : - $event_id = $post['ID']; - $post_url = $post['url']; - $event_title = $post['post_title']; - $start_time = $post['event_start_time']; - $end_time = $post['event_end_time']; - $start_date = $post['event_start_date']; - $end_date = $post['event_end_date']; - $location = $post['event_location']; - $date = $post['event_start_date']; - $year = date( 'Y', strtotime( $start_date ) ); - $month = date( 'M', strtotime( $start_date ) ); - $day = date( 'l', strtotime( $start_date ) ); - $all_day = get_post_meta( $event_id, '_event-allday', true ); - - if ( $all_day === true ) { - $all_day = 'all_day'; - } + foreach ( $events as $key => $post ) : + $event_id = $post->ID; + $post_url = $post->url; + $event_title = $post->post_title; + $start_time = $post->event_start_time; + $end_time = $post->event_end_time; + $start_date = $post->event_start_date; + $end_date = $post->event_end_date; + $location = $post->event_location; + $date = $post->event_start_date; + $year = date( 'Y', strtotime( $start_date ) ); + $month = date( 'M', strtotime( $start_date ) ); + $day = date( 'l', strtotime( $start_date ) ); + $all_day = $post->event_allday; + + if ( $all_day === true ) { + $all_day = 'all_day'; + } ?> diff --git a/wp-content/themes/clarity/src/components/c-events-item-byline/view.php b/wp-content/themes/clarity/src/components/c-events-item-byline/view.php index bc06d38cd..188e3aed3 100644 --- a/wp-content/themes/clarity/src/components/c-events-item-byline/view.php +++ b/wp-content/themes/clarity/src/components/c-events-item-byline/view.php @@ -1,6 +1,4 @@