feat: show the travel name above the mailing list
This commit is contained in:
1 parent
d305774bee
commit
ff722b5cef
5 files changed
+85
-2
No files matched your search
@@ -6,8 +6,10 @@ namespace App\Controller\Admin\TravelMailing;
|
|||||||
|
|
||||||
use App\BpnConnect\Exception\BpnConnectException;
|
use App\BpnConnect\Exception\BpnConnectException;
|
||||||
use App\BpnConnect\TravelsClient;
|
use App\BpnConnect\TravelsClient;
|
||||||
|
use App\BusProNet\Utility\DateCodeUtility;
|
||||||
use App\Form\Admin\TravelMailingLookupType;
|
use App\Form\Admin\TravelMailingLookupType;
|
||||||
use App\Form\Model\TravelMailingLookupDto;
|
use App\Form\Model\TravelMailingLookupDto;
|
||||||
|
use App\Service\TravelDataProvider;
|
||||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
@@ -19,6 +21,7 @@ class IndexController extends AbstractController
|
|||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
private readonly TravelsClient $travelsClient,
|
private readonly TravelsClient $travelsClient,
|
||||||
|
private readonly TravelDataProvider $travelDataProvider,
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -32,10 +35,16 @@ class IndexController extends AbstractController
|
|||||||
$form->handleRequest($request);
|
$form->handleRequest($request);
|
||||||
|
|
||||||
$result = null;
|
$result = null;
|
||||||
|
$travelLabel = null;
|
||||||
$failed = false;
|
$failed = false;
|
||||||
if ($form->isSubmitted() && $form->isValid()) {
|
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 {
|
try {
|
||||||
$result = $this->travelsClient->getMailingRecipients((string) $lookup->travelCode);
|
$result = $this->travelsClient->getMailingRecipients($travelCode);
|
||||||
|
$travelLabel = $this->travelDataProvider->mapDateCodeToLabel($travelCode);
|
||||||
} catch (BpnConnectException) {
|
} catch (BpnConnectException) {
|
||||||
// The client has already logged the cause; the page only needs to say it failed.
|
// The client has already logged the cause; the page only needs to say it failed.
|
||||||
$failed = true;
|
$failed = true;
|
||||||
@@ -45,6 +54,7 @@ class IndexController extends AbstractController
|
|||||||
return $this->render('admin/travel_mailing/index.html.twig', [
|
return $this->render('admin/travel_mailing/index.html.twig', [
|
||||||
'form' => $form,
|
'form' => $form,
|
||||||
'result' => $result,
|
'result' => $result,
|
||||||
|
'travel_label' => $travelLabel,
|
||||||
'failed' => $failed,
|
'failed' => $failed,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -420,6 +420,18 @@ class TravelDataProvider
|
|||||||
return $this->travelLookupService->mapDateCodeToId($dateCode);
|
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.
|
* Map hotel code to hotel ID.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -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.
|
* 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)],
|
messages: ['Keine Empfänger für <code>%s</code> gefunden: Reisecode unbekannt oder keine bestätigten Teilnehmer.'|format(result.travelCode|e)],
|
||||||
} %}
|
} %}
|
||||||
{% else %}
|
{% else %}
|
||||||
<p class="pb-4 text-sm text-gray-700">
|
<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>
|
{{ result.data|length }} Empfänger für <code>{{ result.travelCode }}</code>
|
||||||
</p>
|
</p>
|
||||||
|
</div>
|
||||||
<div class="data-table-wrapper">
|
<div class="data-table-wrapper">
|
||||||
<div class="data-table-wrapper__inner text-sm">
|
<div class="data-table-wrapper__inner text-sm">
|
||||||
<table class="data-table">
|
<table class="data-table">
|
||||||
|
|||||||
@@ -148,6 +148,44 @@ class TravelIndexTest extends TestCase
|
|||||||
$this->assertNull($result);
|
$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
|
// mapHotelCodeToId
|
||||||
// -------------------------------------------------------------------------
|
// -------------------------------------------------------------------------
|
||||||
|
|||||||
Reference in new issue
Block a user