.
*/
namespace App\DataTables\Helpers;
use App\Entity\Attachments\Attachment;
use App\Entity\ProjectSystem\Project;
use App\Services\Attachments\AttachmentURLGenerator;
use App\Services\Attachments\ProjectPreviewGenerator;
use App\Services\EntityURLGenerator;
/**
* A helper service which contains common code to render columns for project related tables
*/
class ProjectDataTableHelper
{
public function __construct(
private readonly EntityURLGenerator $entityURLGenerator,
private readonly ProjectPreviewGenerator $previewGenerator,
private readonly AttachmentURLGenerator $attachmentURLGenerator
) {
}
public function renderName(Project $context): string
{
return sprintf(
'%s',
$this->entityURLGenerator->infoURL($context),
htmlspecialchars($context->getName())
);
}
public function renderPicture(Project $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(
'
',
'Project image',
$this->attachmentURLGenerator->getThumbnailURL($preview_attachment),
$this->attachmentURLGenerator->getThumbnailURL($preview_attachment, 'thumbnail_md'),
'hoverpic project-table-image',
$title
);
}
}