translator = $translator; $this->entityURLGenerator = $entityURLGenerator; $this->attachmentHelper = $attachmentHelper; $this->elementTypeNameGenerator = $elementTypeNameGenerator; } protected function getQuery(QueryBuilder $builder) { $builder->distinct()->select('attachment') ->addSelect('attachment_type') //->addSelect('element') ->from(Attachment::class, 'attachment') ->leftJoin('attachment.attachment_type', 'attachment_type'); //->leftJoin('attachment.element', 'element'); } /** * @param DataTable $dataTable * @param array $options */ public function configure(DataTable $dataTable, array $options) { $dataTable->add('picture', TextColumn::class, [ 'label' => '', 'render' => function ($value, Attachment $context) { if ($context->isPicture() && !$context->isExternal() && $this->attachmentHelper->isFileExisting($context)) { return sprintf( '%s', 'Part image', $this->entityURLGenerator->viewURL($context), 'img-fluid hoverpic' ); } return ''; } ]); $dataTable->add('name', TextColumn::class, [ 'label' => $this->translator->trans('attachment.edit.name'), 'render' => function ($value, Attachment $context) { //Link to external source if ($context->isExternal()) { return sprintf( '%s', htmlspecialchars($context->getURL()), htmlspecialchars($value) ); } if ($this->attachmentHelper->isFileExisting($context)) { return sprintf( '%s', $this->entityURLGenerator->viewURL($context), htmlspecialchars($value) ); } return $value; } ]); $dataTable->add('attachment_type', TextColumn::class, [ 'field' => 'attachment_type.name', 'render' => function ($value, Attachment $context) { return sprintf( '%s', $this->entityURLGenerator->editURL($context->getAttachmentType()), htmlspecialchars($value) ); } ]); $dataTable->add('element', TextColumn::class, [ 'label' => $this->translator->trans('attachment.table.element'), //'propertyPath' => 'element.name', 'render' => function ($value, Attachment $context) { return sprintf( '%s', $this->entityURLGenerator->infoURL($context->getElement()), $this->elementTypeNameGenerator->getTypeNameCombination($context->getElement(), true) ); } ]); $dataTable->add('filename', TextColumn::class, [ 'propertyPath' => 'filename' ]); $dataTable->add('filesize', TextColumn::class, [ 'render' => function ($value, Attachment $context) { if ($this->attachmentHelper->isFileExisting($context)) { return $this->attachmentHelper->getHumanFileSize($context); } if ($context->isExternal()) { return '' . $this->translator->trans('attachment.external') . ''; } return sprintf( ' %s ', $this->translator->trans('attachment.file_not_found') ); } ]); $dataTable ->add('addedDate', LocaleDateTimeColumn::class, [ 'label' => $this->translator->trans('part.table.addedDate'), 'visible' => false ]) ->add('lastModified', LocaleDateTimeColumn::class, [ 'label' => $this->translator->trans('part.table.lastModified'), 'visible' => false ]); $dataTable->add('show_in_table', BoolColumn::class, [ 'label' => $this->translator->trans('attachment.edit.show_in_table'), 'trueValue' => $this->translator->trans('true'), 'falseValue' => $this->translator->trans('false'), 'nullValue' => '', 'visible' => false ]); $dataTable->add('isPicture', BoolColumn::class, [ 'label' => $this->translator->trans('attachment.edit.isPicture'), 'trueValue' => $this->translator->trans('true'), 'falseValue' => $this->translator->trans('false'), 'nullValue' => '', 'visible' => false, 'propertyPath' => 'picture' ]); $dataTable->add('is3DModel', BoolColumn::class, [ 'label' => $this->translator->trans('attachment.edit.is3DModel'), 'trueValue' => $this->translator->trans('true'), 'falseValue' => $this->translator->trans('false'), 'nullValue' => '', 'visible' => false, 'propertyPath' => '3dmodel' ]); $dataTable->add('isBuiltin', BoolColumn::class, [ 'label' => $this->translator->trans('attachment.edit.isBuiltin'), 'trueValue' => $this->translator->trans('true'), 'falseValue' => $this->translator->trans('false'), 'nullValue' => '', 'visible' => false, 'propertyPath' => 'builtin' ]); $dataTable->createAdapter(ORMAdapter::class, [ 'entity' => Attachment::class, 'query' => function (QueryBuilder $builder) { $this->getQuery($builder); }, ]); } }