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
$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 .= '<pre>$events: ' . print_r($events, true) . '</pre>';
echo '<pre>SQL Error: ' . $this->wpdb->last_error . '</pre>';
}
}
+ // checking for $eventId
echo '<pre>$eventId: ' . print_r($eventId, true) . '</pre>';
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',
)
);
}
+ // recurrences for the event
$allDates = !$event['reacur'];
if ( !$allDates && ( $event['bdate'] == $event['edate'] ) ) {
$allDates = 1;
);
$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 '<pre>$locationData: ' . print_r($locationData, true) . '</pre>';
+ die('no return id for location');
+ }
+ }
}
} catch(PDOException $e) {
echo '<pre>$e: ' . print_r($e, true) . '</pre>';