コード例 #1
0
 /**
  * @param GeocodeCached $geocode Previously stored geoLocation information
  * @param string $currentDate date for showtimes to load, advisable to pass it in
  * @param int $dateOffset number of days from the current dates
  * @return TheatreData[] an array of schema TheatreData, see below for description
  *
  * Organized in the format =>
  *
  * ```
  *
  *  TheatreData : [
  *      'theatre' => [
  *              ...fields from theatre table, MUST contain name and address...,
  *      ]
  *      'movies' => MovieData[]
  *  ]
  *
  * MovieData : [
  *     'movie' => [
  *          ...fields from movie table, MUST contain title...,
  *     ]
  *     'showtimes' => ShowtimeData[]
  * ]
  *
  * ShowtimeData: [
  *      ...fields from showtime table, must conatin show_date, show_time & type...
  * ]
  * ```
  */
 public function loadShowtimes(GeocodeCached $geocode, $currentDate = null, $dateOffset = 0)
 {
     $params = ['country' => $geocode->country_iso, 'event_date' => \Utilities::dateFromOffset($currentDate ?: date('Y-m-d'), $dateOffset)];
     \SystemLogger::debug('Begining API Request to Tripican');
     $start = microtime(true);
     $allCinemaMovieShowtimes = TripicanDataLoader::GetCinemaMovieShowtimes($this->apiClient, $params);
     \SystemLogger::debug('Request to API completed in :', microtime(true) - $start);
     $theatres = [];
     foreach ($allCinemaMovieShowtimes as $cinemaMovieShowtimes) {
         $theatre = $cinemaMovieShowtimes['cinema'];
         $id = $theatre['id'];
         if (!isset($theatres[$id])) {
             $theatres[$id] = ['theatre' => ['name' => $theatre['centre_name'], 'address' => $this->_getAddress($theatre), 'longitude' => $theatre['place']['long'], 'latitude' => $theatre['place']['lat']], 'movies' => []];
         }
         $theatreData =& $theatres[$id];
         foreach ($cinemaMovieShowtimes['movie_showtimes'] as $movieShowtimes) {
             $movie = $movieShowtimes['movie'];
             $mId = $movie['id'];
             if (!isset($theatreData['movies'][$mId])) {
                 $theatreData['movies'][$mId] = ['movie' => ['title' => $movie['title'], 'genre' => $movie['genre'][0], 'user_rating' => isset($movie['imdb_rating']) ? floatval($movie['imdb_rating'][0] / 10.0) : null, 'poster_url' => $movie['poster'], 'rated' => $movie['rated'][0], 'runtime' => $movie['duration']], 'showtimes' => []];
             }
             $movieData =& $theatreData['movies'][$mId];
             foreach ($movieShowtimes['showtimes'] as $showtime) {
                 $movieData['showtimes'][] = ['show_date' => $showtime['event_date'], 'show_time' => $showtime['event_time'], 'type' => $this->_getMapType($showtime['type']), 'url' => $showtime['online_ticketing'] ? $showtime['url'] : null];
             }
         }
     }
     array_walk($theatres, function (&$t) {
         $t['movies'] = array_values($t['movies']);
     });
     if (!empty($theatres)) {
         $this->overrideDistanceCompute();
     }
     return array_values($theatres);
 }
コード例 #2
0
 public function loadShowtimes(GeocodeCached $geocode, $currentDate = null, $dateOffset = 0)
 {
     \SystemLogger::debug('SCRAPING started');
     $data = ['countryIso' => $geocode->country_iso, 'date' => \Utilities::dateFromOffset($currentDate ?: date('Y-m-d'), $dateOffset), 'postalCode' => urlencode($geocode->postal_code)];
     $pageData = $this->callUrl($this->formatUrl($this->urlTemplate, $data, true));
     //$pageData = file_get_contents(__DIR__ . DS . "showtimes.html");
     //file_put_contents("data_".microtime(true).".html", $pageData);
     $this->currentDate = $data['date'];
     return $this->extractShowtimes($pageData);
 }
コード例 #3
0
 public function loadShowtimes(GeocodeCached $geocode, $currentDate = null, $dateOffset = 0)
 {
     $this->currentDate = \Utilities::dateFromOffset($currentDate, $dateOffset);
     $allCinemasFound = array();
     for ($i = 0; $i < self::MAX_PAGES; $i++) {
         $data = array('latlng' => $geocode->getGeocode(), 'date' => $dateOffset, 'start' => $i * self::PER_PAGE);
         $url = $this->formatUrl($this->showtimesUrl, $data, true);
         $pageData = $this->callUrl($url);
         //test if hasNextPage===
         $totalFound = count($allCinemasFound);
         $totalPages = 0;
         $allCinemasFound = array_merge($allCinemasFound, $this->extractTheatreMovieShowtimes($pageData, ShowtimeService::THEATRE_LIMIT - $totalFound, $totalPages));
         \SystemLogger::info("Total pages: ", $totalPages);
         if ($i >= $totalPages - 1) {
             break;
         }
     }
     return $allCinemasFound;
 }