diff --git a/src/DataTables/Column/LogEntryTargetColumn.php b/src/DataTables/Column/LogEntryTargetColumn.php index c7ff1b54..705a512b 100644 --- a/src/DataTables/Column/LogEntryTargetColumn.php +++ b/src/DataTables/Column/LogEntryTargetColumn.php @@ -42,9 +42,13 @@ declare(strict_types=1); namespace App\DataTables\Column; +use App\Entity\Attachments\Attachment; use App\Entity\Base\AbstractDBElement; use App\Entity\Base\AbstractNamedDBElement; use App\Entity\LogSystem\AbstractLogEntry; +use App\Entity\Parameters\AbstractParameter; +use App\Entity\PriceInformations\Orderdetail; +use App\Entity\PriceInformations\Pricedetail; use App\Exceptions\EntityNotSupportedException; use App\Services\ElementTypeNameGenerator; use App\Services\EntityURLGenerator; @@ -80,6 +84,7 @@ class LogEntryTargetColumn extends AbstractColumn public function configureOptions(OptionsResolver $resolver) { parent::configureOptions($resolver); + $resolver->setDefault('show_associated', true); return $this; } @@ -89,31 +94,27 @@ class LogEntryTargetColumn extends AbstractColumn /** @var AbstractLogEntry $context */ $target = $this->entryRepository->getTargetElement($context); + $tmp = ''; + //The element is existing if ($target instanceof AbstractNamedDBElement) { try { - return sprintf( + $tmp = sprintf( '%s', $this->entityURLGenerator->infoURL($target), $this->elementTypeNameGenerator->getTypeNameCombination($target, true) ); } catch (EntityNotSupportedException $exception) { - return $this->elementTypeNameGenerator->getTypeNameCombination($target, true); + $tmp = $this->elementTypeNameGenerator->getTypeNameCombination($target, true); } - } - - //Target does not have a name - if ($target instanceof AbstractDBElement) { - return sprintf( + } elseif ($target instanceof AbstractDBElement) { //Target does not have a name + $tmp = sprintf( '%s: %s', $this->elementTypeNameGenerator->getLocalizedTypeLabel($target), $target->getID() ); - } - - //Element was deleted - if (null === $target && $context->hasTarget()) { - return sprintf( + } elseif (null === $target && $context->hasTarget()) { //Element was deleted + $tmp = sprintf( '%s: %s [%s]', $this->elementTypeNameGenerator->getLocalizedTypeLabel($context->getTargetClass()), $context->getTargetID(), @@ -121,7 +122,32 @@ class LogEntryTargetColumn extends AbstractColumn ); } + //Add a hint to the associated element if possible + if (null !== $target && $this->options['show_associated']) { + if ($target instanceof Attachment && $target->getElement() !== null) { + $on = $target->getElement(); + } elseif ($target instanceof AbstractParameter && $target->getElement() !== null) { + $on = $target->getElement(); + } elseif ($target instanceof Orderdetail && $target->getPart() !== null) { + $on = $target->getPart(); + } elseif ($target instanceof Pricedetail && $target->getOrderdetail() !== null && $target->getOrderdetail()->getPart() !== null) { + $on = $target->getOrderdetail()->getPart(); + } + + if (isset($on) && is_object($on)) { + try { + $tmp .= sprintf( + ' (%s)', + $this->entityURLGenerator->infoURL($on), + $this->elementTypeNameGenerator->getTypeNameCombination($on, true) + ); + } catch (EntityNotSupportedException $exception) { + $tmp .= ' (' . $this->elementTypeNameGenerator->getTypeNameCombination($target, true) .')'; + } + } + } + //Log is not associated with an element - return ''; + return $tmp; } } diff --git a/src/DataTables/LogDataTable.php b/src/DataTables/LogDataTable.php index 53d15a6c..135e9717 100644 --- a/src/DataTables/LogDataTable.php +++ b/src/DataTables/LogDataTable.php @@ -212,6 +212,7 @@ class LogDataTable implements DataTableTypeInterface $dataTable->add('target', LogEntryTargetColumn::class, [ 'label' => $this->translator->trans('log.target'), + 'show_associated' => $options['mode'] !== 'element_history', ]); $dataTable->add('extra', LogEntryExtraColumn::class, [