source/php/Parser/EventManagerApi.php
public function saveEvent($event)
    {
        $post_title                     = !empty($event['title']['rendered']) ? $event['title']['rendered'] : null;
        $post_content                   = !empty($event['content']['rendered']) ? $event['content']['rendered'] : null;
        $featured_media                 = !empty($event['featured_media']['source_url']) ? $event['featured_media']['source_url'] : null;
        $categories                     = !empty($event['event_categories']) ? $this->sanitizeCategories($event['event_categories']) : array();
        $tags                           = !empty($event['event_tags']) ? array_map('strtolower', array_map('trim', $event['event_tags'])) : array();
        $groups                         = !empty($event['user_groups']) ? $event['user_groups'] : array();
        $occasions                      = !empty($event['occasions']) ? $event['occasions'] : null;
        $event_link                     = !empty($event['event_link']) ? $event['event_link'] : null;
        $additional_links               = !empty($event['additional_links']) ? $event['additional_links'] : null;
        $related_events                 = !empty($event['related_events']) ? $event['related_events'] : null;
        $organizers                     = !empty($event['organizers']) ? $event['organizers'] : null;
        $supporters                     = !empty($event['supporters']) ? $event['supporters'] : null;
        $booking_link                   = !empty($event['booking_link']) ? $event['booking_link'] : null;
        $booking_phone                  = !empty($event['booking_phone']) ? $event['booking_phone'] : null;
        $booking_email                  = !empty($event['booking_email']) ? $event['booking_email'] : null;
        $age_restriction                = !empty($event['age_restriction']) ? $event['age_restriction'] : null;
        $membership_cards               = !empty($event['membership_cards']) ? $event['membership_cards'] : null;
        $price_information              = !empty($event['price_information']) ? $event['price_information'] : null;
        $ticket_includes                = !empty($event['ticket_includes']) ? $event['ticket_includes'] : null;
        $price_adult                    = isset($event['price_adult']) && $event['price_adult'] !== '' ? $event['price_adult'] : null;
        $price_children                 = isset($event['price_children']) && $event['price_children'] !== '' ? $event['price_children'] : null;
        $children_age                   = !empty($event['children_age']) ? $event['children_age'] : null;
        $price_student                  = isset($event['price_student']) && $event['price_student'] !== '' ? $event['price_student'] : null;
        $price_senior                   = isset($event['price_senior']) && $event['price_senior'] !== '' ? $event['price_senior'] : null;
        $senior_age                     = !empty($event['senior_age']) ? $event['senior_age'] : null;
        $booking_group                  = !empty($event['booking_group']) ? $event['booking_group'] : null;
        $gallery                        = !empty($event['gallery']) ? $event['gallery'] : null;
        $facebook                       = !empty($event['facebook']) ? $event['facebook'] : null;
        $twitter                        = !empty($event['twitter']) ? $event['twitter'] : null;
        $instagram                      = !empty($event['instagram']) ? $event['instagram'] : null;
        $google_music                   = !empty($event['google_music']) ? $event['google_music'] : null;
        $spotify                        = !empty($event['spotify']) ? $event['spotify'] : null;
        $soundcloud                     = !empty($event['soundcloud']) ? $event['soundcloud'] : null;
        $deezer                         = !empty($event['deezer']) ? $event['deezer'] : null;
        $youtube                        = !empty($event['youtube']) ? $event['youtube'] : null;
        $vimeo                          = !empty($event['vimeo']) ? $event['vimeo'] : null;
        $post_status                    = get_field('event_post_status', 'option') ? get_field('event_post_status', 'option') : 'publish';
        $location                       = !empty($event['location']) ? $event['location'] : null;
        $additional_locations           = !empty($event['additional_locations']) ? $event['additional_locations'] : null;
        $latitude                       = is_array($location) && ! empty($location['latitude']) ? $location['latitude'] : null;
        $longitude                      = is_array($location) && ! empty($location['longitude']) ? $location['longitude'] : null;
        $last_update                    = !empty($event['modified_gmt']) ? $event['modified_gmt'] : null;
        $ticket_stock                   = isset($event['ticket_stock']) && $event['ticket_stock'] !== '' ? $event['ticket_stock'] : null;
        $tickets_remaining              = isset($event['tickets_remaining']) && $event['tickets_remaining'] !== '' ? $event['tickets_remaining'] : null;
        $additional_ticket_retailers    = !empty($event['additional_ticket_retailers']) ? $event['additional_ticket_retailers'] : null;
        $additional_ticket_types        = !empty($event['additional_ticket_types']) ? $event['additional_ticket_types'] : null;
        $price_range                    = !empty($event['price_range']) ? $event['price_range'] : null;
        $ticket_release_date            = !empty($event['ticket_release_date']) ? $event['ticket_release_date'] : null;
        $contact_information            = !empty($event['contact_information']) ? $event['contact_information'] : null;
        $contact_phone                  = !empty($event['contact_phone']) ? $event['contact_phone'] : null;
        $contact_email                  = !empty($event['contact_email']) ? $event['contact_email'] : null;
        $age_group_from                 = !empty($event['age_group_from']) ? $event['age_group_from'] : null;
        $age_group_to                   = !empty($event['age_group_to']) ? $event['age_group_to'] : null;
        $accessibility                  = !empty($event['accessibility']) ? $event['accessibility'] : null;
        $lang                           = !empty($event['lang']) ? $event['lang'] : null;
        $translations                   = !empty($event['translations']) ? $event['translations'] : null;

        // Check if event passes taxonomy filters
        $pass_tax_filter = $this->checkFilters(
            $this->filterTaxonomies($categories, 0),
            $this->filterTaxonomies($tags, 1)
        );

        // Check if event already exist and get the post status
        $event_id = $this->checkIfEventExists($event['id']);
        if ($event_id) {
            $post_status = get_post_status($event_id);
        } elseif (is_array($occasions) && !empty($occasions)) {
            // Unpublish the event if occasion is longer than limit option
            $unpublish_limit = get_field('event_unpublish_limit', 'option');
            foreach ($occasions as $occasion) {
                $start = new \DateTime($occasion['start_date']);
                $end = new \Datetime($occasion['end_date']);
                $difference = $end->diff($start)->format("%a");
                if ($unpublish_limit != null && $unpublish_limit >= 0 && ($difference > $unpublish_limit)) {
                    $post_status = 'draft';
                }
            }
        }

        // Save event if it passed taxonomy and group filters
        if ($pass_tax_filter) {
            try {
                $event = new Event(
                    array(
                        'post_title' => $post_title,
                        'post_content' => $post_content,
                        'post_status' => $post_status,
                    ),
                    array(
                        '_event_manager_id' => $event['id'],
                        'categories' => $categories,
                        'tags' => $tags,
                        'groups' => $groups,
                        'occasions_complete' => $occasions,
                        'event_link' => $event_link,
                        'additional_links' => $additional_links,
                        'related_events' => $related_events,
                        'location' => $location,
                        'latitude' => $latitude,
                        'longitude' => $longitude,
                        'additional_locations' => $additional_locations,
                        'organizers' => $organizers,
                        'supporters' => $supporters,
                        'booking_link' => $booking_link,
                        'booking_phone' => $booking_phone,
                        'booking_email' => $booking_email,
                        'age_restriction' => $age_restriction,
                        'membership_cards' => $membership_cards,
                        'price_information' => $price_information,
                        'ticket_includes' => $ticket_includes,
                        'price_adult' => $price_adult,
                        'price_children' => $price_children,
                        'children_age' => $children_age,
                        'price_student' => $price_student,
                        'price_senior' => $price_senior,
                        'senior_age' => $senior_age,
                        'booking_group' => $booking_group,
                        'gallery' => $gallery,
                        'facebook' => $facebook,
                        'twitter' => $twitter,
                        'instagram' => $instagram,
                        'google_music' => $google_music,
                        'spotify' => $spotify,
                        'soundcloud' => $soundcloud,
                        'deezer' => $deezer,
                        'youtube' => $youtube,
                        'vimeo' => $vimeo,
                        'last_update' => $last_update,
                        'ticket_stock' => $ticket_stock,
                        'tickets_remaining' => $tickets_remaining,
                        'additional_ticket_retailers' => $additional_ticket_retailers,
                        'additional_ticket_types' => $additional_ticket_types,
                        'price_range' => $price_range,
                        'ticket_release_date' => $ticket_release_date,
                        'contact_email' => $contact_email,
                        'contact_phone' => $contact_phone,
                        'contact_information' => $contact_information,
                        'age_group_from' => $age_group_from,
                        'age_group_to' => $age_group_to,
                        'accessibility' => $accessibility,
                        'lang' => $lang,
                        'translations' => $translations
                    )
                );
            } catch (\Exception $e) {
                error_log(print_r($e, true));
                return;
            }
            $createSuccess = $event->save();

            if ($createSuccess && !empty($featured_media)) {
                $event->setFeaturedImageFromUrl($featured_media, true);
            }
        }
    }
