Merge branch 'master' into feature/multiple-hotelcodes

This commit is contained in:
Björn Fromme
2025-01-08 10:07:43 +01:00
3 changed files with 14 additions and 24 deletions
@@ -43,7 +43,7 @@ class HotelDataProvider
$hotels = []; $hotels = [];
foreach ($this->getAll() as $hotel) { foreach ($this->getAll() as $hotel) {
if (str_starts_with($hotel->getCode(), $code)) { if (str_starts_with($hotel->getCode(), $code) || str_ends_with($hotel->getCode(), $code)) {
$hotels[] = $hotel; $hotels[] = $hotel;
} }
} }
@@ -2,7 +2,6 @@
namespace App\Controller\HouseManager; namespace App\Controller\HouseManager;
use App\BusProNet\DataProvider\HotelDataProvider;
use App\Entity\User; use App\Entity\User;
use App\Repository\DispositionRepository; use App\Repository\DispositionRepository;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
@@ -12,10 +11,8 @@ use Symfony\Component\Security\Http\Attribute\IsGranted;
class IndexController extends AbstractController class IndexController extends AbstractController
{ {
public function __construct( public function __construct(private readonly DispositionRepository $dispositionRepository)
private readonly HotelDataProvider $hotelDataProvider, {
private readonly DispositionRepository $dispositionRepository
) {
} }
#[Route('/house-manager', name: 'app_house_manager_index')] #[Route('/house-manager', name: 'app_house_manager_index')]
@@ -25,11 +22,6 @@ class IndexController extends AbstractController
/** @var User $user */ /** @var User $user */
$user = $this->getUser(); $user = $this->getUser();
$hotels = $this
->hotelDataProvider
->findByCode($user->getHotelCode())
;
$newDispositions = $this $newDispositions = $this
->dispositionRepository ->dispositionRepository
->findNewDispositionsByHotelCodes($user->getHotelCodes()) ->findNewDispositionsByHotelCodes($user->getHotelCodes())
+11 -13
View File
@@ -70,20 +70,18 @@ class DispositionVoter extends Voter
return false; return false;
} }
$hotels = $this $userHotelCode = $token->getUser()->getHotelCode();
->hotelDataProvider
->findByCode($token->getUser()->getHotelCode())
;
$hotelBusProIds = array_map(function (Hotel $hotel) {
return $hotel->getBusProId();
}, $hotels);
$destination = $disposition
->getAssignment()
->getDestination()
;
return in_array($destination->getHotelBusProId(), $hotelBusProIds) $destination = $disposition
&& $destination->getDateTo() < new \DateTimeImmutable(); ->getAssignment()
->getDestination()
;
$isMatchingHotel = str_starts_with($destination->getHotelCode(), $userHotelCode)
|| str_ends_with($destination->getHotelCode(), $userHotelCode);
$isPast = $destination->getDateTo() < new \DateTimeImmutable();
return $isMatchingHotel && $isPast;
} }
private function assertTeamerAccess(Disposition $disposition): bool private function assertTeamerAccess(Disposition $disposition): bool