/**
  * 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 ticketsAndRoomShouldBeUnavailable()
 {
     $this->inject($this->bookableService, 'configuration', [BookableService::TYPE_ROOM => ['fractionBase' => 12, 'availableQuota' => 10], BookableService::TYPE_TICKET => ['availableQuota' => 10]]);
     $bookables = $this->buildBookableRequest(10);
     $this->bookableService->requestRooms($bookables);
     $this->bookableService->requestTickets($bookables);
     $this->persistenceManager->persistAll();
     $this->assertEquals(0, $this->bookableService->getTicketsStatus());
     $this->assertEquals(0, $this->bookableService->getRoomStatus());
 }
 /**
  * @param Registration $registration
  */
 public function createAction(Registration $registration)
 {
     $pendingRegistration = $this->registrationRepository->findOneByAccountAndNotCompleted($this->securityContext->getAccount());
     if ($pendingRegistration !== NULL) {
         $this->view->assign('value', $this->dataTransferObjectFactory->getDataTransferObject($pendingRegistration));
         return;
     }
     $registrationLock = new \TYPO3\Flow\Utility\Lock\Lock('T3DD-Registration');
     $account = $this->securityContext->getAccount();
     $registrationEntity = $registration->getPayload();
     $registrationEntity->setAccount($account);
     $ticketRequest = [];
     $roomRequests = [];
     $participantPosition = 0;
     /** @var \T3DD\Backend\Domain\Model\Registration\Participant $participant */
     foreach ($registrationEntity->getParticipants() as $participant) {
         $participant->setPositionInRegistration($participantPosition++);
         $participant->setRegistration($registrationEntity);
         if ($participant->isRegistrant()) {
             $person = $this->partyService->getAssignedPartyOfAccount($account);
             $participant->setAccount($account);
             $participant->setPerson($person);
             if ($participant->getRoomSize() > 0) {
                 for ($i = 1; $i < $participant->getRoomSize(); $i++) {
                     $participant->addRoomMate(new \T3DD\Backend\Domain\Model\Registration\Mate());
                 }
             }
         }
         $ticketRequest[] = $participant->getTicketRequest();
         $roomRequest = $participant->getRoomRequest();
         if ($roomRequest !== NULL) {
             $roomRequests[] = $roomRequest;
         }
     }
     $this->bookableService->requestTickets($ticketRequest);
     $this->bookableService->requestRooms($roomRequests);
     $this->registrationRepository->add($registrationEntity);
     $this->persistenceManager->persistAll();
     $registrationLock->release();
     $this->view->assign('value', $registration);
 }