コード例 #1
0
 /**
  * @param int $limit
  * @return int
  */
 public static function update($limit = 100)
 {
     \SystemLogger::setVerbose(true);
     \SystemLogger::info("Running location Update");
     $where = (new \DbTableWhere())->whereOrString('distance_m <= 0')->whereOrString('distance_m IS NULL')->setOrderBy('created_on')->setLimitAndOffset($limit);
     $theatreNearBys = TheatreNearby::manager()->getEntitiesWhere($where);
     \SystemLogger::info("Nearbys found for update = ", count($theatreNearBys));
     $locationService = LocationService::instance();
     $seenTheatres = [];
     $successful = 0;
     foreach ($theatreNearBys as $theatreNearBy) {
         //var_dump($theatreNearBy);exit;
         $theatre = $theatreNearBy->theatre;
         $success = false;
         \SystemLogger::info("Updating Nearby with ID ", $theatreNearBy->id, " PostalCode/ISO", $theatreNearBy->postal_code, "/", $theatreNearBy->country_iso, "Theatre:", $theatre->name, $theatre->address);
         /* @var $theatre Theatre */
         if ($theatre) {
             if (!($theatre->latitude && $theatre->longitude) && !in_array($theatre->id, $seenTheatres)) {
                 $seenTheatres[] = $theatre->id;
                 if ($theatre->address) {
                     self::setTheatreLatLng($theatre);
                 }
             }
             if ($theatre->address || $theatre->latitude && $theatre->longitude) {
                 $geocodeCached = self::getGeocodeCached($theatreNearBy);
                 if ($geocodeCached) {
                     $distance = $locationService->computeDistance($theatre->getGeocode(), $geocodeCached->getGeocode());
                     if ($distance >= 0) {
                         $success = $theatreNearBy->update(['distance_m' => max([$distance, 100])], 'id');
                         \SystemLogger::info("Distance computed as: ", $distance);
                     } else {
                         \SystemLogger::info("Distance could not be computed");
                     }
                 }
             }
         }
         if (!$success) {
             $theatreNearBy->update(['distance_m' => self::DISTANCE_FAILED], 'id');
         } else {
             $successful++;
         }
     }
     return $successful;
 }
コード例 #2
0
 protected function initRelations()
 {
     $this->setOneToMany('nearbys', TheatreNearby::manager(), 'distance_m')->setOneToMany('showtimes', Showtime::manager(), 'show_date DESC, show_time ASC');
 }
コード例 #3
0
 public function getMovies(GeocodeCached $locationInfo, $currentDate = null, $theatre_id = null, $includeShowtimes = false, $includeTheatreIds = false, $dateOffset = 0, &$movieFields = [])
 {
     if (!$this->loadData($locationInfo, $currentDate, false, $dateOffset)) {
         return [];
     }
     $currentDate = Utilities::dateFromOffset($currentDate, $dateOffset);
     $where = $locationInfo->getQueryWhere()->where('s.show_date', $currentDate);
     if ($theatre_id) {
         $where->where('s.theatre_id', $theatre_id);
     }
     $idsQuery = Movie::table()->selectFrom('m.id', 'm')->innerJoin(['s' => Showtime::table()], 's.movie_id = m.id')->innerJoin(['tn' => TheatreNearby::table()], 's.theatre_id = tn.theatre_id', [new \DbTableFunction("GROUP_CONCAT(DISTINCT tn.theatre_id ORDER BY distance_m ASC) as theatres")])->where($where->setGroupBy("m.id"))->query();
     $ids = [];
     $theatres = [];
     foreach ($idsQuery as $result) {
         $ids[] = $result['id'];
         $theatres[$result['id']] = explode(",", $result['theatres']);
     }
     $moviesWhere = \DbTableWhere::get()->whereInArray('id', $ids)->setOrderBy('title');
     $movieList = Movie::manager()->getEntitiesWhere($moviesWhere);
     $movies = [];
     $movieFields = ['id', 'title', 'genre', 'user_rating', 'rated', 'critic_rating', 'runtime'];
     Movie::setToArrayFields($movieFields);
     foreach ($movieList as $movieInList) {
         /* @var $movieInList Movie */
         $movie = $movieInList->toArray();
         //$this->_filterObject($movie);
         //add showtimes ?
         if ($includeShowtimes) {
             $movie['showtimes'] = [];
             foreach ($movieInList->getShowtimes($theatre_id, $currentDate) as $showtime) {
                 $movie['showtimes'][] = $showtime->toArray(0, 1, ['id', 'show_time', 'show_date', 'url', 'type']);
             }
         }
         if ($includeTheatreIds) {
             $movie['theatres'] = $theatres[$movieInList->id];
         }
         $movies[] = ProxyMode::isCompact() ? $this->compactMovie($movie) : $movie;
     }
     if ($includeTheatreIds) {
         $movieFields[] = 'theatres';
     }
     $this->_filterObject($movies);
     return $movies;
 }