<?php
namespace App\Controller;
use Pimcore\Controller\FrontendController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Knp\Component\Pager\PaginatorInterface;
use Pimcore\Model\DataObject\Movies;
use Pimcore\Model\DataObject\Movies\Listing;
use App\Model\Movie;
use Pimcore\Twig\Extension\Templating\HeadTitle;
use Pimcore\Twig\Extension\Templating\Placeholder;
use FFI\Exception;
class MovieDataController extends FrontendController
{
public static $perPage = 60;
/**
* @Template
*/
public function defaultAction(Request $request)
{
return [];
}
/**
* @param Request $request
*
* @return Response
*
* @throws \Exception
*/
public function movieDataAction(Request $request, PaginatorInterface $paginator, $searchTerm = "")
{
// get a list of Movies objects and order them by date
$movieList = new Movies\Listing();
$movieList->setOrderKey('title');
$movieList->setOrder('ASC');
$movieList->setLocale("de");
if($searchTerm)
$movieList->setCondition("title LIKE ?", ["%".$searchTerm."%"]);
$paginator = $paginator->paginate(
$movieList,
$request->get('page', 1),
self::$perPage
);
$fallbackImage = \Pimcore\Model\Asset::getById(414);
return $this->render('movie/movies.html.twig', [
'movies' => $movieList,
'paginationVariables' => $paginator->getPaginationData(),
'fallbackImage' => $fallbackImage,
'searchTerm' => $searchTerm
]);
// $this->render('movie/movies.html.twig');
}
#[Route('/import-image/{id}')]
public function movieImportAction(Request $request): Response
{
try
{
$id = $request->get('id');
$object = Movies::getById($id) == null ? throw new Exception() : Movies::getByID($id)->getTitle("de");
$object == null ? throw new Exception() : 0;
}
catch(Exception $e)
{
echo "This ID does not exist or could not be found";
return new Response();
}
$movie = new Movie();
$movieList = new Listing();
Movie::$DebugMode = true;
$movieList->setCondition("oo_id LIKE ?", ["%".$id."%"]);
$movie->getMovieInformationPerLanguage($movieList, 'de-DE');
$movie->getMovieInformationPerLanguage($movieList, 'en-EN');
Movie::$DebugMode = false;
return $this->render('simple-page/importInfo.twig',[
'title' => $object
]);
}
#[Route('/movie-detail/{id}')]
public function movieDetailAction(Request $request): Response
{
$id = $request->get('id');
$movie = Movies::getById($id);
$actors = $movie->getActors();
$similarMovies = $this->getSimilarMovies($movie);
return $this->render('movie/movies-detail.html.twig',
[
'movie' => $movie,
'actors' => $actors,
'similarmovies' => $similarMovies
]);
}
public function getSimilarMovies(Movies $movie)
{
$movieList = new Movies\Listing();
$movieList->setOrderKey("RAND()",false);
$movieList->setOrder('ASC');
$movieList->setLocale("de");
$movieList->setCondition("genre LIKE ?", ["%".$movie->getGenre()."%"]);
$movieList->setCondition("oo_id != ?", ["%".$movie->getId()."%"]);
$movieList->setLimit(8);
return $movieList;
}
}