Example #1
0
 public function jsonEventsToGEventObjects($jsonObject)
 {
     $json = json_decode($jsonObject);
     /**
      * Loop through each event in the json array
      * and create a gEvent object and add to our
      * array to return back to caller.
      * @var array
      */
     $gEvents = array();
     foreach ($json as $event) {
         $gEvent = new gEvent();
         $gEvent->setInternal_Id($event->internal_Id);
         $gEvent->setExternal_Id($event->external_id);
         $gEvent->setDatasource($event->datasource);
         $gEvent->setEvent_external_url($event->event_external_url);
         $gEvent->setTitle($event->title);
         $gEvent->setDescription($event->description);
         $gEvent->setNotes($event->notes);
         $gEvent->setTimezone($event->timezone);
         $gEvent->setTimezone_abbr($event->timezone_abbr);
         $gEvent->setStart_time($event->start_time);
         $gEvent->setEnd_time($event->end_time);
         $gEvent->setStart_date_month($event->start_date_month);
         $gEvent->setStart_date_day($event->start_date_day);
         $gEvent->setStart_date_year($event->start_date_year);
         $gEvent->setStart_date_time($event->start_date_time);
         $gEvent->setEnd_date_month($event->end_date_month);
         $gEvent->setEnd_date_day($event->end_date_day);
         $gEvent->setEnd_date_year($event->end_date_year);
         $gEvent->setEnd_date_time($event->end_date_time);
         $gEvent->setVenue_external_id($event->venue_external_id);
         $gEvent->setVenue_external_url($event->venue_external_url);
         $gEvent->setVenue_name($event->venue_external_name);
         $gEvent->setVenue_display($event->venue_display);
         $gEvent->setVenue_address($event->venue_address);
         $gEvent->setState_name($event->state_name);
         $gEvent->setCity_name($event->city_name);
         $gEvent->setPostal_code($event->postal_code);
         $gEvent->setCountry_name($event->country_name);
         $gEvent->setAll_day($event->all_day);
         $gEvent->setPrice_range($event->price_range);
         $gEvent->setIs_free($event->is_free);
         $gEvent->setMajor_genre($event->major_genre);
         $gEvent->setMinor_genre($event->minor_genre);
         $gEvent->setLatitude($event->latitude);
         $gEvent->setLongitude($event->longitude);
         $performersArr = array();
         foreach ($event->performers as $performer) {
             $gEventPerformer = new gEventPerformer();
             $gEventPerformer->setPerformer_name($performer->name);
             $gEventPerformer->setPerformer_external_id($performer->external_id);
             $gEventPerformer->setPerformer_external_url($performer->external_url);
             $gEventPerformer->setPerformer_short_bio($performer->short_bio);
             $gEventPerformer->setPerformer_external_image_url($performer->external_image_url);
             array_push($performersArr, $gEventPerformer);
         }
         $gEvent->setPerformers($performersArr);
         $imagesArr = array();
         foreach ($event->images as $image) {
             $gEventImage = new gEventImage();
             $gEventImage->setImage_category($image->image_category);
             $gEventImage->setImage_height($image->image_height);
             $gEventImage->setImage_width($image->image_width);
             $gEventImage->setImage_external_url($image->image_external_url);
             array_push($imagesArr, $gEventImage);
         }
         $gEvent->setImages($imagesArr);
         // push event object onto event array stack
         array_push($gEvents, $gEvent);
     }
     return $gEvents;
 }
