diff --git a/public/img/part_placeholder.svg b/public/img/part_placeholder.svg new file mode 100644 index 00000000..9904975c --- /dev/null +++ b/public/img/part_placeholder.svg @@ -0,0 +1,22 @@ + + + + + + + diff --git a/src/Controller/PartController.php b/src/Controller/PartController.php index 217ca681..c1f77148 100644 --- a/src/Controller/PartController.php +++ b/src/Controller/PartController.php @@ -34,6 +34,7 @@ namespace App\Controller; use App\Entity\Part; +use App\Services\AttachmentFilenameService; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\Routing\Annotation\Route; @@ -44,14 +45,15 @@ class PartController extends AbstractController * @Route("/part/{id}/info", name="part_info") * @Route("/part/{id}") */ - function show(Part $part) + function show(Part $part, AttachmentFilenameService $attachmentFilenameService) { $filename = $part->getMasterPictureFilename(true); dump($filename); return $this->render('show_part_info.html.twig', [ - "part" => $part + "part" => $part, + "main_image" => $attachmentFilenameService->attachmentPathToAbsolutePath($filename) ] ); } diff --git a/src/Services/AttachmentFilenameService.php b/src/Services/AttachmentFilenameService.php new file mode 100644 index 00000000..5bb0199a --- /dev/null +++ b/src/Services/AttachmentFilenameService.php @@ -0,0 +1,59 @@ +package = $package; + } + + public function attachmentPathToAbsolutePath(?string $filename) : ?string + { + //Return placeholder if a part does not have an attachment + if ($filename == null) { + return $this->package->getUrl('/img/part_placeholder.svg'); + } + if (stripos($filename, "%BASE%/img/") !== false) { + return $this->package->getUrl(str_replace('%BASE%', '', $filename)); + } + + //If no other method works, return placeholder + return $this->package->getUrl('/img/part_placeholder.svg'); + } +} \ No newline at end of file diff --git a/templates/show_part_info.html.twig b/templates/show_part_info.html.twig index a367fd10..b01d2a67 100644 --- a/templates/show_part_info.html.twig +++ b/templates/show_part_info.html.twig @@ -19,7 +19,7 @@
- +
{{ part.manufacturer.name ?? ""}}