From 8b294d27e6d7d68e03ce96611d825a1bd42a6920 Mon Sep 17 00:00:00 2001 From: Anthony Talarico Date: Tue, 23 May 2017 16:14:56 -0400 Subject: [PATCH] filtering events by member id if specified in event list shortcode if event list shortcode has a member id to get events based on members, adjusting queries to only get the events by that id, also fixing the dropdown to only have the dates from events associated with that member id as well --- models/admin/ajax/eventsCalMonthAJAX.php | 21 +++++++++------ models/front/events/list.php | 34 ++++++++++++++++++------ views/front/events/agenda.html | 10 +++++-- 3 files changed, 47 insertions(+), 18 deletions(-) diff --git a/models/admin/ajax/eventsCalMonthAJAX.php b/models/admin/ajax/eventsCalMonthAJAX.php index dc24261..01e6d09 100644 --- a/models/admin/ajax/eventsCalMonthAJAX.php +++ b/models/admin/ajax/eventsCalMonthAJAX.php @@ -81,19 +81,27 @@ class GlmMembersAdmin_ajax_eventsCalMonthAJAX extends GlmDataEventsTimes * from within a given date range. Left out of the where statement because it is * already performed by $this->dateRange */ - public function getModelTimesData( ) + public function getModelTimesData($member_id = false ) { $this->postAddTimes = true; $where = ''; - + + if($member_id !== false && $member_id !== ''){ + $ref_dest = "= $member_id"; + } else { + $ref_dest = 'IS NOT NULL'; + } + $where .= "T.active = 1 AND T.event IN ( SELECT ET.id FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "events AS ET WHERE ET.status = " . $this->config['status_numb']['Active'] . " + AND ref_dest $ref_dest ) AND $this->dateRangeTimes "; + if ( isset( $_REQUEST['category'] ) && $catId = filter_var( $_REQUEST['category'], FILTER_VALIDATE_INT ) ) { $where .= " AND T.event IN ( @@ -130,7 +138,6 @@ class GlmMembersAdmin_ajax_eventsCalMonthAJAX extends GlmDataEventsTimes { global $wpdb; - $event_data = []; $image_url = false; $datesArray = array(); @@ -217,7 +224,6 @@ class GlmMembersAdmin_ajax_eventsCalMonthAJAX extends GlmDataEventsTimes // end section for front page events widget data } else if( isset($_REQUEST['month']) ){ - $month = filter_var_array( $_REQUEST['month'], array( @@ -238,8 +244,8 @@ class GlmMembersAdmin_ajax_eventsCalMonthAJAX extends GlmDataEventsTimes WHERE DATE(start_time) BETWEEN '{$from}' AND '{$to}' )"; - - $times = $this->getModelTimesData(); + $member_id = (isset($_REQUEST['member_id']) ? filter_var($_REQUEST['member_id'], FILTER_SANITIZE_STRING) : ''); + $times = $this->getModelTimesData($member_id); if ( is_array( $times ) ) { foreach ($times as $e=>$val){ $sql = "SELECT * FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "events WHERE id = " . $val['event']; @@ -266,8 +272,7 @@ class GlmMembersAdmin_ajax_eventsCalMonthAJAX extends GlmDataEventsTimes // 'status' => false, // Assume nothing works 'events' => $event_data , // Where our events list will go 'message' => $image_url, - 'array_dates' => $datesArray, -// 'event' => $dates + 'array_dates' => $datesArray ); header('Content-type:application/json;charset=utf-8', true); diff --git a/models/front/events/list.php b/models/front/events/list.php index 2d3f68c..eece508 100644 --- a/models/front/events/list.php +++ b/models/front/events/list.php @@ -765,17 +765,35 @@ class GlmMembersFront_events_list extends GlmMembersFront_events_baseAction $years = array('current' => $current_year = date("Y"), 'next' => date('Y') +1 ); $months = []; $count = 0; + foreach($years as $key=>$year){ - - if($current_year == $year){ - $sql = 'SELECT MONTH(start_time) as month FROM '. GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX .'times '; - $sql .= "WHERE YEAR(start_time) = $year AND MONTH(start_time) >= MONTH(CURDATE()) GROUP BY month"; - $results[$year] = $wpdb->get_results($sql, ARRAY_A); + // if member id we need to limit the dates for month dropdown by member id + if($memberId){ + if($current_year == $year){ + $sql = 'SELECT MONTH(start_time) as month FROM '. GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX .'times '; + $sql .= "WHERE event IN (select id from ".GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX ."events WHERE ref_dest = $memberId )"; + $sql .= " AND YEAR(start_time) = $year AND MONTH(start_time) >= MONTH(CURDATE()) GROUP BY month"; + $results[$year] = $wpdb->get_results($sql, ARRAY_A); + } else { + $sql = 'SELECT MONTH(start_time) as month FROM '. GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX .'times '; + $sql .= "WHERE event IN (select id from ".GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX ."events WHERE ref_dest = $memberId )"; + $sql .= " AND YEAR(start_time) = $year GROUP BY month"; + $results[$year] = $wpdb->get_results($sql, ARRAY_A); + } + // otherwise we can just pull all of the dates for the events as usual } else { - $sql = 'SELECT MONTH(start_time) as month FROM '. GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX .'times '; - $sql .= "WHERE YEAR(start_time) = $year GROUP BY month"; - $results[$year] = $wpdb->get_results($sql, ARRAY_A); + + if($current_year == $year){ + $sql = 'SELECT MONTH(start_time) as month FROM '. GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX .'times '; + $sql .= "WHERE YEAR(start_time) = $year AND MONTH(start_time) >= MONTH(CURDATE()) GROUP BY month"; + $results[$year] = $wpdb->get_results($sql, ARRAY_A); + } else { + $sql = 'SELECT MONTH(start_time) as month FROM '. GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX .'times '; + $sql .= "WHERE YEAR(start_time) = $year GROUP BY month"; + $results[$year] = $wpdb->get_results($sql, ARRAY_A); + } } + } foreach($results as $year => $month){ foreach($month as $key=>$value){ diff --git a/views/front/events/agenda.html b/views/front/events/agenda.html index afc1825..42badfd 100644 --- a/views/front/events/agenda.html +++ b/views/front/events/agenda.html @@ -2,6 +2,7 @@
{include file='front/events/searchForm.html'}
+
{foreach $eventsByDate as $date => $key} @@ -136,6 +137,7 @@ var calendar = $("#eventCalendar"); var event_search = $(".glm-search-icon"); var main_content = $("#main-content"); + var member_id = '{$memberId}'; var view = '{$cal_view}'; var months = '{$json_months}'; var category = $('#glm-event-category').val(); @@ -143,6 +145,10 @@ var current_year = $('{$current_year}'); var retain_date; + if(!member_id){ + member_id = null; + } + // add 7 days to ensure we always get the current month and not any other month view that may // be visible (last few days of previous month or first few days of next month) function get_current_view(){ @@ -186,7 +192,8 @@ action: 'glm_members_admin_ajax', glm_action: 'eventsCalMonthAJAX', month: month, - category: category + category: category, + member_id: member_id }; $('.fc-event').remove(); @@ -206,7 +213,6 @@ cache: false, success: function (response){ var buildingEvents = []; -// console.log(response.message); //var events_obj = jQuery.parseJSON(response); var events_obj = response; var events = events_obj.events; -- 2.17.1