Example #2
0
function eventfulAPI_findEvents($queryString, $optionsArray)
{
    $app_key = 'NzRqz6hgC5t3ZR8B';
    // Filter Parameters
    $q = urlencode(strtolower($queryString));
    $userLat = $optionsArray['userLat'];
    $userLong = $optionsArray['userLng'];
    $filterCity = $optionsArray['city'];
    $filterState = $optionsArray['state'];
    $filterDate = $optionsArray['date'];
    $filterRadius = $optionsArray['radius'];
    if ($q == $filterCity) {
        $q == null;
    }
    // Just do a simple lookup
    $ev_noauth = new Services_Eventful($app_key);
    $args = array('keywords' => "{$q}", 'location' => "{$filterCity}, {$filterState}", 'within' => "{$filterRadius}", 'units' => "mi", 'sort_order' => "date", 'page_size' => 100);
    $data = $ev_noauth->call('events/search', $args, "json");
    $num = $data['page_size'];
    $gEvents = array();
    $i = 0;
    // Loop through Json Results from CURL resuest
    while ($i < $num) {
        $externalId = empty($data['events']['event'][$i]['id']) ? null : $data['events']['event'][$i]['id'];
        $city = empty($data['events']['event'][$i]['city_name']) ? null : $data['events']['event'][$i]['city_name'];
        $state = empty($data['events']['event'][$i]['region_abbr']) ? null : $data['events']['event'][$i]['region_abbr'];
        $date = empty($data['events']['event'][$i]['start_time']) ? null : $data['events']['event'][$i]['start_time'];
        $desc = empty($data['events']['event'][$i]['description']) ? null : $data['events']['event'][$i]['description'];
        $title = empty($data['events']['event'][$i]['title']) ? null : $data['events']['event'][$i]['title'];
        $venueExternalId = empty($data['events']['event'][$i]['venue_id']) ? null : $data['events']['event'][$i]['venue_id'];
        $venueName = empty($data['events']['event'][$i]['venue_name']) ? null : $data['events']['event'][$i]['venue_name'];
        $venueAddress = empty($data['events']['event'][$i]['venue_address']) ? null : $data['events']['event'][$i]['venue_address'];
        $country = empty($data['events']['event'][$i]['country_abbr']) ? null : $data['events']['event'][$i]['country_abbr'];
        $postalCode = empty($data['events']['event'][$i]['postal_code']) ? null : $data['events']['event'][$i]['postal_code'];
        $defaultDomain = empty($data['events']['event'][$i]['default_domain']) ? "http://eventful.com" : $data['events']['event'][$i]['default_domain'];
        $venueExternalUrl = empty($data['events']['event'][$i]['venue_url']) ? null : $data['events']['event'][$i]['venue_url'];
        $latitude = empty($data['events']['event'][$i]['latitude']) ? null : $data['events']['event'][$i]['latitude'];
        $longitude = empty($data['events']['event'][$i]['longitude']) ? null : $data['events']['event'][$i]['longitude'];
        $timezone = empty($data['events']['event'][$i]['olson_path']) ? null : $data['events']['event'][$i]['olson_path'];
        $startTime = empty($data['events']['event'][$i]['start_time']) ? null : $data['events']['event'][$i]['start_time'];
        $endTime = empty($data['events']['event'][$i]['stop_time']) ? null : $data['events']['event'][$i]['stop_time'];
        $minPrice = null;
        $maxPrice = null;
        $channel = null;
        $eventExternalUrl = empty($data['events']['event'][$i]['url']) ? null : $data['events']['event'][$i]['url'];
        $imageExternalUrl = empty($data['events']['event'][$i]['image']) ? null : $data['events']['event'][$i]['image'];
        $geoParent = empty($data['events']['event'][$i]['geocode_type']) ? null : $data['events']['event'][$i]['geocode_type'];
        $currentEvent = true;
        if (!empty($startTime)) {
            date_default_timezone_set($timezone);
            $currentUnixTime = strtotime("now");
            $eventUnixTime = strtotime($startTime);
            $currentEvent = $currentUnixTime > $eventUnixTime ? false : true;
        }
        if (null != $latitude && null != $longitude && null != $userLat && null != $userLong) {
            $distance = distanceInMiles($userLat, $userLong, $latitude, $longitude);
        } else {
            $distance = null;
        }
        if (!empty($externalId) && $currentEvent) {
            if (empty($filterRadius) || $distance <= $filterRadius && $distance > 0) {
                $gEvent = new gEvent();
                $gEvent->setExternal_id($externalId);
                $gEvent->setDatasource("eventful");
                $gEvent->setTitle($title);
                $gEvent->setDescription($title);
                $gEvent->setNotes($desc);
                $gEvent->setVenue_external_id($venueExternalId);
                $gEvent->setVenue_name($venueName);
                $gEvent->setVenue_address($venueAddress);
                $gEvent->setCountry_name($country);
                $gEvent->setState_name($state);
                $gEvent->setCity_name($city);
                $gEvent->setPostal_code($postalCode);
                $gEvent->setVenue_external_url($venueExternalUrl);
                $gEvent->setLatitude($latitude);
                $gEvent->setLongitude($longitude);
                $gEvent->setDistance(number_format((double) $distance, 2, '.', ''));
                $gEvent->setTimezone($timezone);
                $gEvent->setTimezone_abbr(convertTimezoneToAbbr($timezone));
                $gEvent->setStart_time($startTime);
                $gEvent->setEnd_time($endTime);
                $gEvent->setStart_date_month(convertDateToMonthOptions($startTime));
                $gEvent->setStart_date_day(convertDateToDayOptions($startTime, $timezone));
                $gEvent->setStart_date_year(convertDateToYearOptions($startTime));
                $gEvent->setStart_date_time(convertDateToTimeOptions($startTime));
                $gEvent->setPrice_range($minPrice . " - " . $maxPrice);
                if (substr($gEvent->getPrice_range(), 0, 2) === "0 ") {
                    $gEvent->setIs_free(true);
                } else {
                    if ($gEvent->getPrice_range() !== null) {
                        $gEvent->setIs_free(false);
                    }
                }
                $minorGenre = array();
                $majorGenre = array();
                $gEvent->setMinor_genre($minorGenre);
                $gEvent->setMajor_genre($majorGenre);
                $gEvent->setEvent_external_url($eventExternalUrl);
                // Populate image links found
                $gEventImages = array();
                if (isset($imageExternalUrl)) {
                    $image = $data['events']['event'][$i]['image']['medium'];
                    //var_dump($image);
                    //if(!empty($image['medium'])){
                    $gImage = new gEventImage();
                    $gImage->setImage_external_url($image['url']);
                    $gImage->setImage_height($image['height']);
                    $gImage->setImage_width($image['width']);
                    $gImage->setImage_category("attraction");
                    array_push($gEventImages, $gImage);
                    //}
                } else {
                    $gImage = new gEventImage();
                    $searchImageQuery = explode("[", $desc);
                    $searchImageQuery = explode("-", $searchImageQuery[0]);
                    $searchImageQuery = urlencode($searchImageQuery[0]);
                    $searchImageUrl = "https://ajax.googleapis.com/ajax/services/search/images?v=1.0&q={$searchImageQuery}";
                    $googleImageUrl = googleImageSearch($searchImageUrl);
                    $gImage->setImage_external_url($googleImageUrl);
                    //$gImage->setImage_external_url("https://cdn4.iconfinder.com/data/icons/small-n-flat/24/calendar-128.png");
                    $gImage->setImage_category("attraction");
                    array_push($gEventImages, $gImage);
                }
                $gEvent->setImages($gEventImages);
                //Populate performers found
                $gEventPerformers = array();
                if (isset($data['events']['event'][$i]['performers']['performer'])) {
                    foreach ($data['events']['event'][$i]['performers']['performer'] as $performer) {
                        if (isset($performer) && isset($performer['id'])) {
                            $gPerformer = new gEventPerformer();
                            $gPerformer->setPerformer_external_id($performer['id']);
                            $gPerformer->setPerformer_name($performer['name']);
                            $gPerformer->setPerformer_external_url($performer['url']);
                            $gPerformer->setPerformer_short_bio($performer['short_bio']);
                            array_push($gEventPerformers, $gPerformer);
                        }
                    }
                }
                $gEvent->setPerformers($gEventPerformers);
                // Push gEvent object onto arraylist of gEvent objects
                array_push($gEvents, $gEvent);
            }
        }
        $i++;
    }
    return $gEvents;
}