. */ namespace App\DataTables\Helpers; use App\Entity\ProjectSystem\Project; use App\Entity\Attachments\Attachment; use App\Entity\Parts\Part; use App\Services\Attachments\AttachmentURLGenerator; use App\Services\Attachments\PartPreviewGenerator; use App\Services\EntityURLGenerator; use Symfony\Contracts\Translation\TranslatorInterface; /** * A helper service which contains common code to render columns for part related tables */ class PartDataTableHelper { public function __construct(private readonly PartPreviewGenerator $previewGenerator, private readonly AttachmentURLGenerator $attachmentURLGenerator, private readonly EntityURLGenerator $entityURLGenerator, private readonly TranslatorInterface $translator) { } public function renderName(Part $context): string { $icon = ''; //Depending on the part status we show a different icon (the later conditions have higher priority) if ($context->isFavorite()) { $icon = sprintf('', $this->translator->trans('part.favorite.badge')); } if ($context->isNeedsReview()) { $icon = sprintf('', $this->translator->trans('part.needs_review.badge')); } if ($context->getBuiltProject() instanceof Project) { $icon = sprintf('', $this->translator->trans('part.info.projectBuildPart.hint') . ': ' . $context->getBuiltProject()->getName()); } return sprintf( '%s%s', $this->entityURLGenerator->infoURL($context), $icon, htmlspecialchars($context->getName()) ); } public function renderPicture(Part $context): string { $preview_attachment = $this->previewGenerator->getTablePreviewAttachment($context); if (!$preview_attachment instanceof Attachment) { return ''; } $title = htmlspecialchars($preview_attachment->getName()); if ($preview_attachment->getFilename()) { $title .= ' ('.htmlspecialchars($preview_attachment->getFilename()).')'; } return sprintf( '%s', 'Part image', $this->attachmentURLGenerator->getThumbnailURL($preview_attachment), $this->attachmentURLGenerator->getThumbnailURL($preview_attachment, 'thumbnail_md'), 'hoverpic part-table-image', $title ); } }