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; }