Example #1
0
 private function canRent(Rental $rental, User $user)
 {
     if ($rental->getUser() != $user) {
         return false;
     }
     if ($rental->getReturnAt()) {
         return false;
     }
     if ($user->getIsPenalized()) {
         return false;
     }
     if ($user->getFaculty()->getIsEnabled() === false) {
         return false;
     }
     if (!$rental->getIsRenewable()) {
         return false;
     }
     if ($rental->getIsExpired()) {
         return false;
     }
     if ($rental->getDaysLeft() > $this->days_before_renovation) {
         return false;
     }
     return true;
 }
 public function let(EntityManager $manager, EventDispatcherInterface $dispatcher, Faculty $faculty, RentalRepository $rentalRepository, LockerRepository $lockerRepository, User $user, Rental $rental, Locker $locker)
 {
     $days_length_rental = 7;
     $this->beConstructedWith($manager, $dispatcher, $lockerRepository, $rentalRepository, $days_length_rental);
     $user->getLocker()->willReturn(null);
     $user->getIsPenalized()->willReturn(false);
     $user->getQueue()->willReturn(null);
     $user->getFaculty()->willReturn($faculty);
     $faculty->getIsEnabled()->willReturn(true);
     $locker->getOwner()->willReturn(null);
     $locker->getStatus()->willReturn(Locker::AVAILABLE);
     $rentalRepository->getCurrentRental($locker)->willReturn($rental);
     $rental->getIsRenewable()->willReturn(true);
 }
Example #3
0
 public function rentLocker(User $user, Locker $locker)
 {
     if ($user->getIsPenalized()) {
         throw new PenalizedUserException();
     }
     if ($user->getFaculty()->getIsEnabled() === false) {
         throw new PenalizedFacultyException();
     }
     if ($locker->getStatus() != Locker::AVAILABLE) {
         throw new BusyLockerException();
     }
     if ($user->getLocker()) {
         throw new TooManyLockersRentedException();
     }
     /** @var Rental $rental */
     $rental = $this->rentalRepository->createNew();
     $rental->setUser($user);
     $rental->setLocker($locker);
     $rental->setEndAt(new \DateTime($this->days_length_rental . ' days'));
     $locker->setStatus(Locker::RENTED);
     $locker->setOwner($user);
     $this->manager->persist($locker);
     $this->manager->persist($rental);
     $this->manager->flush();
     $event = new RentalEvent($rental);
     $this->dispatcher->dispatch(RentalEvents::LOCKER_RENTED, $event);
     return $rental;
 }