*
* @category glmWordPressPlugin
* @package glmMembersDatabase
- * @author Chuck Scott <cscott@gaslightmedia.com>
+ * @author Chuck Scott <cscott@gaslightmedia.com>
* @license http://www.gaslightmedia.com Gaslightmedia
* @release events.php,v 1.0 2014/10/31 19:31:47 cscott Exp $
* @link http://dev.gaslightmedia.com/
*
* @category Model
* @package GLM Member DB
- * @author Chuck Scott <cscott@gaslightmedia.com>
+ * @author Chuck Scott <cscott@gaslightmedia.com>
* @license http://www.gaslightmedia.com Gaslightmedia
- * @release SVN: $Id: packaging.php,v 1.0 2011/01/25 19:31:47 cscott
- * Exp $
+ * @release SVN: $Id: packaging.php,v 1.0 2011/01/25 19:31:47 cscott
+ * Exp $
*/
class GlmMembersAdmin_management_events extends GlmDataEventsManagement
{
public function modelAction($actionData = false)
{
- $option = false;
- $testResult = false;
- $importResult = false;
- $settingsUpdated = false;
- $settingsUpdateError = false;
- $eventsSettings = false;
+ $option = false;
+ $test_result = false;
+ $import_result = false;
+ $settings_updated = false;
+ $settings_update_error = false;
+ $event_settings = false;
if (isset($_REQUEST['option'])) {
$option = $_REQUEST['option'];
}
-
+
switch ($option) {
+ case 'timelyImport':
+ $import = false;
+ if (isset($_REQUEST['import'])) {
+ $import = filter_var( $_REQUEST['import'], FILTER_VALIDATE_BOOLEAN );
+ }
+ $import_result = $this->importFromTimely();
+ break;
case 'tests':
case 'recurrence':
- $testResult = $this->testRecurrence();
+ $test_result = $this->testRecurrence();
break;
if ( $this->image_owner ) {
$this->importEventImages();
$this->importEventFiles();
- $importResult = '<p>All images and files imported</p>';
+ $import_result = '<p>All images and files imported</p>';
} else {
- $importResult = '<pre>Failure: Not given owner id.</pre>';
+ $import_result = '<pre>Failure: Not given owner id.</pre>';
}
}
switch ($import) {
case 'true':
- $importResult = '<pre>$_REQUEST: ' . print_r( $_REQUEST, true ) . '</pre>';
+ $import_result = '<pre>$_REQUEST: ' . print_r( $_REQUEST, true ) . '</pre>';
$db_host = filter_var( $_REQUEST['db_host'], FILTER_SANITIZE_STRING );
$db_name = filter_var( $_REQUEST['db_name'], FILTER_SANITIZE_STRING );
$db_user = filter_var( $_REQUEST['db_user'], FILTER_SANITIZE_STRING );
'schema' => FILTER_SANITIZE_STRING,
'cattablename' => FILTER_SANITIZE_STRING,
'tablename' => FILTER_SANITIZE_STRING,
- 'sdate' => array(
+ 'sdate' => array(
'filter' => FILTER_VALIDATE_REGEXP,
'options' => array(
'regexp' => '%[0-9]{2}/[0-9]{2}/[0-9]{4}%'
)
);
- $importResult .= '<pre>$this->settings: ' . print_r($this->settings, true) . '</pre>';
+ $import_result .= '<pre>$this->settings: ' . print_r($this->settings, true) . '</pre>';
$this->addCategories();
- $importResult .= $this->addEvents();
+ $import_result .= $this->addEvents();
- $importResult .= '<pre>$this->categories: ' . print_r($this->categories, true) . '</pre>';
+ $import_result .= '<pre>$this->categories: ' . print_r($this->categories, true) . '</pre>';
break;
'status' => false,
'menuItemRedirect' => 'error',
'modelRedirect' => 'index',
- 'view' => 'admin/error/index.html',
- 'data' => array(
+ 'view' => 'admin/error/index.html',
+ 'data' => array(
'reason' => 'User does not have rights to make configuration changes.'
)
);
case 'submit':
// Update the event management settings
- $eventsSettings = $this->updateEntry(1);
- if ($eventsSettings['status']) {
- $settingsUpdated = true;
+ $event_settings = $this->updateEntry(1);
+ if ($event_settings['status']) {
+ $settings_updated = true;
} else {
- $settingsUpdateError = true;
+ $settings_update_error = true;
}
+
break;
// Default is to get the current settings and display the form
default:
// Try to get the first (should be only) entry for general settings.
- $eventsSettings = $this->editEntry(1);
+ $event_settings = $this->editEntry(1);
- if ($eventsSettings === false) {
+ if ($event_settings === false) {
if (GLM_MEMBERS_PLUGIN_ADMIN_DEBUG) {
glmMembersAdmin::addNotice("<b> /models/admin/management/events.php: Unable to load events management settings.", 'Alert');
}
// Compile template data
- $templateData = array(
+ $template_data = array(
'option' => $option,
- 'testResult' => $testResult,
- 'importResult' => $importResult,
- 'settingsUpdated' => $settingsUpdated,
- 'settingsUpdateError' => $settingsUpdateError,
- 'eventsSettings' => $eventsSettings
+ 'testResult' => $test_result,
+ 'importResult' => $import_result,
+ 'settingsUpdated' => $settings_updated,
+ 'settingsUpdateError' => $settings_update_error,
+ 'eventsSettings' => $event_settings
);
// Return status, suggested view, and data to controller
'status' => true,
'menuItemRedirect' => false,
'modelRedirect' => false,
- 'view' => 'admin/management/events.html',
- 'data' => $templateData
+ 'view' => 'admin/management/events.html',
+ 'data' => $template_data
);
*/
public function connectPostgresDb($db_host, $db_name, $db_user, $db_password)
{
- $connStr = "pgsql:";
+ $conn_str = "pgsql:";
if ( $db_host ) {
- $connPart[] = "host={$db_host}";
+ $conn_part[] = "host={$db_host}";
}
if ( $db_name ) {
- $connPart[] = "dbname={$db_name}";
+ $conn_part[] = "dbname={$db_name}";
}
if ( $db_user ) {
- $connPart[] = "user={$db_user}";
+ $conn_part[] = "user={$db_user}";
}
if ( $db_password ) {
- $connPart[] = "password={$db_password}";
+ $conn_part[] = "password={$db_password}";
}
- if ( !empty($connPart) ) {
- $connStr .= implode( " ", $connPart );
+ if ( !empty($conn_part) ) {
+ $conn_str .= implode( " ", $conn_part );
}
- $driverOptions = array(
+ $driver_options = array(
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_BOTH,
);
try {
- $this->dbh = new PDO($connStr, null, null, $driverOptions);
+ $this->dbh = new PDO($conn_str, null, null, $driver_options);
$this->dbh->setAttribute(
PDO::ATTR_ERRMODE,
PDO::ERRMODE_EXCEPTION
$this->wpdb->insert(
GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . 'categories',
array(
- 'name' => trim($category['name']),
+ 'name' => trim($category['name']),
'parent' => 0
),
array(
return $return;
}
+ public function addTimelyCategories() {
+ $categories = get_terms( 'events_categories' );
+ foreach ( $categories as $category ) {
+ // first check to see if the category is already there
+ $sql = "
+ SELECT id
+ FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "categories
+ WHERE name = '" . esc_sql( trim($category->name) ) . "'";
+ $found = $this->wpdb->get_row($sql, ARRAY_A);
+ if ( !isset($found) ) {
+ $this->wpdb->insert(
+ GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . 'categories',
+ array(
+ 'name' => trim($category->name),
+ 'parent' => $category->parent
+ ),
+ array(
+ '%s',
+ '%d'
+ )
+ );
+ $catid = $this->wpdb->insert_id;
+ $this->categories[$catid] = trim($category->name);
+ $this->oldCatMap[$category->term_id] = $catid;
+ } else {
+ $this->categories[$found['id']] = trim($category->name);
+ $this->oldCatMap[$category->term_id] = $found['id'];
+ }
+ }
+ }
/**
* getTime
*
*/
public function getTime($time)
{
- echo '<pre>$time: ' . print_r($time, true) . '</pre>';
+ echo '<pre>$time: ' . print_r($time, true) . '</pre>';
if (!$time) {
return false;
}
- if (!preg_match('%(\d{1,2}):?(\d{2})? ?(\w{1,2})?%', $time, $timeParts)) {
+ if (!preg_match('%(\d{1,2}):?(\d{2})? ?(\w{1,2})?%', $time, $time_parts)) {
//die('not found');
return false;
}
- echo '<pre>$timeParts: ' . print_r($timeParts, true) . '</pre>';
+ echo '<pre>$timeParts: ' . print_r($time_parts, true) . '</pre>';
//$hour = (!$timeParts[3] || in_array(strtolower(trim($timeParts[3])), array('pm', 'p')))
- // ? ( ((int)$timeParts[1] === 12) ? 12 : (int)$timeParts[1] += 12 )
- // : ( ((int)$timeParts[1] === 12) ? 0 : (int)$timeParts[1] );
- $hour = $timeParts[1];
+ // ? ( ((int)$timeParts[1] === 12) ? 12 : (int)$timeParts[1] += 12 )
+ // : ( ((int)$timeParts[1] === 12) ? 0 : (int)$timeParts[1] );
+ $hour = $time_parts[1];
// parse the hour from event
$dateTime = new DateTime();
- $dateTime->setTime($hour, (int)$timeParts[2] );
- echo '<pre>$dateTime: ' . print_r($dateTime, true) . '</pre>';
+ $dateTime->setTime($hour, (int)$time_parts[2] );
+ echo '<pre>$dateTime: ' . print_r($dateTime, true) . '</pre>';
return $dateTime->format('H:i');
}
* Given a city name find and return the id of the city.
* If a city cannot be found then create city with that name.
*
- * @param mixed $cityName Name of the city
+ * @param mixed $city_name Name of the city
*
* @access public
* @return id of city
*/
- public function getCityId($cityName)
+ public function getCityId($city_name)
{
$sql = "
SELECT id
FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "cities
- WHERE name like '" . esc_sql( trim( $cityName ) ) . "'";
+ WHERE name like '" . esc_sql( trim( $city_name ) ) . "'";
$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( 'name' => trim( $city_name ) ),
array( '%s' )
);
return $this->wpdb->insert_id;
$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 = '';
- $oldEventFormat = ($this->settings['tablename'] == 'event');
- if ( $oldEventFormat ) {
+ $return = '';
+ $old_event_format = ($this->settings['tablename'] == 'event');
+ if ( $old_event_format ) {
$sql = "
SELECT *
FROM {$this->settings['schema']}.{$this->settings['tablename']}
SELECT *
FROM {$this->settings['schema']}.{$this->settings['tablename']}
WHERE ending >= '{$this->settings['sdate']}'::DATE";
- $prepareSql = "
+ $prepare_sql = "
SELECT filename,urltext
FROM {$this->settings['schema']}.files
WHERE event = :eid";
- $getFileData = $this->dbh->prepare($prepareSql);
+ $get_file_data = $this->dbh->prepare($prepare_sql);
}
//$sql .=" AND file != '' ";
- //$sql .= " AND id = 5";
+ //$sql .= " AND id = 5";
$this->wpdb->show_errors();
echo '<pre>$sql: ' . print_r($sql, true) . '</pre>';
try {
$events = $this->dbh->query($sql)->fetchAll(PDO::FETCH_ASSOC);
$return .= '<pre>$events: ' . print_r($events, true) . '</pre>';
foreach ( $events as $event ) {
- $foundMemberId = $refType = null;
- $memberId = (isset($event['member_id'])) ? $event['member_id'] : $event['member'];
- if ( $memberId ) {
+ $found_member_id = $refType = null;
+ $member_id = (isset($event['member_id'])) ? $event['member_id'] : $event['member'];
+ if ( $member_id ) {
// get the new member id
$sql = "
SELECT id
FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "members
- WHERE old_member_id = " . esc_sql( trim($memberId) );
- $foundMemberId = $this->wpdb->get_row($sql, ARRAY_A);
- if ( $foundMemberId ) {
- $foundMemberId = $foundMemberId['id'];
+ WHERE old_member_id = " . esc_sql( trim($member_id) );
+ $found_member_id = $this->wpdb->get_row($sql, ARRAY_A);
+ if ( $found_member_id ) {
+ $found_member_id = $found_member_id['id'];
$refType = $this->config['ref_type_numb']['Member'];
}
}
- if ( $oldEventFormat ) {
+ if ( $old_event_format ) {
$intro = substr(strip_tags($event['descr']), 0, 250);
- $eventData = array(
+ $event_data = array(
'status' => (($event['visable'] == '1')
? $this->config['status_numb']['Active']
: $this->config['status_numb']['Inactive']),
- 'created' => $event['create_date'],
- 'updated' => $event['create_date'],
- 'approved' => $event['approved_date'],
- 'name' => $event['header'],
- 'intro' => $intro,
- 'descr' => $event['descr'],
- 'image' => $event['img'],
- 'file1' => $event['file'],
- 'file1_descr' => $event['filename'],
- 'cost' => $event['cost'],
- 'url' => $event['url'],
- 'old_event_id' => $event['id'],
- 'ref_type' => $refType,
- 'ref_dest' => $foundMemberId,
+ 'created' => $event['create_date'],
+ 'updated' => $event['create_date'],
+ 'approved' => $event['approved_date'],
+ 'name' => $event['header'],
+ 'intro' => $intro,
+ 'descr' => $event['descr'],
+ 'image' => $event['img'],
+ 'file1' => $event['file'],
+ 'file1_descr' => $event['filename'],
+ 'cost' => $event['cost'],
+ 'url' => $event['url'],
+ 'old_event_id' => $event['id'],
+ 'ref_type' => $refType,
+ 'ref_dest' => $found_member_id,
'admin_name' => $event['admin_contact_name'],
- 'admin_org' => $event['admin_org_name'],
- 'admin_email' => $event['admin_email'],
- 'admin_phone' => $event['admin_phone'],
+ 'admin_org' => $event['admin_org_name'],
+ 'admin_email' => $event['admin_email'],
+ 'admin_phone' => $event['admin_phone'],
'contact_email' => $event['email'],
- 'contact_name' => $event['contact'],
+ 'contact_name' => $event['contact'],
'contact_phone' => $event['phone'],
- 'notes' => $event['notes'],
- 'hide_address' => $event['hide_address'],
+ 'notes' => $event['notes'],
+ 'hide_address' => $event['hide_address'],
);
- $eventDataFormat = array(
+ $event_data_format = array(
'%d',
'%s',
'%s',
'%d',
);
} else {
- $getFileData->bindParam(':eid', $event['id'], PDO::PARAM_INT);
- $getFileData->execute();
+ $get_file_data->bindParam(':eid', $event['id'], PDO::PARAM_INT);
+ $get_file_data->execute();
$file = $filename = '';
- $fileData = $getFileData->fetch(PDO::FETCH_ASSOC);
+ $fileData = $get_file_data->fetch(PDO::FETCH_ASSOC);
if ($fileData ) {
- $file = $fileData['filename'];
+ $file = $fileData['filename'];
$filename = $fileData['urltext'];
}
$intro = ($event['intro'])
? substr(strip_tags($event['intro']), 0, 250)
: substr(strip_tags($event['description']), 0, 250);
- $eventData = array(
+ $event_data = array(
'status' => (($event['active'] == '1')
? $this->config['status_numb']['Active']
: $this->config['status_numb']['Inactive']),
- 'created' => $event['created'],
- 'updated' => $event['updated'],
- 'approved' => $event['approved'],
- 'name' => $event['header'],
- 'intro' => $intro,
- 'descr' => $event['description'],
- 'image' => $event['image'],
- 'file1' => $file,
- 'file1_descr' => $filename,
- 'cost' => $event['cost'],
- 'url' => $event['website'],
- 'old_event_id' => $event['id'],
- 'ref_type' => $refType,
- 'ref_dest' => $foundMemberId,
+ 'created' => $event['created'],
+ 'updated' => $event['updated'],
+ 'approved' => $event['approved'],
+ 'name' => $event['header'],
+ 'intro' => $intro,
+ 'descr' => $event['description'],
+ 'image' => $event['image'],
+ 'file1' => $file,
+ 'file1_descr' => $filename,
+ 'cost' => $event['cost'],
+ 'url' => $event['website'],
+ 'old_event_id' => $event['id'],
+ 'ref_type' => $refType,
+ 'ref_dest' => $found_member_id,
'admin_name' => $event['admin_contact'],
- 'admin_org' => $event['admin_org'],
- 'admin_email' => $event['admin_email'],
- 'admin_phone' => $event['admin_phone'],
- 'contact_email' => $event['contact_email'],
- 'contact_name' => $event['contact_name'],
- 'contact_phone' => $event['contact_phone'],
- 'notes' => $event['notes'],
- 'hide_address' => $event['hide_address'],
+ 'admin_org' => $event['admin_org'],
+ 'admin_email' => $event['admin_email'],
+ 'admin_phone' => $event['admin_phone'],
+ 'contact_email' => $event['contact_email'],
+ 'contact_name' => $event['contact_name'],
+ 'contact_phone' => $event['contact_phone'],
+ 'notes' => $event['notes'],
+ 'hide_address' => $event['hide_address'],
'use_member_location' => $event['use_memberloc']
);
- $eventDataFormat = array(
+ $event_data_format = array(
'%d',
'%s',
'%s',
);
}
- echo '<pre>$eventData: ' . print_r($eventData, true) . '</pre>';
+ echo '<pre>$eventData: ' . print_r($event_data, true) . '</pre>';
echo '</pre>';
$this->wpdb->insert(
GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . 'events',
- $eventData,
- $eventDataFormat
+ $event_data,
+ $event_data_format
);
- $eventId = $this->wpdb->insert_id;
- var_dump( $eventId );
- echo '<pre>$eventId: from insert ' . print_r($eventId, true) . '</pre>';
- if ( !$eventId ) {
+ $event_id = $this->wpdb->insert_id;
+ var_dump( $event_id );
+ echo '<pre>$eventId: from insert ' . print_r($event_id, true) . '</pre>';
+ if ( !$event_id ) {
echo '<pre>SQL Error: ' . $this->wpdb->last_error . '</pre>';
echo '<pre>SQL Error: ' . $this->wpdb->print_error() . '</pre>';
}
// checking for $eventId
//echo '<pre>$eventId: ' . print_r($eventId, true) . '</pre>';
- if (!$eventId) {
+ if (!$event_id) {
die('something is wrong no eventId');
}
// generate the slug name for this new event
- $eventAbstract = new GlmDataEvents($this->wpdb, $this->config);
- $eventAbstract->updateSlug($eventId);
+ $event_abstract = new GlmDataEvents($this->wpdb, $this->config);
+ $event_abstract->updateSlug($event_id);
// category for event
if ( $event['topicid'] ) {
$this->wpdb->insert(
GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . 'event_categories',
array(
- 'event' => $eventId,
+ 'event' => $event_id,
'category' => $this->oldCatMap[$event['topicid']]
),
array(
$this->wpdb->insert(
GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . 'event_categories',
array(
- 'event' => $eventId,
+ 'event' => $event_id,
'category' => $this->oldCatMap[$event['category']]
),
array(
}
// recurrences for the event
if (isset($event['reacur'])) {
- $recurringEvent = $event['reacur'];
- if ( $recurringEvent && ( $event['bdate'] == $event['edate'] ) ) {
- $recurringEvent = 0;
+ $recurring_event = $event['reacur'];
+ if ( $recurring_event && ( $event['bdate'] == $event['edate'] ) ) {
+ $recurring_event = 0;
}
} else {
- $recurringEvent = $event['recurr'];
- if ( $recurringEvent && ( $event['starting'] == $event['ending'] ) ) {
- $recurringEvent = 0;
+ $recurring_event = $event['recurr'];
+ if ( $recurring_event && ( $event['starting'] == $event['ending'] ) ) {
+ $recurring_event = 0;
}
}
- $dayOfWeek =
- $monthOfYear =
- $weekOfMonth =
- $byDayOfMonth =
- $lastDayOfMonth = null;
- if ( $recurringEvent ) {
+ $day_of_week =
+ $month_of_year =
+ $week_of_month =
+ $by_day_of_month =
+ $last_day_of_month = null;
+ if ( $recurring_event ) {
if ( $event['daysow'] ) {
- $dayOfWeek = $event['daysow'];
+ $day_of_week = $event['daysow'];
} else {
- $dayOfWeek = 127;
+ $day_of_week = 127;
}
if ( $event['weekom'] ) {
switch ($event['weekom']) {
case '1':
- $weekOfMonth = 1;
+ $week_of_month = 1;
break;
case '2':
- $weekOfMonth = 2;
+ $week_of_month = 2;
break;
case '3':
- $weekOfMonth = 4;
+ $week_of_month = 4;
break;
case '4':
- $weekOfMonth = 8;
+ $week_of_month = 8;
break;
case '5':
- $weekOfMonth = 16;
+ $week_of_month = 16;
break;
}
} else {
- $weekOfMonth = 63;
+ $week_of_month = 63;
}
- $monthOfYear = 4095;
+ $month_of_year = 4095;
}
if ( isset($event['btime']) ) {
- $btime = $this->getTime($event['btime']);
- $etime = $this->getTime($event['etime']);
+ $btime = $this->getTime($event['btime']);
+ $etime = $this->getTime($event['etime']);
} else {
- $btime = $this->getTime($event['starthour']);
- $etime = $this->getTime($event['endhour']);
+ $btime = $this->getTime($event['starthour']);
+ $etime = $this->getTime($event['endhour']);
}
- $startTimeOnly = ($btime && !$etime);
- if ( $startTimeOnly ) {
+ $start_time_only = ($btime && !$etime);
+ if ( $start_time_only ) {
$etime = $btime;
}
if ( isset($event['all_day']) ) {
- $allDay = ( $event['all_day'] || !$btime );
+ $all_day = ( $event['all_day'] || !$btime );
} else {
- $allDay = ( $event['allday'] || !$btime );
+ $all_day = ( $event['allday'] || !$btime );
}
if (isset($event['bdate'])) {
- $fromDate = $event['bdate'];
- $toDate = $event['edate'];
+ $from_date = $event['bdate'];
+ $to_date = $event['edate'];
} else {
- $fromDate = $event['starting'];
- $toDate = $event['ending'];
+ $from_date = $event['starting'];
+ $to_date = $event['ending'];
}
- $recurData =array(
- 'event' => $eventId,
- 'name' => 'Imported Event Schedule',
+ $recur_data =array(
+ 'event' => $event_id,
+ 'name' => 'Imported Event Schedule',
'start_time' => $btime,
- 'end_time' => $etime,
- 'start_time_only' => $startTimeOnly,
- 'from_date' => $fromDate,
- 'to_date' => $toDate,
- 'all_day' => $allDay,
- 'recurring' => $recurringEvent,
- 'month_of_year' => $monthOfYear,
- 'week_of_month' => $weekOfMonth,
- 'day_of_week' => $dayOfWeek,
- 'by_day_of_month' => $byDayOfMonth,
- 'last_day_of_month' => $lastDayOfMonth
+ 'end_time' => $etime,
+ 'start_time_only' => $start_time_only,
+ 'from_date' => $from_date,
+ 'to_date' => $to_date,
+ 'all_day' => $all_day,
+ 'recurring' => $recurring_event,
+ 'month_of_year' => $month_of_year,
+ 'week_of_month' => $week_of_month,
+ 'day_of_week' => $day_of_week,
+ 'by_day_of_month' => $by_day_of_month,
+ 'last_day_of_month' => $last_day_of_month
);
//echo '<pre>' . print_r( $recurData, true) . '</pre>';
- echo '<pre>$recurData: ' . print_r($recurData, true) . '</pre>';
+ echo '<pre>$recurData: ' . print_r($recur_data, true) . '</pre>';
$this->wpdb->insert(
GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . 'recurrences',
- $recurData,
+ $recur_data,
array(
'%d',
'%s',
'%d',
)
);
- $recurId = $this->wpdb->insert_id;
- $Recurrences->createRecurrenceTimesEntries( $recurId, true, true );
+ $recur_id = $this->wpdb->insert_id;
+ $Recurrences->createRecurrenceTimesEntries( $recur_id, true, true );
// location for the event
- $hasLocation = ($event['loc'] || $event['place']);
- if ( $hasLocation ) {
- $locationData = $locationFormat = array();
- $locationData['event'] = $eventId;
- $locationFormat[] = '%d';
+ $has_location = ($event['loc'] || $event['place']);
+ if ( $has_location ) {
+ $location_data = $location_format = array();
+ $location_data['event'] = $event_id;
+ $location_format[] = '%d';
if ($event['place']) {
- $locationData['name'] = $event['place'];
- $locationFormat[] = '%s';
+ $location_data['name'] = $event['place'];
+ $location_format[] = '%s';
}
if ($event['loc']) {
- $locationData['name'] = $event['loc'];
- $locationFormat[] = '%s';
+ $location_data['name'] = $event['loc'];
+ $location_format[] = '%s';
}
if ($event['address']) {
- $locationData['address'] = $event['address'];
- $locationFormat[] = '%s';
+ $location_data['address'] = $event['address'];
+ $location_format[] = '%s';
}
if ($event['city']) {
- $locationData['city'] = $this->getCityId( $event['city'] );
- $locationFormat[] = '%s';
+ $location_data['city'] = $this->getCityId( $event['city'] );
+ $location_format[] = '%s';
}
if ($event['state']) {
- $locationData['state'] = $event['state'];
- $locationFormat[] = '%s';
+ $location_data['state'] = $event['state'];
+ $location_format[] = '%s';
}
if ($event['zip']) {
- $locationData['zip'] = $event['zip'];
- $locationFormat[] = '%s';
+ $location_data['zip'] = $event['zip'];
+ $location_format[] = '%s';
}
if ($event['lat']) {
- $locationData['lat'] = $event['lat'];
- $locationFormat[] = '%s';
+ $location_data['lat'] = $event['lat'];
+ $location_format[] = '%s';
}
if ($event['lon']) {
- $locationData['lon'] = $event['lon'];
- $locationFormat[] = '%s';
+ $location_data['lon'] = $event['lon'];
+ $location_format[] = '%s';
}
$this->wpdb->insert(
GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . 'locations',
- $locationData,
- $locationFormat
+ $location_data,
+ $location_format
);
- $locationId = $this->wpdb->insert_id;
- if ( !$locationId ) {
- echo '<pre>$locationData: ' . print_r($locationData, true) . '</pre>';
+ $location_id = $this->wpdb->insert_id;
+ if ( !$location_id ) {
+ echo '<pre>$locationData: ' . print_r($location_data, true) . '</pre>';
die('no return id for location');
}
}
}
return $return;
}
+ public function importFromTimely() {
+ // clear the events tables first
+ $this->wpdb->query( "DELETE FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "events" );
+ $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" );
+
+ $return = $this->addTimelyCategories();
+
+ $Recurrences = new GlmDataEventsRecurrences($this->wpdb, $this->config);
+ require_once(GLM_MEMBERS_PLUGIN_PATH.'/models/admin/ajax/imageUpload.php');
+ $image_upload = new GlmMembersAdmin_ajax_imageUpload($this->wpdb, $this->config);
+
+ $sql = "
+ SELECT *
+ FROM " . $this->wpdb->prefix . "posts
+ WHERE post_type = 'ai1ec_event'
+ AND post_status = 'publish'";
+ $results = $this->wpdb->get_results( $sql, ARRAY_A );
+
+ echo '<p>Total events: ' . count( $results ) . '</p>';
+
+ if ( !empty( $results ) ) {
+ foreach ( $results as $post ) {
+ echo '<pre>$post: ' . print_r($post, true) . '</pre>';
+ $sql = "
+ SELECT *
+ FROM " . $this->wpdb->prefix . "ai1ec_events
+ WHERE post_id = {$post['ID']}";
+ $event_data = $this->wpdb->get_row( $sql, ARRAY_A );
+ echo '<pre>$event_data: ' . print_r($event_data, true) . '</pre>';
+ $cost_data = unserialize( $event_data['cost'] );
+ $cost = $cost_data['cost'];
+ $is_free = $cost_data['is_free'];
+
+ // use the posts table data
+ $image = '';
+ if ( has_post_thumbnail( $post['ID'] ) ) {
+ $thumbnail_id = get_post_thumbnail_id( $post['ID'] );
+ $thumb_src = wp_get_attachment_image_src( $thumbnail_id, 'large' );
+ echo '<pre>$thumb_src: ' . print_r($thumb_src, true) . '</pre>';
+ $res = $image_upload->storeImage($thumb_src[0]);
+ echo '<pre>$res: ' . print_r($res, true) . '</pre>';
+ if ( $res['newFileName'] ) {
+ $image = $res['newFileName'];
+ }
+ }
+ // Insert the event data
+ $event_import_data = array(
+ 'status' => $this->config['status_numb']['Active'],
+ 'created' => $post['post_date'],
+ 'updated' => $post['post_modified'],
+ 'approved' => $post['post_modified'],
+ 'name' => $post['post_title'],
+ 'name_slug' => $post['post_name'],
+ 'intro' => substr( strip_tags( $post['post_content'] ), 0, 250 ),
+ 'descr' => $post['post_content'],
+ 'image' => $image,
+ 'file1' => null,
+ 'file1_descr' => null,
+ 'cost' => $cost,
+ 'free' => $is_free,
+ 'url' => $event_data['contact_url'],
+ 'old_event_id' => $post['ID'],
+ 'ref_type' => null,
+ 'ref_dest' => null,
+ 'admin_name' => $event_data['contact_name'],
+ 'admin_org' => null,
+ 'admin_email' => $event_data['contact_email'],
+ 'admin_phone' => $event_data['contact_phone'],
+ 'contact_email' => $event_data['contact_email'],
+ 'contact_name' => $event_data['contact_name'],
+ 'contact_phone' => $event_data['contact_phone'],
+ 'notes' => null,
+ 'hide_address' => null,
+ 'use_member_location' => 0,
+ );
+ $event_data_format = array(
+ '%d',
+ '%s',
+ '%s',
+ '%s',
+ '%s',
+ '%s',
+ '%s',
+ '%s',
+ '%s',
+ '%s',
+ '%s',
+ '%s',
+ '%s',
+ '%s',
+ '%s',
+ '%s',
+ '%s',
+ '%s',
+ '%s',
+ '%s',
+ '%s',
+ '%s',
+ '%s',
+ '%s',
+ '%s',
+ '%s',
+ );
+ $this->wpdb->insert(
+ GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . 'events',
+ $event_import_data,
+ $event_data_format
+ );
+ $event_id = $this->wpdb->insert_id;
+ var_dump( $event_id );
+ if ( !$event_id ) {
+ echo '<pre>SQL Error: ' . $this->wpdb->last_error . '</pre>';
+ echo '<pre>SQL Error: ' . $this->wpdb->print_error() . '</pre>';
+ die('something is wrong no event_id');
+ }
+ // get the post categories
+ $categories = array();
+ $post_terms = wp_get_post_terms( $post['ID'], 'events_categories', 'term_id' );
+ foreach ( $post_terms as $term ) {
+ $this->wpdb->insert(
+ GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . 'event_categories',
+ array(
+ 'event' => $event_id,
+ 'category' => $this->oldCatMap[$term->term_id]
+ ),
+ array(
+ '%d',
+ '%d'
+ )
+ );
+ }
+ echo '<pre>$categories: ' . print_r($categories, true) . '</pre>';
+
+ $by_day_of_month =
+ $last_day_of_month = null;
+
+ $recurring_event =
+ $start_time_only =
+ $recurring_event = 0;
+
+ $weekly =
+ $daily = false;
+
+ $day_of_week = 127;
+ $month_of_year = 4095;
+ $week_of_month = 63;
+
+ $from_date = date( 'Y-m-d', $event_data['start'] );
+ echo '<pre>$from_date: ' . print_r($from_date, true) . '</pre>';
+ $to_date = date( 'Y-m-d', $event_data['end'] );
+ echo '<pre>$to_date: ' . print_r($to_date, true) . '</pre>';
+ $btime = date( 'H:i', $event_data['start'] );
+ echo '<pre>$btime: ' . print_r($btime, true) . '</pre>';
+ $etime = date( 'H:i', $event_data['end'] );
+ echo '<pre>$etime: ' . print_r($etime, true) . '</pre>';
+
+ if ( $event_data['recurrence_rules'] ) {
+ $recurring_event = 1;
+ $recurrence_rules = explode( ';', $event_data['recurrence_rules'] );
+ echo '<pre>$recurrence_rules: ' . print_r($recurrence_rules, true) . '</pre>';
+ foreach ( $recurrence_rules as $rule ) {
+ if(strpos($rule, 'RDATE') !== false){
+ $rdate = $rule;
+ $rdate = substr($rdate,6);
+ $custom_times = explode(',', $rdate);
+ }
+ if ( preg_match( ';FREQ=(.*);', $rule, $matches ) ) {
+ echo '<pre>$matches: ' . print_r($matches, true) . '</pre>';
+ switch ( $matches[1] ) {
+ case "WEEKLY":
+ $weekly = true;
+ // check for BYDAY
+ break;
+ case "DAILY":
+ $daily = true;
+ break;
+ case "YEARLY":
+ $sum = 0;
+ $yearly = $recurrence_rules[1];
+ $yearly = substr($yearly,8);
+ $month_ints = explode(',', $yearly);
+ foreach($month_ints as $ints){
+ $ints--;
+ $ints = pow(2, $ints);
+ $month_sum += $ints;
+ }
+ $month_of_year = $month_sum;
+ $day_of_month = 2147483647;
+ if($month_sum){
+ $by_day_of_month = 1;
+ }
+ break;
+ case "MONTHLY":
+ $monthly = $recurrence_rules[1];
+ $pos = strpos($monthly, "BYday");
+ if($pos === false){
+ $monthly = substr($monthly, 11);
+ $day_ints = explode(',', $monthly);
+ foreach($day_ints as $day){
+ $day--;
+ $day = pow(2, $day);
+ $day_sum += $day;
+ }
+ $day_of_month = $day_sum;
+ if($day_sum){
+ $by_day_of_month = 1;
+ }
+ }
+ break;
+ }
+ } else if ( preg_match( ';COUNT=(.*);', $rule, $matches ) ) {
+ echo '<pre>$matches: ' . print_r($matches, true) . '</pre>';
+ // set the end date to COUNT days from start
+ try {
+ $number_of_days = (int)$matches[1] - 1;
+ $starting_datetime = new DateTime( $from_date );
+ $add = ( $number_of_days === 1 ) ? '1 day': $number_of_days . ' days';
+ $ending_date = $starting_datetime->modify($add);
+ $to_date = $ending_date->format( 'Y-m-d' );
+ $recurring_event = 0;
+ } catch (Exception $e) {
+ echo '<pre>$e: ' . print_r($e, true) . '</pre>';
+ die();
+ }
+ } else if ( preg_match( ';UNTIL=(.*);', $rule, $matches ) ) {
+ $to_date = date( 'Y-m-d', strtotime( $matches[1] ) );
+ } else if ( preg_match( ';BYday=(.*);', $rule, $matches ) ) {
+
+ echo '<pre>$matches: ' . print_r($matches, true) . '</pre>';
+
+ // check if the selection is the nth week with a selected day, if not parse the input as a list if selected days
+ if(strpos($matches[1], ",") == false){
+ $week_number = substr($matches[1],0, 1);
+ $week_number = $week_number - 1;
+ $week_of_month = pow(2, $week_number);
+ $days[] = substr($matches[1], -2);
+ $by_day_of_month = 0;
+ } else {
+ $days = explode( ',', $matches[1] );
+ }
+ $day_of_week = 0;
+ foreach ( $days as $day ) {
+ switch ( $day ) {
+ case "SU":
+ $day_of_week += pow(2, 0);
+ break;
+ case "MO":
+ $day_of_week += pow(2, 1);
+ break;
+ case "TU":
+ $day_of_week += pow(2, 2);
+ break;
+ case "WE":
+ $day_of_week += pow(2, 3);
+ break;
+ case "TH":
+ $day_of_week += pow(2, 4);
+ break;
+ case "FR":
+ $day_of_week += pow(2, 5);
+ break;
+ case "SA":
+ $day_of_week += pow(2, 6);
+ break;
+ }
+ }
+ }
+ }
+ if(!empty($custom_times)){
+ date_default_timezone_set('UTC');
+ $serialized_custom_times = serialize($custom_times);
+ foreach($custom_times as $custom){
+ $convert = date('U',strtotime($custom));
+ $stamp[] = date('Y-m-d', $convert);
+ }
+ $serialized_custom_times = serialize($stamp);
+ }
+ }
+ $all_day = $event_data['allday'];
+ // for the recurrences part
+ $recur_data = array(
+ 'event' => $event_id,
+ 'name' => 'Imported',
+ 'start_time' => $btime,
+ 'end_time' => $etime,
+ 'start_time_only' => $start_time_only,
+ 'from_date' => $from_date,
+ 'to_date' => $to_date,
+ 'all_day' => $all_day,
+ 'recurring' => $recurring_event,
+ 'month_of_year' => $month_of_year,
+ 'week_of_month' => $week_of_month,
+ 'day_of_week' => $day_of_week,
+ 'day_of_month' => $day_of_month,
+ 'by_day_of_month' => $by_day_of_month,
+ 'last_day_of_month' => $last_day_of_month,
+ 'specific_dates' => $serialized_custom_times
+ );
+ echo '<pre>$recur_data: ' . print_r($recur_data, true) . '</pre>';
+ $this->wpdb->insert(
+ GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . 'recurrences',
+ $recur_data,
+ array(
+ '%d',
+ '%s',
+ '%s',
+ '%s',
+ '%s',
+ '%s',
+ '%s',
+ '%d',
+ '%d',
+ '%d',
+ '%d',
+ '%d',
+ '%d',
+ '%d',
+ '%d',
+ '%s'
+ )
+ );
+ $recurr_id = $this->wpdb->insert_id;
+ var_dump($recurr_id);
+ $Recurrences->createRecurrenceTimesEntries( $recurr_id, true, true );
+ // location for the event
+ $has_location = ( $event_data['address'] || $event_data['venue'] );
+ if ( $has_location ) {
+ $location_data = $location_format = array();
+ $location_data['event'] = $event_id;
+ $location_format[] = '%d';
+ if ($event_data['venue']) {
+ $location_data['name'] = $event_data['venue'];
+ $location_format[] = '%s';
+ }
+ if ($event_data['address']) {
+ $location_data['address'] = $event_data['address'];
+ $location_format[] = '%s';
+ }
+ if ($event_data['city']) {
+ $location_data['city'] = $this->getCityId( $event_data['city'] );
+ $location_format[] = '%s';
+ }
+ if ($event_data['province']) {
+ // need to lookup the state abbreviation
+ $state_abbr = array_search( $event_data['province'], $this->config['states'] );
+ if ( $state_abbr !== false ) {
+ $location_data['state'] = $state_abbr;
+ $location_format[] = '%s';
+ }
+ }
+ if ($event_data['postal_code']) {
+ $location_data['zip'] = $event_data['postal_code'];
+ $location_format[] = '%s';
+ }
+ if ($event_data['latitude']) {
+ $location_data['lat'] = $event_data['latitude'];
+ $location_format[] = '%s';
+ }
+ if ($event_data['longitude']) {
+ $location_data['lon'] = $event_data['longitude'];
+ $location_format[] = '%s';
+ }
+ $this->wpdb->insert(
+ GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . 'locations',
+ $location_data,
+ $location_format
+ );
+ $location_id = $this->wpdb->insert_id;
+ if ( !$location_id ) {
+ echo '<pre>$location_data: ' . print_r($location_data, true) . '</pre>';
+ die('no return id for location');
+ }
+ }
+ }
+ }
+ }
}
?>