/** * Parse the fields of an Event to the structure used by API */ public function parse_event_fields_to_api_structure(Ai1ec_Event $event, WP_Post $post, $post_ticket_types, $api_fields_values) { $calendar_id = $this->_get_ticket_calendar(); if ($calendar_id <= 0) { return null; } //fields of ai1ec events table used by API $body['latitude'] = $event->get('latitude'); $body['longitude'] = $event->get('longitude'); $body['post_id'] = $event->get('post_id'); $body['calendar_id'] = $calendar_id; $body['dtstart'] = $event->get('start')->format_to_javascript(); $body['dtend'] = $event->getenddate()->format_to_javascript(); $body['timezone'] = $event->get('timezone_name'); $body['venue_name'] = $event->get('venue'); $body['address'] = $event->get('address'); $body['city'] = $event->get('city'); $body['province'] = $event->get('province'); $body['postal_code'] = $event->get('postal_code'); $body['country'] = $event->get('country'); $body['contact_name'] = $event->get('contact_name'); $body['contact_phone'] = $event->get('contact_phone'); $body['contact_email'] = $event->get('contact_email'); $body['contact_website'] = $event->get('contact_url'); $body['uid'] = $event->get_uid(); $body['title'] = $post->post_title; $body['description'] = $post->post_content; $body['url'] = get_permalink($post->ID); $body['status'] = $post->post_status; $utc_current_time = $this->_registry->get('date.time')->format_to_javascript(); $body['created_at'] = $utc_current_time; $body['updated_at'] = $utc_current_time; //removing blank values foreach ($body as $key => $value) { if (ai1ec_is_blank($value)) { unset($body[$key]); } } if (is_null($api_fields_values) || 0 == count($api_fields_values)) { $api_fields_values = array('status' => 'closed', 'ai1ec_version' => AI1EC_VERSION); } else { if (!isset($api_fields_values['ai1ec_version'])) { $api_fields_values['ai1ec_version'] = AI1EC_VERSION; } foreach ($api_fields_values as $key => $value) { $body[$key] = $api_fields_values[$key]; if ('visibility' === $key) { if (0 === strcasecmp('private', $value)) { $body['status'] = 'private'; } else { if (0 === strcasecmp('password', $value)) { $body['status'] = 'password'; } } } } } $tickets_types = array(); if (!is_null($post_ticket_types)) { $index = 0; foreach ($post_ticket_types as $ticket_type_ite) { if (false === isset($ticket_type_ite['id']) && isset($ticket_type_ite['remove'])) { //ignoring new tickets that didn't go to api yet continue; } $tickets_types[$index++] = $this->_parse_tickets_type_post_to_api_structure($ticket_type_ite, $event); } } $body['ticket_types'] = $tickets_types; return $body; }