diff --git a/src/Controller/CapsuleController.php b/src/Controller/CapsuleController.php index 59797db643231b7efc74416817fa59cb315e3e26..dbf0c440a63e0778bbef6ccd949dd8609eb4f226 100644 --- a/src/Controller/CapsuleController.php +++ b/src/Controller/CapsuleController.php @@ -10,7 +10,6 @@ use App\Helper\StringHelper; use App\Repository\CapsuleRepository; use App\Builder\CapsuleBuilder; use App\Form\CreateCapsuleFormType; -use App\Retriever\ProjectRetriever; use Knp\Component\Pager\PaginatorInterface; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\Filesystem\Filesystem; @@ -110,31 +109,6 @@ class CapsuleController extends AbstractController ); } - /** - * @Route("capsule/{capsule_id}/video_preview", name="video_preview") - */ - public function videoPreview(int $capsule_id): Response - { - chdir('../legacy/'); - $file_system = new Filesystem(); - $capsule = $this->capsule_repository->findOneBy(['id' => $capsule_id]); - - if (! $capsule instanceof Capsule) { - throw new \Exception('The retrieved capsule is not an instance of Capsule.'); - } - - if (! $file_system->exists($capsule->getLinkPath())) { - return $this->render('project/project_not_found.html.twig'); - } - - $video_preview_image_link = $this->getVideoPreviewImageLink($capsule); - - return $this->render( - 'project/project_preview.html.twig', - ['video_preview_url' => $video_preview_image_link] - ); - } - /** * @Route("capsule/edit/{path}", name="edit_capsule") */ @@ -148,12 +122,12 @@ class CapsuleController extends AbstractController $capsule = $this->capsule_repository->findOneBy(['link_path' => $path]); if (null === $capsule) { - $this->addFlash('warning', $translator->trans('capsule.edit.not_found')); + $this->addFlash('warning', $this->translator->trans('capsule.edit.not_found')); return $this->redirectToRoute('capsule_list'); } if (! $capsule->getEditors()->contains($current_user)) { - $this->addFlash('warning', $translator->trans('capsule.edit.not_allowed')); + $this->addFlash('warning', $this->translator->trans('capsule.edit.not_allowed')); return $this->redirectToRoute('capsule_list'); } @@ -327,17 +301,4 @@ class CapsuleController extends AbstractController return $capsule; } - - private function getVideoPreviewImageLink(Capsule $capsule): string - { - $project_retriever = new ProjectRetriever($capsule); - $video_url = $project_retriever->getVideoUrl(); - $video_id = $project_retriever->getVideoId($video_url); - - if (strpos($video_url, 'yout') !== false) { - return 'https://img.youtube.com/vi/' . $video_id . '/maxresdefault.jpg'; - } - - return 'https://vumbnail.com/' . $video_id . '.jpg'; - } } diff --git a/src/Entity/Capsule.php b/src/Entity/Capsule.php index 28ecd46c74942f9c9dd35e5c1cb3fd405f59a64b..08ff123ce5e6625d0200dfc0cfdd0a2760e4d94f 100644 --- a/src/Entity/Capsule.php +++ b/src/Entity/Capsule.php @@ -211,4 +211,24 @@ class Capsule { return $this->editors; } + + + public function getVideoPreviewImageLink(): ?string + { + $file_system = new Filesystem(); + + if (! $file_system->exists('../legacy/' . $this->getLinkPath())) { + return null; + } + + $project_retriever = new ProjectRetriever($this); + $video_url = $project_retriever->getVideoUrl(); + $video_id = $project_retriever->getVideoId($video_url); + + if (strpos($video_url, 'yout') !== false) { + return 'https://img.youtube.com/vi/' . $video_id . '/maxresdefault.jpg'; + } + + return 'https://vumbnail.com/' . $video_id . '.jpg'; + } } diff --git a/templates/capsule/index.html.twig b/templates/capsule/index.html.twig index 23bb03df93fff5bc68fc3633e493489ce73b7b51..24c3d22ac50d87f75ee65a19e0f80327b8b69087 100644 --- a/templates/capsule/index.html.twig +++ b/templates/capsule/index.html.twig @@ -56,22 +56,13 @@ <div class="d-flex flex-column flex-md-row justify-content-center align-items-center"> <div class="m-4 ratio ratio-16x9"> -{# <img src="{{ capsule.getVideoPreviewImageLink() }}" alt="video preview">#} - {# <img src="/capsule/{{ capsule.getId() }}/video_preview" alt="video preview">#} + {% if capsule.getVideoPreviewImageLink() is null %} + <img src="{{ asset('build/images/project_not_found.jpg') }}" alt="video preview"> + {% else %} + <img src="{{ capsule.getVideoPreviewImageLink() }}" alt="video preview"> + {% endif %} </div> -{# {% if 'yout' in video_url %}#} -{# <img src="https://img.youtube.com/vi/{{ capsule.getVideoId() }}maxresdefault.jpg">#} -{# {% else %}#} -{# <img src="https://vumbnail.com/{{ capsule.getVideoId() }}.jpg">#} - {# <div class="m-4 ratio ratio-16x9">#} -{# <iframe#} -{# src="/capsule/preview/{{ capsule.getLinkPath() }}"#} -{# allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"#} -{# allowfullscreen>#} -{# </iframe>#} -{# </div>#} - <div class="d-flex flex-column justify-content-center m-2 pe-2"> <i class="fa-thin fa-gears"></i> diff --git a/templates/project/project_not_found.html.twig b/templates/project/project_not_found.html.twig index 0112bbe8103816565d42a611c18f10a6537a7ac0..05a7eba826a994468a07e77d0ead33934138e4c0 100644 --- a/templates/project/project_not_found.html.twig +++ b/templates/project/project_not_found.html.twig @@ -1,13 +1,13 @@ {% extends 'layout.html.twig' %} {% block title %} - {{ 'project.not_found'|trans }} + {{ 'project.not_exist'|trans }} - {{ parent() }} {% endblock %} {% block body %} <div class="col-10 col-md-8 col-lg-6 col-xl-5 col-xxl-6 m-auto d-flex flex-row align-items-center justify-content-center mb-5 alert alert-warning" role="status"> - <span class="p-5">{{ 'project.not_found' | trans }}</span> + <span class="p-5">{{ 'project.not_exist' | trans }}</span> </div> {% endblock %} \ No newline at end of file diff --git a/tests/functional/ProjectControllerTest.php b/tests/functional/ProjectControllerTest.php index 04168284371b13473a79b8586e269c4c3c1bcf16..7db3e685f9b301063081f5f4ad7000b24f91192f 100644 --- a/tests/functional/ProjectControllerTest.php +++ b/tests/functional/ProjectControllerTest.php @@ -86,7 +86,7 @@ class ProjectControllerTest extends WebTestCase $submit_button = $crawler->selectButton('Create a capsule'); $this->form = $submit_button->form(); - $video_url = "https://TestUrl"; + $video_url = "https://www.youtube.com/watch?v=dQw4w9WgXcQ&ab_channel=RickAstley"; $this->form['create_capsule_form[name]'] = self::CAPSULE_NAME; $this->form['create_capsule_form[video_url]'] = $video_url; @@ -123,7 +123,7 @@ class ProjectControllerTest extends WebTestCase $video_url_in_xml_file = $video_node->getAttribute('url'); - $this->assertEquals($video_url, $video_url_in_xml_file); + $this->assertEquals($video_url, htmlspecialchars_decode($video_url_in_xml_file)); $this->assertSame(self::CAPSULE_NAME, $capsule_name_in_db); } @@ -293,7 +293,7 @@ class ProjectControllerTest extends WebTestCase $submit_button = $crawler->selectButton('Create a capsule'); $this->form = $submit_button->form(); - $video_url = "https://TestUrl"; + $video_url = "https://www.youtube.com/watch?v=dQw4w9WgXcQ&ab_channel=RickAstley"; $this->form['create_capsule_form[name]'] = self::CAPSULE_NAME; $this->form['create_capsule_form[video_url]'] = $video_url;