diff --git a/public/api-spec-v1.json b/public/api-spec-v1.json index c32a38d..6322468 100644 --- a/public/api-spec-v1.json +++ b/public/api-spec-v1.json @@ -442,6 +442,7 @@ "type": "string" }, "proximityToUnlock": { + "description": "Proximity to unlock in meters.", "type": [ "integer", "null" @@ -542,6 +543,7 @@ "type": "string" }, "proximityToUnlock": { + "description": "Proximity to unlock in meters.", "type": [ "integer", "null" diff --git a/public/api-spec-v1.yaml b/public/api-spec-v1.yaml index edeaf49..cf7d8d5 100644 --- a/public/api-spec-v1.yaml +++ b/public/api-spec-v1.yaml @@ -208,6 +208,7 @@ components: longitude: type: string proximityToUnlock: + description: 'Proximity to unlock in meters.' type: - integer - 'null' @@ -278,6 +279,7 @@ components: longitude: type: string proximityToUnlock: + description: 'Proximity to unlock in meters.' type: - integer - 'null' diff --git a/src/Controller/Admin/PointOfInterestCrudController.php b/src/Controller/Admin/PointOfInterestCrudController.php index 60ad309..0d9077a 100644 --- a/src/Controller/Admin/PointOfInterestCrudController.php +++ b/src/Controller/Admin/PointOfInterestCrudController.php @@ -3,10 +3,12 @@ namespace App\Controller\Admin; use App\Admin\Field\LocationField; +use App\Admin\Field\ValueWithUnitField; use App\Entity\PointOfInterest; use App\Entity\Role; use App\Entity\Route; use App\Field\VichImageField; +use App\Form\ValueWithUnitType; use App\Service\EasyAdminHelper; use EasyCorp\Bundle\EasyAdminBundle\Config\Crud; use EasyCorp\Bundle\EasyAdminBundle\Field\AssociationField; @@ -91,8 +93,15 @@ public function configureFields(string $pageName): iterable ->setRequired(true) ->setVirtual(true)->setColumns(12); - yield NumberField::new('proximityToUnlock', new TranslatableMessage('Proximity to unlock', [], 'admin')) - ->setHelp(new TranslatableMessage('The proximity that allows unlocking this point of interest (in m).', [], 'admin'))->setColumns(12); + yield ValueWithUnitField::new('proximityToUnlock', new TranslatableMessage('Proximity to unlock', [], 'admin')) + ->setFormTypeOption('units', [ + 'm' => [ + ValueWithUnitType::OPTION_LABEL => new TranslatableMessage('meter', [], 'admin'), + ValueWithUnitType::OPTION_SCALE => 1, + ValueWithUnitType::OPTION_LOCALIZED_UNIT => new TranslatableMessage('unit.m', [], 'admin'), + ], + ]) + ->setHelp(new TranslatableMessage('The proximity that allows unlocking this point of interest.', [], 'admin'))->setColumns(12); yield DateField::new('createdAt', new TranslatableMessage('Created at', [], 'admin'))->hideOnForm(); yield DateField::new('updatedAt', new TranslatableMessage('Updated at', [], 'admin'))->hideOnForm(); diff --git a/src/Entity/PointOfInterest.php b/src/Entity/PointOfInterest.php index 4e5b144..798a2de 100644 --- a/src/Entity/PointOfInterest.php +++ b/src/Entity/PointOfInterest.php @@ -81,6 +81,9 @@ class PointOfInterest implements BlameableInterface, \JsonSerializable #[Groups(['read'])] private ?string $longitude = null; + /** + * Proximity to unlock in meters. + */ #[ORM\Column(length: 255, nullable: true)] #[Assert\NotBlank] #[Groups(['read'])] diff --git a/src/Form/ValueWithUnitType.php b/src/Form/ValueWithUnitType.php index 7884872..d8bb7b6 100644 --- a/src/Form/ValueWithUnitType.php +++ b/src/Form/ValueWithUnitType.php @@ -62,7 +62,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void ; } - public function transform(int $value, array $options): array + public function transform(?int $value, array $options): array { try { return $this->getMatchingUnit($value, $options); @@ -118,14 +118,14 @@ private function getUnits(array $options): array return $units; } - public function getMatchingUnit(int $value, array $options): array + public function getMatchingUnit(?int $value, array $options): array { $units = $this->getUnits($options); foreach ($units as $unit => $info) { $scale = $info[self::OPTION_SCALE]; if ($value >= $scale || array_key_last($units) === $unit) { return [ - self::FIELD_VALUE => $scale > 1 ? $value / $scale : $value, + self::FIELD_VALUE => null === $value ? null : ($scale > 1 ? $value / $scale : $value), self::FIELD_UNIT => $unit, self::OPTION_LOCALIZED_UNIT => $info[self::OPTION_LOCALIZED_UNIT], ]; diff --git a/translations/admin+intl-icu.da.xlf b/translations/admin+intl-icu.da.xlf index 5952eb3..50faeb7 100644 --- a/translations/admin+intl-icu.da.xlf +++ b/translations/admin+intl-icu.da.xlf @@ -21,10 +21,6 @@ A text version of the podcast, for people with hearing disabilities. En tekstuel udgave af podcasten til mennesker med hørenedsættelse. - - The proximity that allows unlocking this point of interest (in m). - Nærheden for at afspille seværdigheden (i meter). - Users mail address, which is also used as login name E-mailadresse som også bruges som brugernavn @@ -89,7 +85,7 @@ This link will expire in {expire_info}. Linket udløber om {expire_info}. - + If you don't receive an email please check your spam folder or <a href="{forgot_password_url}">try again</a>. prøv igen.]]> @@ -205,7 +201,7 @@ Email E-mail - + Enter a location on the form <code>lat, lng</code>, e.g. <code>56.153244272970866, 10.213798100000005</code>. <strong>Notice</strong>: the two numbers must always be separated by a comma and use dot as decimal separator.<br>Hint: Open <a href="https://www.google.com/maps" target="_blank">Google Maps</a> and “right” click on the map to get the coordinates. breddegrad, længdegrad, fx. 56.153244272970866, 10.213798100000005. Bemærk: de to tal skal altid adskilles af et komma og skal bruge punktum som decimalseparator.
Tip: Åbn Google Maps og højreklik på kortet for at få koordinaterne.]]>
@@ -341,6 +337,10 @@ minutes minutter
+ + The proximity that allows unlocking this point of interest. + Nærheden for at afspille seværdigheden. + diff --git a/translations/admin+intl-icu.en.xlf b/translations/admin+intl-icu.en.xlf index 537c42e..837a6e2 100644 --- a/translations/admin+intl-icu.en.xlf +++ b/translations/admin+intl-icu.en.xlf @@ -21,10 +21,6 @@ A text version of the podcast, for people with hearing disabilities. A text version of the podcast, for people with hearing disabilities. - - The proximity that allows unlocking this point of interest (in m). - The proximity that allows unlocking this point of interest (in m). - Users mail address, which is also used as login name Users mail address, which is also used as login name @@ -341,6 +337,10 @@ minutes minutes + + The proximity that allows unlocking this point of interest. + The proximity that allows unlocking this point of interest. +