From: Steve Sutton Date: Wed, 16 Mar 2016 19:05:23 +0000 (-0400) Subject: importing events X-Git-Tag: v1.0.0^2~162^2~23 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=ca44a31c1f28d7108b59ae6b87eaa6502b0da18a;p=WP-Plugins%2Fglm-member-db-events.git importing events now it imports the times,categories, location, recurrences, event_times still doing some testing to see if everything is working correctly. --- diff --git a/models/admin/management/events.php b/models/admin/management/events.php index 55eea7e..7198e38 100644 --- a/models/admin/management/events.php +++ b/models/admin/management/events.php @@ -454,6 +454,26 @@ class GlmMembersAdmin_management_events extends GlmDataEventsManagement return $dateTime->format('H:i'); } + public function getCityId($cityName) + { + $sql = " + SELECT id + FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "cities + WHERE name like '" . esc_sql( trim( $cityName ) ) . "'"; + $cityId = $this->wpdb->get_row($sql, ARRAY_A); + if ( !$cityId ) { + // then add the city to the city table + $this->wpdb->insert( + GLM_MEMBERS_PLUGIN_DB_PREFIX . 'cities', + array( 'name' => trim( $cityName ) ), + array( '%s' ) + ); + return $this->wpdb->insert_id; + } else { + return $cityId['id']; + } + } + public function addEvents() { // clear the events tables first @@ -461,13 +481,14 @@ class GlmMembersAdmin_management_events extends GlmDataEventsManagement $this->wpdb->query( "DELETE FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "recurrences" ); $this->wpdb->query( "DELETE FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "times" ); $this->wpdb->query( "DELETE FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "event_categories" ); + $this->wpdb->query( "DELETE FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "locations" ); $Recurrences = new GlmDataEventsRecurrences($this->wpdb, $this->config); $return = ''; $sql = " SELECT * FROM {$this->settings['schema']}.{$this->settings['tablename']} WHERE edate >= '{$this->settings['sdate']}'::DATE"; - $sql .=" AND reacur "; + //$sql .=" AND reacur "; try { $events = $this->dbh->query($sql)->fetchAll(PDO::FETCH_ASSOC); $return .= '
$events: ' . print_r($events, true) . '
'; @@ -549,10 +570,12 @@ class GlmMembersAdmin_management_events extends GlmDataEventsManagement echo '
SQL Error: ' . $this->wpdb->last_error . '
'; } } + // checking for $eventId echo '
$eventId: ' . print_r($eventId, true) . '
'; if (!$eventId) { die('something is wrong no eventId'); } + // category for event if ( $event['topicid'] ) { $this->wpdb->insert( GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . 'event_categories', @@ -566,6 +589,7 @@ class GlmMembersAdmin_management_events extends GlmDataEventsManagement ) ); } + // recurrences for the event $allDates = !$event['reacur']; if ( !$allDates && ( $event['bdate'] == $event['edate'] ) ) { $allDates = 1; @@ -648,6 +672,74 @@ class GlmMembersAdmin_management_events extends GlmDataEventsManagement ); $recurId = $this->wpdb->insert_id; $Recurrences->createRecurrenceTimesEntries( $recurId, true, true ); + // location for the event + $hasLocation = ( + ($event['loc']) + || ($event['contact']) + || ($event['phone']) + || ($event['url']) + || ($event['email']) + ); + if ( $hasLocation ) { + $locationData = $locationFormat = array(); + $locationData['event'] = $eventId; + $locationFormat[] = '%d'; + if ($event['loc']) { + $locationData['name'] = $event['loc']; + $locationFormat[] = '%s'; + } + if ($event['address']) { + $locationData['address'] = $event['address']; + $locationFormat[] = '%s'; + } + if ($event['city']) { + $locationData['city'] = $this->getCityId( $event['city'] ); + $locationFormat[] = '%s'; + } + if ($event['state']) { + $locationData['state'] = $event['state']; + $locationFormat[] = '%s'; + } + if ($event['lat']) { + $locationData['lat'] = $event['lat']; + $locationFormat[] = '%s'; + } + if ($event['lon']) { + $locationData['lon'] = $event['lon']; + $locationFormat[] = '%s'; + } + if ($event['contact']) { + // break up the contact name db is expecting first and + // last name separately + list( $firstName, $lastName ) = explode( ' ', $event['contact'], 2 ); + $locationData['contact_fname'] = $firstName; + $locationFormat[] = '%s'; + $locationData['contact_lname'] = $lastName; + $locationFormat[] = '%s'; + } + if ($event['phone']) { + $locationData['contact_phone'] = $event['phone']; + $locationFormat[] = '%s'; + } + if ($event['url']) { + $locationData['url'] = $event['url']; + $locationFormat[] = '%s'; + } + if ($event['email']) { + $locationData['contact_email'] = $event['email']; + $locationFormat[] = '%s'; + } + $this->wpdb->insert( + GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . 'locations', + $locationData, + $locationFormat + ); + $locationId = $this->wpdb->insert_id; + if ( !$locationId ) { + echo '
$locationData: ' . print_r($locationData, true) . '
'; + die('no return id for location'); + } + } } } catch(PDOException $e) { echo '
$e: ' . print_r($e, true) . '
';