feat: show the travel name above the mailing list
This commit is contained in:
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,
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
*
|
||||
|
||||
@@ -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.
|
||||
*
|
||||
|
||||
Reference in new issue
Block a user