src/Controller/MovieDataController.php line 97

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Pimcore\Controller\FrontendController;
  4. use Symfony\Component\HttpFoundation\Request;
  5. use Symfony\Component\HttpFoundation\Response;
  6. use Symfony\Component\Routing\Annotation\Route;
  7. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  8. use Knp\Component\Pager\PaginatorInterface;
  9. use Pimcore\Model\DataObject\Movies;
  10. use Pimcore\Model\DataObject\Movies\Listing;
  11. use App\Model\Movie;
  12. use Pimcore\Twig\Extension\Templating\HeadTitle;
  13. use Pimcore\Twig\Extension\Templating\Placeholder;
  14. use FFI\Exception;
  15. class MovieDataController extends FrontendController
  16. {
  17.     public static $perPage 60;
  18.     /**
  19.      * @Template
  20.      */
  21.     public function defaultAction(Request $request)
  22.     {
  23.         return [];
  24.     }
  25.     /**
  26.      * @param Request $request
  27.      *
  28.      * @return Response
  29.      *
  30.      * @throws \Exception
  31.      */
  32.     public function movieDataAction(Request $requestPaginatorInterface $paginator$searchTerm "")
  33.     {
  34.         // get a list of Movies objects and order them by date
  35.         $movieList = new Movies\Listing();
  36.         $movieList->setOrderKey('title');
  37.         $movieList->setOrder('ASC');
  38.         $movieList->setLocale("de");
  39.         if($searchTerm)
  40.             $movieList->setCondition("title LIKE ?", ["%".$searchTerm."%"]);
  41.         $paginator $paginator->paginate(
  42.             $movieList,
  43.             $request->get('page'1),
  44.             self::$perPage
  45.         );
  46.         $fallbackImage \Pimcore\Model\Asset::getById(414);
  47.         return $this->render('movie/movies.html.twig', [
  48.             'movies' => $movieList,
  49.             'paginationVariables' => $paginator->getPaginationData(),
  50.             'fallbackImage' => $fallbackImage,
  51.             'searchTerm' => $searchTerm
  52.         ]);
  53.         // $this->render('movie/movies.html.twig');
  54.     }
  55.     #[Route('/import-image/{id}')]
  56.     public function movieImportAction(Request $request): Response
  57.     {
  58.         try
  59.         {
  60.         $id $request->get('id');
  61.         $object Movies::getById($id) == null ? throw new Exception() : Movies::getByID($id)->getTitle("de");
  62.         $object == null ? throw new Exception() : 0;        
  63.         }
  64.         catch(Exception $e)
  65.         {
  66.             echo "This ID does not exist or could not be found";
  67.             return new Response();
  68.         }
  69.         
  70.         $movie = new Movie();
  71.         $movieList = new Listing();
  72.         Movie::$DebugMode true;
  73.         $movieList->setCondition("oo_id LIKE ?", ["%".$id."%"]);
  74.         $movie->getMovieInformationPerLanguage($movieList'de-DE');
  75.         $movie->getMovieInformationPerLanguage($movieList'en-EN');   
  76.         Movie::$DebugMode false;         
  77.         return $this->render('simple-page/importInfo.twig',[
  78.                 'title' => $object
  79.     ]);
  80.     }
  81.     #[Route('/movie-detail/{id}')]
  82.     public function movieDetailAction(Request $request): Response
  83.     {
  84.         $id $request->get('id');
  85.         $movie Movies::getById($id);
  86.         $actors $movie->getActors();
  87.         $similarMovies $this->getSimilarMovies($movie);
  88.         
  89.         return $this->render('movie/movies-detail.html.twig',
  90.         [
  91.             'movie' => $movie,
  92.             'actors' => $actors,
  93.             'similarmovies' => $similarMovies
  94.         ]);
  95.     }   
  96.     public function getSimilarMovies(Movies $movie)
  97.     {
  98.         $movieList = new Movies\Listing();
  99.         $movieList->setOrderKey("RAND()",false);
  100.         $movieList->setOrder('ASC');
  101.         $movieList->setLocale("de");
  102.         $movieList->setCondition("genre LIKE ?", ["%".$movie->getGenre()."%"]);
  103.         $movieList->setCondition("oo_id != ?", ["%".$movie->getId()."%"]);
  104.         $movieList->setLimit(8);
  105.         return $movieList;
  106.     }
  107. }