From 5f88362e86e7a624ac93675bbbf8617c4786910c Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Fri, 19 Aug 2016 16:06:49 -0400 Subject: [PATCH] Update for event categories Need to bring in the event categories too. --- models/front/events/icalFeedImport.php | 45 +++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/models/front/events/icalFeedImport.php b/models/front/events/icalFeedImport.php index 31a6173..3fa8f81 100644 --- a/models/front/events/icalFeedImport.php +++ b/models/front/events/icalFeedImport.php @@ -39,6 +39,34 @@ class GlmMembersFront_events_icalFeedImport } exit; } + public function getCategoryId( $category ) + { + $category_id = $this->wpdb->get_var( + $this->wpdb->prepare( + "SELECT id + FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "categories + WHERE name = %d", + $category + ) + ); + if ( $category_id ) { + return $category_id; + } else { + $this->wpdb->insert( + GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . 'categories', + array( + 'name' => $category, + 'parent' => 0 + ), + array( + '%s', + '%d' + ) + ); + $category_id = $this->wpdb->insert_id; + return $category_id; + } + } public function clearData() { $this->wpdb->query( "DELETE FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "events" ); @@ -131,7 +159,7 @@ class GlmMembersFront_events_icalFeedImport $old_image = $this->wpdb->get_var( $this->wpdb->prepare( "SELECT image - FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . " + FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "events WHERE id = %d", $event_id ) @@ -202,6 +230,21 @@ class GlmMembersFront_events_icalFeedImport // generate the slug name for this new event $event_abstract = new GlmDataEvents( $this->wpdb, $this->config ); $event_abstract->updateSlug( $event_id ); + + // Categories + if ( isset( $event['CATEGORIES'] ) ) { + $category_data = explode( ',', $event['CATEGORIES'] ); + foreach ( $category_data as $category ) { + $this->wpdb->insert( + GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . 'event_categories', + array( + 'event' => $event_id, + 'category' => $this->getCategoryId( $category ) + ), + '%d' + ); + } + } // Location Data if ( isset( $event['LOCATION'] ) ) { $location_data = explode( ',', str_replace( '\\', '', $event['LOCATION'] ) ); -- 2.17.1