feat: show the travel name above the mailing list

This commit is contained in:
fromme committed 2026-10-14 14:05:42 +02:00
1 parent d305774bee
commit ff722b5cef
5 files changed
+87 -4

No files matched your search

@@ -6,8 +6,10 @@ namespace App\Controller\Admin\TravelMailing;
use App\BpnConnect\Exception\BpnConnectException;
use App\BpnConnect\TravelsClient;
use App\BusProNet\Utility\DateCodeUtility;
use App\Form\Admin\TravelMailingLookupType;
use App\Form\Model\TravelMailingLookupDto;
use App\Service\TravelDataProvider;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
@@ -19,6 +21,7 @@ class IndexController extends AbstractController
{
public function __construct(
private readonly TravelsClient $travelsClient,
private readonly TravelDataProvider $travelDataProvider,
) {
}
@@ -32,10 +35,16 @@ class IndexController extends AbstractController
$form->handleRequest($request);
$result = null;
$travelLabel = null;
$failed = false;
if ($form->isSubmitted() && $form->isValid()) {
// The local index matches codes exactly, so "lpjmp-281126" has to become "LPJMP281126"
// before the label lookup; bpn-connect gets the same code to keep both in step.
$travelCode = (new DateCodeUtility())->sanitize((string) $lookup->travelCode);
try {
$result = $this->travelsClient->getMailingRecipients((string) $lookup->travelCode);
$result = $this->travelsClient->getMailingRecipients($travelCode);
$travelLabel = $this->travelDataProvider->mapDateCodeToLabel($travelCode);
} catch (BpnConnectException) {
// The client has already logged the cause; the page only needs to say it failed.
$failed = true;
@@ -45,6 +54,7 @@ class IndexController extends AbstractController
return $this->render('admin/travel_mailing/index.html.twig', [
'form' => $form,
'result' => $result,
'travel_label' => $travelLabel,
'failed' => $failed,
]);
}
+12
View File
@@ -420,6 +420,18 @@ class TravelDataProvider
return $this->travelLookupService->mapDateCodeToId($dateCode);
}
/**
* Map date code to the travel's label.
*
* @param string $dateCode The date code to map
*
* @return string|null The travel label or null if not found
*/
public function mapDateCodeToLabel(string $dateCode): ?string
{
return $this->travelLookupService->mapDateCodeToLabel($dateCode);
}
/**
* Map hotel code to hotel ID.
*
+18
View File
@@ -109,6 +109,24 @@ class TravelIndex
}
}
/**
* Resolve a date code to its travel label, e.g. "Davos - Sportclub Waldschlössli - Wochenende".
*
* @param string $dateCode The date code to resolve
*
* @return string|null The label, or null if the code is not found or the travel has none
*/
public function mapDateCodeToLabel(string $dateCode): ?string
{
$dateId = $this->mapDateCodeToId($dateCode);
if (null === $dateId) {
return null;
}
return $this->generateFilesMap()[$dateId]['label'] ?? null;
}
/**
* Convert a hotel code string to its corresponding hotel ID.
*
@@ -29,9 +29,14 @@
messages: ['Keine Empfänger für <code>%s</code> gefunden: Reisecode unbekannt oder keine bestätigten Teilnehmer.'|format(result.travelCode|e)],
} %}
{% else %}
<p class="pb-4 text-sm text-gray-700">
{{ result.data|length }} Empfänger für <code>{{ result.travelCode }}</code>
</p>
<div class="pb-4">
<h2 class="text-lg font-semibold">
{{ travel_label|default('Reise nicht im lokalen Reisebestand') }}
</h2>
<p class="text-sm text-gray-700">
{{ result.data|length }} Empfänger für <code>{{ result.travelCode }}</code>
</p>
</div>
<div class="data-table-wrapper">
<div class="data-table-wrapper__inner text-sm">
<table class="data-table">
+38
View File
@@ -148,6 +148,44 @@ class TravelIndexTest extends TestCase
$this->assertNull($result);
}
// -------------------------------------------------------------------------
// mapDateCodeToLabel
// -------------------------------------------------------------------------
public function testMapDateCodeToLabelReturnsTheTravelLabel(): void
{
$this->travelLoader->method('generateFilesMap')->willReturn([
42 => ['id' => 42, 'code' => 'WI25', 'label' => 'Davos - Sportclub Waldschlössli - Wochenende', 'hotels' => []],
]);
$this->travelSnapshotService->method('generateMapping')->willReturn([]);
$result = $this->service()->mapDateCodeToLabel('WI25');
$this->assertSame('Davos - Sportclub Waldschlössli - Wochenende', $result);
}
public function testMapDateCodeToLabelReturnsNullWhenNotFound(): void
{
$this->travelLoader->method('generateFilesMap')->willReturn([]);
$this->travelSnapshotService->method('generateMapping')->willReturn([]);
$result = $this->service()->mapDateCodeToLabel('UNKNOWN');
$this->assertNull($result);
}
public function testMapDateCodeToLabelReturnsNullWhenTheTravelHasNoLabel(): void
{
$this->travelLoader->method('generateFilesMap')->willReturn([
42 => ['id' => 42, 'code' => 'WI25', 'label' => null, 'hotels' => []],
]);
$this->travelSnapshotService->method('generateMapping')->willReturn([]);
$result = $this->service()->mapDateCodeToLabel('WI25');
$this->assertNull($result);
}
// -------------------------------------------------------------------------
// mapHotelCodeToId
// -------------------------------------------------------------------------