/**
  * Implement this method in the task subclass to
  * execute via the TaskRunner
  */
 public function run($request)
 {
     set_time_limit(0);
     $summit_id = intval($request->getVar('summit_id'));
     if (empty($summit_id)) {
         throw new InvalidArgumentException('missing summit_id param!');
     }
     $client = new GuzzleHttp\Client();
     $query = array('api_key' => SCHED_API_KEY, 'format' => 'json');
     $response = $client->get("http://openstacksummitoctober2015tokyo.sched.org/api/session/list", array('query' => $query));
     if ($response->getStatusCode() !== 200) {
         throw new Exception('invalid status code!');
     }
     $content_type = $response->getHeader('content-type');
     if (empty($content_type)) {
         throw new Exception('invalid content type!');
     }
     if ($content_type !== 'application/json') {
         throw new Exception('invalid content type!');
     }
     $summit = Summit::get()->byID($summit_id);
     if (is_null($summit)) {
         throw new InvalidArgumentException('missing summit_id param!');
     }
     $json = $response->getBody()->getContents();
     $events = json_decode($json, true);
     foreach ($events as $sched_event) {
         try {
             if ($sched_event["active"] !== "Y") {
                 continue;
             }
             $title = $sched_event["name"];
             $start_date = $sched_event["event_start"];
             $end_date = $sched_event["event_end"];
             $event_type = isset($sched_event["event_type"]) ? $sched_event["event_type"] : $title;
             $venue = $sched_event["venue"];
             $event = SummitEvent::get()->filter(array("SummitID" => $summit_id, "Title" => trim($title), "StartDate" => $summit->convertDateFromTimeZone2UTC($start_date), "EndDate" => $summit->convertDateFromTimeZone2UTC($end_date)))->first();
             if (is_null($event)) {
                 $event = SummitEvent::get()->filter(array("SummitID" => $summit_id, "Title" => trim($title)))->first();
             }
             $location = SummitVenueRoom::get()->filter(array("SummitID" => $summit_id, "Name" => trim($venue)))->first();
             if (is_null($location) && $venue !== 'TBA') {
                 // create location
                 $main_venue = SummitVenue::get()->filter(array("SummitID" => $summit_id))->first();
                 $location = new SummitVenueRoom();
                 $location->SummitID = $summit_id;
                 $location->Name = trim($venue);
                 $location->VenueID = $main_venue->ID;
                 $location->write();
             }
             if (is_null($event)) {
                 // create event and event type ...
                 if (isset($sched_event['speakers'])) {
                     continue;
                 }
                 $type = SummitEventType::get()->filter(array("SummitID" => $summit_id, "Type" => trim($event_type)))->first();
                 if (is_null($type)) {
                     $type = new SummitEventType();
                     $type->SummitID = $summit_id;
                     $type->Type = trim($event_type);
                     $type->write();
                 }
                 $event = new SummitEvent();
                 $event->TypeID = $type->ID;
                 $event->SummitID = $summit_id;
                 $event->Title = trim($title);
                 $event->write();
             }
             $event->StartDate = $start_date;
             $event->EndDate = $end_date;
             if (!is_null($location)) {
                 $event->LocationID = $location->ID;
             }
             $event->write();
             if ($event->isPublished()) {
                 continue;
             }
             $event_id = $event->ID;
             if (intval($event->AllowedSummitTypes()->count()) === 0) {
                 DB::query("INSERT INTO SummitEvent_AllowedSummitTypes\n(SummitEventID, SummitTypeID)\nSELECT SummitEvent.ID, SummitType.ID FROM SummitEvent, SummitType WHERE SummitEvent.ID = {$event_id} ;\n");
             }
             $event->publish();
             $event->write();
         } catch (ValidationException $ex) {
             SS_Log::log($ex->getMessage(), SS_Log::ERR);
         }
     }
 }
Example #2
0
 /**
  * @return ISummitVenue
  */
 public function getMainVenue()
 {
     return SummitVenue::get()->filter(array('SummitID' => $this->ID, 'IsMain' => true))->first();
 }
 public function thereIsSummitSessionOnHotel($hotel_id)
 {
     $summit = $this->Summit()->ID > 0 ? $this->Summit() : $this->CurrentSummit();
     $hotel = SummitHotel::get()->byID(intval($hotel_id));
     if (is_null($hotel)) {
         return false;
     }
     $venue = SummitVenue::get()->filter(array('SummitID' => $summit->ID, 'Name' => $hotel->Name))->first();
     return !is_null($venue);
 }