*
* Return the array of events.
*
- * @param integer $categoryId Id of the category for filtering events (optional)
- * @param integer $limit Number of events to return (optional)
- * @param integer $memberId Member ID if filtering by member
- * @param integer $amenityId Amenity id for filter
- * @param integer $venueId Venue id for filter
+ * Defaults.
+ * $defaults = [
+ * 'categories' => null,
+ * 'event_name' => null,
+ * 'member_id' => null,
+ * 'amenity_id' => null,
+ * 'venue_id' => null,
+ * 'city_id' => null,
+ * 'limit' => null,
+ * ];
+ *
+ * Config parameters. Overrides Defaults.
+ * $config = [
+ * 'categories' => $categories,
+ * 'event_name' => $event_name,
+ * 'member_id' => $member_id,
+ * 'amenity_id' => $amenity_id,
+ * 'venue_id' => $venue_id,
+ * 'city_id' => $city_id,
+ * 'limit' => $limit,
+ * ];
+ *
+ * @param integer $event_config Config Parameters
*
* @access public
* @return array events
*/
- public function getModelEventsData( $categoryId = null, $limit = null, $memberId = null, $amenityId = null, $venueId = null, $cityId = null, $isNameSearch = false )
+ //public function getModelEventsData( $categoryId = null, $limit = null, $memberId = null, $amenityId = null, $venueId = null, $cityId = null, $isNameSearch = false )
+ public function getModelEventsData( $event_config )
{
+ // Initialize $is_name_search to false.
+ $is_name_search = false;
+
+ // Setup of defaults.
+ $defaults = [
+ 'categories' => null,
+ 'event_name' => null,
+ 'member_id' => null,
+ 'amenity_id' => null,
+ 'venue_id' => null,
+ 'city_id' => null,
+ 'limit' => null,
+ ];
+
+ // Merge the default and event_config arrays.
+ $params = array_merge( $defaults, $event_config );
+
+ // Pull all parameter values.
+ $categories = $params['categories'];
+ $event_name = $params['event_name'];
+ $member_id = $params['member_id'];
+ $amenity_id = $params['amenity_id'];
+ $venue_id = $params['venue_id'];
+ $city_id = $params['city_id'];
+ $limit = $params['limit'];
- // echo '<pre>$cityId: ' . print_r( $cityId, true ) . '</pre>';
$this->postAddTimes = true;
$whereParts = array();
$where = $order = '';
- if ($memberId = filter_var( $memberId, FILTER_VALIDATE_INT )) {
- $whereParts[] = "T.ref_type = ".$this->config['ref_type_numb']['Member']." and T.ref_dest = $memberId ";
+ if ( $event_name ) {
+ $is_name_search = true;
+ }
+
+ if ( $member_id = filter_var( $member_id, FILTER_VALIDATE_INT )) {
+ $whereParts[] = "T.ref_type = ".$this->config['ref_type_numb']['Member']." and T.ref_dest = $member_id ";
}
- if ( $amenityId = filter_var( $amenityId, FILTER_VALIDATE_INT ) ) {
+ if ( $amenity_id = filter_var( $amenity_id, FILTER_VALIDATE_INT ) ) {
$whereParts[] = "
T.id IN (
SELECT event
FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "amenity_event
- WHERE amenity = {$amenityId}
+ WHERE amenity = {$amenity_id}
AND event IN (
SELECT event
FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "times AS ET
}
// check for city id in event list search
- if ( ( $cityId = filter_var( $cityId, FILTER_VALIDATE_INT ) ) && !$isNameSearch ) {
- // echo '<pre>$cityId: ' . print_r( $cityId, true ) . '</pre>';
+ if ( ( $city_id = filter_var( $city_id, FILTER_VALIDATE_INT ) ) && !$is_name_search ) {
+ // echo '<pre>$city_id: ' . print_r( $city_id, true ) . '</pre>';
$whereParts[] = "(
(T.use_member_location <> true
AND
T.id IN (
SELECT event
FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "locations
- WHERE city = {$cityId}
+ WHERE city = {$city_id}
))
OR (
T.use_member_location = true
SELECT member
FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "member_info
WHERE status = 10
- AND city = {$cityId}
+ AND city = {$city_id}
)
)
)";
}
- if ( $venueId = filter_var( $venueId, FILTER_VALIDATE_INT ) ) {
+ if ( $venue_id = filter_var( $venue_id, FILTER_VALIDATE_INT ) ) {
$whereParts[] = "
- T.other_ref_dest = {$venueId}
+ T.other_ref_dest = {$venue_id}
AND T.id IN (
SELECT event
FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "times AS ET
";
}
- // Get cats if categoryId is an array
- $cats = array_filter( filter_var( $categoryId, FILTER_VALIDATE_INT, array( 'flags' => FILTER_FORCE_ARRAY ) ) );
- $catId = filter_var( $categoryId, FILTER_VALIDATE_INT );
+ // Get cats if categories is an array
+ $cats = array_filter( filter_var( $categories, FILTER_VALIDATE_INT, array( 'flags' => FILTER_FORCE_ARRAY ) ) );
+ $catId = filter_var( $categories, FILTER_VALIDATE_INT );
// If a category ID is supplied
- if ( $catId && !$isNameSearch ) {
+ if ( $catId && !$is_name_search ) {
//$events = $this->getEventsByCategory( $catId, $limit );
$whereParts[] = "
T.id IN (
if ( $limit = filter_var( $limit, FILTER_VALIDATE_INT ) ) {
$order .= " LIMIT {$limit} OFFSET 0";
}
- } else if ( $this->notInCat && !empty( $this->notInCat ) && !$isNameSearch ) {
+ } else if ( $this->notInCat && !empty( $this->notInCat ) && !$is_name_search ) {
$whereParts[] = "
T.id NOT IN (
SELECT event
$order .= " LIMIT {$limit} OFFSET 0";
}
- // Else if the $categoryId is an array
- } else if ( $cats && !empty( $cats ) && !$isNameSearch ) {
+ // Else if the $categories is an array
+ } else if ( $cats && !empty( $cats ) && !$is_name_search ) {
$whereParts[] = "
T.id IN (
SELECT event
FROM " .GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "event_categories
- WHERE category IN (" . implode( ',', $categoryId ) . ")
+ WHERE category IN (" . implode( ',', $categories ) . ")
AND event IN (
SELECT event
FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "times AS ET
$order .= " LIMIT {$limit} OFFSET 0";
}
// Else if a event name is supplied
- } else if ( $term = filter_var( $categoryId, FILTER_SANITIZE_STRING, FILTER_FLAG_NO_ENCODE_QUOTES ) ) {
+ } else if ( $term = filter_var( $event_name, FILTER_SANITIZE_STRING, FILTER_FLAG_NO_ENCODE_QUOTES ) ) {
$searchTerm = $this->wpdb->esc_like( stripslashes( $term ) );
$whereParts[] .= "T.name like '%" . $term . "%'
AND T.status = " . $this->config['status_numb']['Active'] . "
wp_enqueue_script('event-dashboard-js');
wp_enqueue_style('jquery-style', '//ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/themes/smoothness/jquery-ui.css');
- // echo '<pre>$action: ' . print_r( $action, true ) . '</pre>';
+ $event_config = [
+ 'categories' => $categoryId,
+ 'event_name' => $eventNameSearch,
+ 'member_id' => $memberId,
+ 'amenity_id' => $amenityId,
+ 'venue_id' => $venueId,
+ 'city_id' => $cityId,
+ 'limit' => $limit,
+ ];
+
switch ( $action ) {
case 'front-page':
$this->postAddRecurrences = true;
- $events = $this->getModelEventsData( $categoryId, $limit, $memberId, $amenityId, $venueId );
+ $events = $this->getModelEventsData( $event_config );
$this->postAddRecurrences = false;
break;
case 'event-list-name':
$this->postAddRecurrences = true;
- $events = $this->getModelEventsData( $eventNameSearch, null, $memberId, $amenityId, $venueId, null, true );
+ $events = $this->getModelEventsData( $event_config );
$this->postAddRecurrences = false;
if ( !$view ) {
$view = 'agenda.html';
case 'event-list':
$this->postAddLocations = true;
$this->postAddRecurrences = true;
- $events = $this->getModelEventsData( $categoryId, null, $memberId, $amenityId, $venueId, $cityId );
+ $events = $this->getModelEventsData( $event_config );
if ( !$view ) {
$view = 'agenda.html';
}
include_once GLM_MEMBERS_EVENTS_PLUGIN_PATH . '/SetaPDF/Autoload.php';
$this->postAddLocations = true;
$this->postAddRecurrences = true;
- $events = $this->getModelEventsData( $categoryId, null, $memberId, $amenityId, $venueId );
+ $events = $this->getModelEventsData( $event_config );
$this->postAddLocations = false;
$this->postAddRecurrences = false;
if ( !$view ) {
$view = 'agenda.html';
}
- $events = $this->getModelEventsData( $categoryId, null, $memberId, $amenityId, $venueId, $cityId );
+ $events = $this->getModelEventsData( $event_config );
$this->postAddRecurrences = false;
$this->postAddLocations = false;
break;