Skip to content
Snippets Groups Projects
Commit b9b4976b authored by Jonathan Foucher's avatar Jonathan Foucher
Browse files

linked items selector labels. Fixes #953

parent 3cf8e7df
No related branches found
No related tags found
Loading
Pipeline #84768 passed
......@@ -4,6 +4,8 @@ namespace App\Application\Form\Type;
use App\Application\Interfaces\CollectivityRelated;
use App\Domain\Registry\Dictionary\MesurementStatusDictionary;
use App\Domain\Registry\Dictionary\ProofTypeDictionary;
use App\Domain\Registry\Dictionary\ViolationNatureDictionary;
use App\Domain\Registry\Model\Mesurement;
use App\Domain\Registry\Model\Proof;
use App\Domain\Registry\Model\Request;
......@@ -65,8 +67,14 @@ class LinkableType extends AbstractType
'aria-label' => $ariaLabel,
],
'choice_label' => function ($object) {
if ($object instanceof Violation || $object instanceof Request || $object instanceof Proof) {
return $this->formatArchivedObjectLabel($object);
if ($object instanceof Request) {
return $this->formatRequestLabel($object);
}
if ($object instanceof Violation) {
return $this->formatViolationLabel($object);
}
if ($object instanceof Proof) {
return $this->formatProofLabel($object);
}
if ($object instanceof Treatment) {
return $this->formatInactiveObjectLabel($object);
......@@ -80,6 +88,19 @@ class LinkableType extends AbstractType
];
}
protected function formatRequestLabel(Request $object)
{
if (!\method_exists($object, '__toString')) {
throw new \RuntimeException('The object ' . \get_class($object) . ' must implement __toString() method');
}
if (\method_exists($object, 'getDeletedAt') && null !== $object->getDeletedAt()) {
return '(Archivé) ' . $object->getDate()->format('d/m/Y') . ' - ' . $object->__toString();
}
return $object->getDate()->format('d/m/Y') . ' - ' . $object->__toString();
}
/**
* Prefix every inactive object with "Inactif".
*/
......@@ -113,18 +134,44 @@ class LinkableType extends AbstractType
}
/**
* Prefix every archived object with "Archivé".
* Prefix every proof.
*/
protected function formatArchivedObjectLabel($object): string
protected function formatProofLabel(Proof $object): string
{
if (!\method_exists($object, '__toString')) {
throw new \RuntimeException('The object ' . \get_class($object) . ' must implement __toString() method');
}
if (\method_exists($object, 'getDeletedAt') && null !== $object->getDeletedAt()) {
return '(Archivé) ' . $object->__toString();
return '(Archivé) ' . $object->__toString() . ' (' . ProofTypeDictionary::getTypes()[$object->getType()] . ')';
}
return $object->__toString();
return $object->__toString() . ' (' . ProofTypeDictionary::getTypes()[$object->getType()] . ')';
}
/**
* Prefix violations.
*/
protected function formatViolationLabel(Violation $object): string
{
if (!\method_exists($object, '__toString')) {
throw new \RuntimeException('The object ' . \get_class($object) . ' must implement __toString() method');
}
$natures = [];
if ($object->getViolationNatures()) {
$raw = $object->getViolationNatures();
if (is_string($raw)) {
$raw = explode(',', $raw);
}
$natures = array_map(function ($n) {return ViolationNatureDictionary::getNatures()[trim($n)]; }, (array) $raw);
}
if (\method_exists($object, 'getDeletedAt') && null !== $object->getDeletedAt()) {
return '(Archivé) ' . $object->getDate()->format('d/m/Y') . ' - ' . join(', ', $natures);
}
return $object->getDate()->format('d/m/Y') . ' - ' . join(', ', $natures);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment