/**
  * @param Theatre $theatre
  * @return bool|mixed|\mysqli_result
  */
 public static function setTheatreLatLng(Theatre $theatre)
 {
     //51.4752267,-0.2396438
     \SystemLogger::info("Finding LongLat for: ", $theatre->name, $theatre->address);
     $geocode = LocationService::instance()->addressLookup($theatre->address, [], true);
     $saved = false;
     if ($geocode) {
         $geoLocation = $geocode->getGeocode();
         \SystemLogger::info("Found Geocode: ", strval($geoLocation));
         $saved = $theatre->update(['longitude' => $geoLocation->getLongitude(), 'latitude' => $geoLocation->getLatitude()], 'id');
     }
     return $saved;
 }
 protected function initRelations()
 {
     $this->setManyToOne('theatre', Theatre::manager());
 }
 public function getTheatres(GeocodeCached $locationInfo, $currentDate = null, $movie_id = null, $includeShowtimes = null, $includeMovieIds = false, $dateOffset = 0, &$theatreFields = [])
 {
     if (!$this->loadData($locationInfo, $currentDate, false, $dateOffset)) {
         return [];
     }
     $currentDate = Utilities::dateFromOffset($currentDate, $dateOffset);
     $where = $locationInfo->getQueryWhere()->where('s.show_date', $currentDate)->setOrderBy('distance_m', 'ASC')->setGroupBy('t.id');
     if ($movie_id) {
         $where->where('s.movie_id', $movie_id);
     }
     $ids = Theatre::table()->selectFrom('t.id', 't')->innerJoin(['tn' => TheatreNearby::table()], 't.id = tn.theatre_id', ['tn.distance_m'])->innerJoin(['s' => Showtime::table()], 's.theatre_id = t.id', [new \DbTableFunction("GROUP_CONCAT(DISTINCT s.movie_id) AS movies")])->where($where)->query();
     $theatres = [];
     $theatreFields = ['id', 'name', 'address', 'distance_m'];
     foreach ($ids as $idRow) {
         $theatre = $this->theatreManager->getEntity($idRow['id']);
         /* @var $theatre Theatre */
         if ($theatre) {
             $theatreArr = $theatre->toArray(Theatre::TO_ARRAY_MVA, 1, $theatreFields);
             $theatreArr['distance_m'] = $idRow['distance_m'];
             if ($includeShowtimes) {
                 $theatreArr['showtimes'] = [];
                 $showtimes = $theatre->getShowtimes($movie_id, $currentDate);
                 foreach ($showtimes as $showtime) {
                     $theatreArr['showtimes'][] = $showtime->toArray(0, 1, ['id', 'show_time', 'show_date', 'url', 'type']);
                 }
             }
             if ($includeMovieIds) {
                 $theatreArr['movies'] = explode(",", $idRow['movies']);
             }
             $theatres[] = ProxyMode::isCompact() ? $this->compactTheatre($theatreArr) : $theatreArr;
         }
     }
     if ($includeShowtimes) {
         $theatreFields[] = 'showtimes';
     }
     if ($includeMovieIds) {
         $theatreFields[] = 'movies';
     }
     $this->_filterObject($theatres);
     return $theatres;
 }