/** * Move tickets and rooms from the waiting list * to pending if there are free quota */ public function updateWaitingListCommand() { $registrationsToNotify = []; $numberOfTickets = $this->bookableService->getTicketsStatus(); if ($numberOfTickets > 0) { $waitingTickets = $this->ticketRepository->findWaitingByCount($numberOfTickets); /** @var Ticket $ticket */ foreach ($waitingTickets as $ticket) { $priorBookingState = $ticket->getBookingState(); $ticket->setBookingState(AbstractBookable::BOOKING_STATE_PENDING); $this->ticketRepository->update($ticket); /** @var Participant $participant */ $participant = $this->registrationParticipantRepository->findOneByTicket($ticket); /** @var Registration $notification */ $notification = $participant->getRegistration(); $registrationIdentifier = $this->persistenceManager->getIdentifierByObject($notification); if (!array_key_exists($registrationIdentifier, $registrationsToNotify)) { $registrationsToNotify[$registrationIdentifier] = ['registration' => $notification, 'ticketBookingStateChanged' => [], 'roomBookingStateChanged' => []]; } $participantIdentifier = $this->persistenceManager->getIdentifierByObject($participant); $registrationsToNotify[$registrationIdentifier]['ticketBookingStateChanged'][$participantIdentifier] = ['participant' => $participant, 'priorBookingState' => $priorBookingState, 'newBookingState' => $ticket->getBookingState()]; } } $numberOfRooms = $this->bookableService->getTicketsStatus(); if ($numberOfRooms > 0) { $waitingRooms = $this->roomRepository->findWaitingByCount($numberOfRooms); /** @var Room $room */ foreach ($waitingRooms as $room) { $priorBookingState = $room->getBookingState(); $room->setBookingState(AbstractBookable::BOOKING_STATE_PENDING); $this->roomRepository->update($room); /** @var Participant $participant */ $participant = $this->registrationParticipantRepository->findOneByRoom($room); /** @var Registration $registration */ $notification = $participant->getRegistration(); $registrationIdentifier = $this->persistenceManager->getIdentifierByObject($notification); if (!array_key_exists($registrationIdentifier, $registrationsToNotify)) { $registrationsToNotify[$registrationIdentifier] = ['registration' => $notification, 'ticketBookingStateChanged' => [], 'roomBookingStateChanged' => []]; } $participantIdentifier = $this->persistenceManager->getIdentifierByObject($participant); $registrationsToNotify[$registrationIdentifier]['roomBookingStateChanged'][$participantIdentifier] = ['participant' => $participant, 'priorBookingState' => $priorBookingState, 'newBookingState' => $room->getBookingState()]; } } $this->persistenceManager->persistAll(); /** @var array $notification */ foreach ($registrationsToNotify as $notification) { $this->mailService->sendMoveToWaitingListMail($notification); } }
/** * @test */ public function requestingRoomBookingWithoutQuotaApplicationDoesNotIncreaseSpentAmount() { $this->inject($this->bookableService, 'configuration', [BookableService::TYPE_ROOM => ['fractionBase' => 12, 'availableQuota' => 10]]); $this->bookableService->requestRooms($this->buildBookableRequest(10)); $this->persistenceManager->persistAll(); $requests = $this->buildBookableRequest(3); $requests = array_map(function ($request) { $request['quotaApplies'] = FALSE; return $request; }, $requests); $requestedRooms = $this->bookableService->requestRooms($requests); $this->persistenceManager->persistAll(); $requestedStates = array_map(function ($requestedRoom) { return $requestedRoom->getBookingState(); }, $requestedRooms); $this->assertEquals(array_fill(0, 3, AbstractBookable::BOOKING_STATE_PENDING), $requestedStates); $this->assertEquals(10, $this->roomRepository->getSpentQuota() / 12); }