/** * Event Profiles */ protected function ccb_event_profiles($item) { update_option('ccbpress_event_sync_in_progress', 'Processing batch ' . $item['args']['page']); $results = CCBPress()->ccb->event_profiles($item['args']); if (!$results) { delete_option('ccbpress_event_sync_in_progress'); update_option('ccbpress_last_event_sync', date('Y-m-d H:i:s', current_time('timestamp'))); return false; } $events_count = 0; if (isset($results->response->events['count'])) { $events_count = $results->response->events['count']; } $event_profiles_db = new CCBPress_Event_Profiles_DB(); foreach ($results->response->events->event as $event) { // Skip the event if it is not listed if ('false' == $event->public_calendar_listed) { continue; } $db_data = array('event_id' => $event['id'], 'name' => $event->name, 'description' => $event->description, 'leader_notes' => $event->leader_notes, 'start_datetime' => date('Y-m-d H:i:s', strtotime($event->start_datetime, current_time('timestamp'))), 'start_date' => $event->start_date, 'start_time' => $event->start_time, 'end_datetime' => date('Y-m-d H:i:s', strtotime($event->end_datetime, current_time('timestamp'))), 'end_date' => $event->end_date, 'end_time' => $event->end_time, 'timezone' => $event->timezone, 'recurrence_description' => $event->recurrence_description, 'approval_status_id' => $event->approval_status['id'], 'approval_status' => $event->approval_status, 'exceptions' => json_encode($event->exceptions), 'group_id' => $event->group['id'], 'group_name' => $event->group, 'organizer_id' => $event->organizer['id'], 'organizer' => $event->organizer, 'phone_type' => $event->phone['type'], 'phone' => $event->phone, 'location_name' => $event->location->name, 'location_street_address' => $event->location->street_address, 'location_city' => $event->location->city, 'location_state' => $event->location->state, 'location_zip' => $event->location->zip, 'location_line_1' => $event->location->line_1, 'location_line_2' => $event->location->line_2, 'registration_limit' => $event->registration->limit, 'registration_event_type_id' => $event->registration->event_type['id'], 'registration_event_type' => $event->registration->event_type, 'registration_forms' => json_encode($event->registration->forms), 'resources' => json_encode($event->resources), 'setup_start' => date('Y-m-d H:i:s', strtotime($event->setup->start, current_time('timestamp'))), 'setup_end' => date('Y-m-d H:i:s', strtotime($event->setup->end, current_time('timestamp'))), 'setup_notes' => $event->setup->notes, 'event_grouping_id' => $event->event_grouping['id'], 'event_grouping' => $event->event_grouping, 'creator_id' => $event->creator['id'], 'creator' => $event->creator, 'modifier_id' => $event->modifier['id'], 'modifier' => $event->modifier, 'listed' => 'true' == $event->listed ? 1 : 0, 'public_calendar_listed' => 'true' == $event->public_calendar_listed ? 1 : 0, 'created' => date('Y-m-d H:i:s', strtotime($event->created, current_time('timestamp'))), 'modified' => date('Y-m-d H:i:s', strtotime($event->modified, current_time('timestamp')))); $exists = $event_profiles_db->get($event['id']); if ($exists) { $event_profiles_db->update($event['id'], $db_data); } else { $event_profiles_db->insert($db_data); } unset($exists); } unset($event_profiles_db); unset($results); if ($events_count > 0 && $item['args']['per_page'] > 0 && $events_count == $item['args']['per_page']) { $item['args']['page'] = $item['args']['page'] + 1; return $item; } delete_option('ccbpress_event_sync_in_progress'); update_option('ccbpress_last_event_sync', date('Y-m-d H:i:s', current_time('timestamp'))); return false; }
/** * Create the custom tables needed for our plugin * * @since 1.0.0 * * @return void */ public static function create_tables() { require_once plugin_dir_path(__FILE__) . 'includes/group_profiles-db.php'; $group_profiles_db = new CCBPress_Group_Profiles_DB(); $group_profiles_db->create_table(); unset($group_profiles_db); require_once plugin_dir_path(__FILE__) . 'includes/event_profiles-db.php'; $event_profiles_db = new CCBPress_Event_Profiles_DB(); $event_profiles_db->create_table(); unset($event_profiles_db); }
private function purge($what) { switch ($what) { case 'groups': $group_profiles_db = new CCBPress_Group_Profiles_DB(); $group_profiles_db->purge(strtotime('yesterday', current_time('timestamp'))); break; case 'events': $event_profiles_db = new CCBPress_Event_Profiles_DB(); $event_profiles_db->purge(strtotime('yesterday', current_time('timestamp'))); break; } }