feat: custom destinations
This commit is contained in:
1 parent
57e1082f2f
commit
efc4b58077
27 files changed
+826
-40
No files matched your search
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller\Admin\Autocomplete;
|
||||
|
||||
use App\BusProNet\DataProvider\HotelDataProvider;
|
||||
use App\BusProNet\Model\Hotel;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
use Symfony\Component\Security\Http\Attribute\IsGranted;
|
||||
|
||||
class HotelController extends AbstractController
|
||||
{
|
||||
public function __construct(private readonly HotelDataProvider $hotelDataProvider)
|
||||
{}
|
||||
|
||||
#[Route('/admin/autocomplete/hotel', name: 'app_admin_autocomplete_hotel')]
|
||||
#[IsGranted('ROLE_ADMINISTRATIVE')]
|
||||
public function index(Request $request): JsonResponse
|
||||
{
|
||||
try {
|
||||
$query = json_decode($request->getContent(), true, 512, JSON_THROW_ON_ERROR);
|
||||
$queryString = $query['search'];
|
||||
} catch (\JsonException $e) {
|
||||
throw $this->createNotFoundException();
|
||||
}
|
||||
|
||||
/** @var Hotel[] $hotels */
|
||||
$hotels = $this->hotelDataProvider->getAll();
|
||||
|
||||
$data = [
|
||||
[
|
||||
'value' => '',
|
||||
'text' => '...',
|
||||
],
|
||||
];
|
||||
|
||||
foreach ($hotels as $hotel) {
|
||||
if (false !== stripos($hotel->getName(), $queryString)) {
|
||||
$data[] = [
|
||||
'value' => $hotel->getBusProId(),
|
||||
'text' => sprintf('%s (%s)', $hotel->getName(), $hotel->getCode()),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
return $this->json($data);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user