public static function getOrCreate(GeocodeCached $locationInfo, Theatre $theatre, $computeDistance = false) { $where = $locationInfo->getQueryWhere()->where('theatre_id', $theatre->id); $manager = static::manager(); $nearby = $manager->getEntityWhere($where); if ($nearby) { return $nearby; } $data = $locationInfo->toArray(0, 2, array('country_iso', 'postal_code', 'country', 'city')); $data['distance_m'] = $computeDistance ? LocationService::instance()->computeDistance($locationInfo->getGeocode(), $theatre->getGeocode()) : -1; $data['theatre_id'] = $theatre->id; $nearbyId = $manager->createEntity($data)->save(); return $nearbyId ? $manager->getEntity($nearbyId) : null; }
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; }