public function saveEvent($event)
    {
        $post_title                     = !empty($event['title']['rendered']) ? $event['title']['rendered'] : null;
        $post_content                   = !empty($event['content']['rendered']) ? $event['content']['rendered'] : null;
        $featured_media                 = !empty($event['featured_media']['source_url']) ? $event['featured_media']['source_url'] : null;
        $categories                     = !empty($event['event_categories']) ? $this->sanitizeCategories($event['event_categories']) : array();
        $tags                           = !empty($event['event_tags']) ? array_map('strtolower', array_map('trim', $event['event_tags'])) : array();
        $groups                         = !empty($event['user_groups']) ? $event['user_groups'] : array();
        $occasions                      = !empty($event['occasions']) ? $event['occasions'] : null;
        $event_link                     = !empty($event['event_link']) ? $event['event_link'] : null;
        $additional_links               = !empty($event['additional_links']) ? $event['additional_links'] : null;
        $related_events                 = !empty($event['related_events']) ? $event['related_events'] : null;
        $organizers                     = !empty($event['organizers']) ? $event['organizers'] : null;
        $supporters                     = !empty($event['supporters']) ? $event['supporters'] : null;
        $booking_link                   = !empty($event['booking_link']) ? $event['booking_link'] : null;
        $booking_phone                  = !empty($event['booking_phone']) ? $event['booking_phone'] : null;
        $booking_email                  = !empty($event['booking_email']) ? $event['booking_email'] : null;
        $age_restriction                = !empty($event['age_restriction']) ? $event['age_restriction'] : null;
        $membership_cards               = !empty($event['membership_cards']) ? $event['membership_cards'] : null;
        $price_information              = !empty($event['price_information']) ? $event['price_information'] : null;
        $ticket_includes                = !empty($event['ticket_includes']) ? $event['ticket_includes'] : null;
        $price_adult                    = isset($event['price_adult']) && $event['price_adult'] !== '' ? $event['price_adult'] : null;
        $price_children                 = isset($event['price_children']) && $event['price_children'] !== '' ? $event['price_children'] : null;
        $children_age                   = !empty($event['children_age']) ? $event['children_age'] : null;
        $price_student                  = isset($event['price_student']) && $event['price_student'] !== '' ? $event['price_student'] : null;
        $price_senior                   = isset($event['price_senior']) && $event['price_senior'] !== '' ? $event['price_senior'] : null;
        $senior_age                     = !empty($event['senior_age']) ? $event['senior_age'] : null;
        $booking_group                  = !empty($event['booking_group']) ? $event['booking_group'] : null;
        $gallery                        = !empty($event['gallery']) ? $event['gallery'] : null;
        $facebook                       = !empty($event['facebook']) ? $event['facebook'] : null;
        $twitter                        = !empty($event['twitter']) ? $event['twitter'] : null;
        $instagram                      = !empty($event['instagram']) ? $event['instagram'] : null;
        $google_music                   = !empty($event['google_music']) ? $event['google_music'] : null;
        $spotify                        = !empty($event['spotify']) ? $event['spotify'] : null;
        $soundcloud                     = !empty($event['soundcloud']) ? $event['soundcloud'] : null;
        $deezer                         = !empty($event['deezer']) ? $event['deezer'] : null;
        $youtube                        = !empty($event['youtube']) ? $event['youtube'] : null;
        $vimeo                          = !empty($event['vimeo']) ? $event['vimeo'] : null;
        $post_status                    = get_field('event_post_status', 'option') ? get_field('event_post_status', 'option') : 'publish';
        $location                       = !empty($event['location']) ? $event['location'] : null;
        $additional_locations           = !empty($event['additional_locations']) ? $event['additional_locations'] : null;
        $latitude                       = is_array($location) && ! empty($location['latitude']) ? $location['latitude'] : null;
        $longitude                      = is_array($location) && ! empty($location['longitude']) ? $location['longitude'] : null;
        $last_update                    = !empty($event['modified_gmt']) ? $event['modified_gmt'] : null;
        $ticket_stock                   = isset($event['ticket_stock']) && $event['ticket_stock'] !== '' ? $event['ticket_stock'] : null;
        $tickets_remaining              = isset($event['tickets_remaining']) && $event['tickets_remaining'] !== '' ? $event['tickets_remaining'] : null;
        $additional_ticket_retailers    = !empty($event['additional_ticket_retailers']) ? $event['additional_ticket_retailers'] : null;
        $additional_ticket_types        = !empty($event['additional_ticket_types']) ? $event['additional_ticket_types'] : null;
        $price_range                    = !empty($event['price_range']) ? $event['price_range'] : null;
        $ticket_release_date            = !empty($event['ticket_release_date']) ? $event['ticket_release_date'] : null;
        $contact_information            = !empty($event['contact_information']) ? $event['contact_information'] : null;
        $contact_phone                  = !empty($event['contact_phone']) ? $event['contact_phone'] : null;
        $contact_email                  = !empty($event['contact_email']) ? $event['contact_email'] : null;
        $age_group_from                 = !empty($event['age_group_from']) ? $event['age_group_from'] : null;
        $age_group_to                   = !empty($event['age_group_to']) ? $event['age_group_to'] : null;
        $accessibility                  = !empty($event['accessibility']) ? $event['accessibility'] : null;
        $lang                           = !empty($event['lang']) ? $event['lang'] : null;
        $translations                   = !empty($event['translations']) ? $event['translations'] : null;

        // Check if event passes taxonomy filters
        $pass_tax_filter = $this->checkFilters(
            $this->filterTaxonomies($categories, 0),
            $this->filterTaxonomies($tags, 1)
        );

        // Check if event already exist and get the post status
        $event_id = $this->checkIfEventExists($event['id']);
        if ($event_id) {
            $post_status = get_post_status($event_id);
        } elseif (is_array($occasions) && !empty($occasions)) {
            // Unpublish the event if occasion is longer than limit option
            $unpublish_limit = get_field('event_unpublish_limit', 'option');
            foreach ($occasions as $occasion) {
                $start = new \DateTime($occasion['start_date']);
                $end = new \Datetime($occasion['end_date']);
                $difference = $end->diff($start)->format("%a");
                if ($unpublish_limit != null && $unpublish_limit >= 0 && ($difference > $unpublish_limit)) {
                    $post_status = 'draft';
                }
            }
        }

        // Save event if it passed taxonomy and group filters
        if ($pass_tax_filter) {
            try {
                $event = new Event(
                    array(
                        'post_title' => $post_title,
                        'post_content' => $post_content,
                        'post_status' => $post_status,
                    ),
                    array(
                        '_event_manager_id' => $event['id'],
                        'categories' => $categories,
                        'tags' => $tags,
                        'groups' => $groups,
                        'occasions_complete' => $occasions,
                        'event_link' => $event_link,
                        'additional_links' => $additional_links,
                        'related_events' => $related_events,
                        'location' => $location,
                        'latitude' => $latitude,
                        'longitude' => $longitude,
                        'additional_locations' => $additional_locations,
                        'organizers' => $organizers,
                        'supporters' => $supporters,
                        'booking_link' => $booking_link,
                        'booking_phone' => $booking_phone,
                        'booking_email' => $booking_email,
                        'age_restriction' => $age_restriction,
                        'membership_cards' => $membership_cards,
                        'price_information' => $price_information,
                        'ticket_includes' => $ticket_includes,
                        'price_adult' => $price_adult,
                        'price_children' => $price_children,
                        'children_age' => $children_age,
                        'price_student' => $price_student,
                        'price_senior' => $price_senior,
                        'senior_age' => $senior_age,
                        'booking_group' => $booking_group,
                        'gallery' => $gallery,
                        'facebook' => $facebook,
                        'twitter' => $twitter,
                        'instagram' => $instagram,
                        'google_music' => $google_music,
                        'spotify' => $spotify,
                        'soundcloud' => $soundcloud,
                        'deezer' => $deezer,
                        'youtube' => $youtube,
                        'vimeo' => $vimeo,
                        'last_update' => $last_update,
                        'ticket_stock' => $ticket_stock,
                        'tickets_remaining' => $tickets_remaining,
                        'additional_ticket_retailers' => $additional_ticket_retailers,
                        'additional_ticket_types' => $additional_ticket_types,
                        'price_range' => $price_range,
                        'ticket_release_date' => $ticket_release_date,
                        'contact_email' => $contact_email,
                        'contact_phone' => $contact_phone,
                        'contact_information' => $contact_information,
                        'age_group_from' => $age_group_from,
                        'age_group_to' => $age_group_to,
                        'accessibility' => $accessibility,
                        'lang' => $lang,
                        'translations' => $translations
                    )
                );
            } catch (\Exception $e) {
                error_log(print_r($e, true));
                return;
            }
            $createSuccess = $event->save();

            if ($createSuccess && !empty($featured_media)) {
                $event->setFeaturedImageFromUrl($featured_media, true);
            }
        }
    }
Save event to database
@param  object $event Event data
@return void
@throws \Exception