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; }
public function addNewMovieAction() { // action body $movie = new Movie(); $movieRepo = MyEntityManagerFactory::getEntityManager()->getRepository('\\Models\\Entities\\Movie'); //$type->setTypeName($this->getRequest()->getPost('type')); $movie->setMovieName($this->getRequest()->getPost('movieName')); $movie->setFriendlyName($this->getRequest()->getPost('friendlyName')); $movie->setDescription($this->getRequest()->getPost('description')); $category = MyEntityManagerFactory::getEntityManager()->getRepository('\\Models\\Entities\\Category')->find($this->getRequest()->getPost('category')); $movie->setCategory($category); $realUrl = $this->getRequest()->getPost('realUrl'); $movie->setIsProcessUrl(true); $movie->setRealUrl($realUrl); // $movie->setProcessedUrl(serialize($vids)); $currentDate = new DateTime(); $movie->setCreatedDate($currentDate); $movie->setUpdatedDate($currentDate); $movie->setIsActive(true); $movie->setCoverUrl($this->getRequest()->getPost('cover')); $movie->setScreenShotUrl($this->getRequest()->getPost('screenShot')); $movieRepo->save($movie); $url = '/manage/movies'; $this->redirect($url); //$this->forward("servers","manage"); }