Пример #1
0
 /**
  * @param integer $availableMinutes
  * @param Address $startAddress
  * @param Address $endAddress
  * @return bool
  */
 private function isFeasibleEmptyRide($availableMinutes, Address $startAddress, Address $endAddress)
 {
     if (null !== $this->routeManagement) {
         /** @var Route $route */
         $route = $this->routeManagement->getRouteFromAddresses($startAddress, $endAddress);
         if ($availableMinutes >= $route->getDurationInMinutes() + DispositionVariables::ARRIVAL_BEFORE_PICKUP) {
             return true;
             // time to spare ...
         }
         return false;
         // too far to cope ...
     }
     return false;
     // can't check feasibility ...
 }
 /**
  * @param DrivingOrderRegisterDTO $registerDTO
  * @param Passenger $passenger
  * @param array $errors
  * @return RepeatedDrivingOrderPlan
  */
 public function registerDTOtoNewDrivingOrderPlan(DrivingOrderRegisterDTO $registerDTO, Passenger $passenger, &$errors)
 {
     /** @var Address $fromAddress */
     $fromAddress = $this->addressAssembler->addressLookaheadDTOtoAddress($registerDTO->lookaheadaddressFrom);
     /** @var Address $toAddress */
     $toAddress = $this->addressAssembler->addressLookaheadDTOtoAddress($registerDTO->lookaheadaddressTo);
     /** @var Zone $zone */
     $zone = $this->zonePlanManagement->getZoneWithHighestPriorityForCities(array($fromAddress->getCity(), $toAddress->getCity()));
     if (null == $zone) {
         $errors[] = 'drivingorder.form.error.zone';
     }
     if ($zone->isUnclassified()) {
         $errors[] = 'repeateddrivingorder.form.error.longDistance';
     }
     $route = $this->routeManagement->getRouteFromAddresses($fromAddress, $toAddress);
     $drivingOrderPlan = RepeatedDrivingOrderPlan::registerRepeatedDrivingOrderPlan($registerDTO->anchorDate, $registerDTO->withHolidays, $registerDTO->compagnion, $registerDTO->endDate, $registerDTO->memo, $registerDTO->additionalTime);
     $drivingOrderPlan->assignPassenger($passenger);
     $drivingOrderPlan->assignRoute($route);
     $drivingOrderPlan->assignZone($zone);
     $passenger->assignRepeatedDrivingOrderPlan($drivingOrderPlan);
     return $drivingOrderPlan;
 }
Пример #3
0
 /** -------------------------
  * Register one driving order (one way: outbound or return)
  *
  * @param DrivingOrderRegisterDTO $registerDTO
  * @param Passenger $passenger
  * @param $direction
  * @param mixed $status
  * @param array $errors
  * @return DrivingOrder|null
  * @throws Exception
  */
 protected function registerDtoToDrivingOrder(DrivingOrderRegisterDTO $registerDTO, Passenger $passenger, $direction, $status, &$errors)
 {
     /** @var Address $fromAddress */
     $fromAddress = $this->addressAssembler->addressLookaheadDTOtoAddress($registerDTO->lookaheadaddressFrom);
     /** @var Address $toAddress */
     $toAddress = $this->addressAssembler->addressLookaheadDTOtoAddress($registerDTO->lookaheadaddressTo);
     if ($fromAddress->getId() === $toAddress->getId() or null === $fromAddress or null === $toAddress) {
         $errors[] = 'drivingorder.form.error.illegalRoute';
         return null;
     }
     /** @var Zone $zone */
     $zone = $this->zonePlanManagement->getZoneWithHighestPriorityForCities(array($fromAddress->getCity(), $toAddress->getCity()));
     if (null == $zone) {
         $errors[] = 'drivingorder.form.error.zone';
         return null;
     }
     /** @var Route $route */
     $route = null;
     $pickupTime = null;
     try {
         if ($direction === self::OUTWARD_DIRECTION) {
             $pickupTime = $registerDTO->orderTime->outwardTime;
             $route = $this->routeManagement->getRouteFromAddresses($fromAddress, $toAddress);
         } elseif ($direction === self::RETURN_DIRECTION) {
             $pickupTime = $registerDTO->orderTime->returnTime;
             $route = $this->routeManagement->getRouteFromAddresses($toAddress, $fromAddress);
         } else {
             $errors[] = 'drivingorder.form.error.unknown';
         }
     } catch (Exception $e) {
         $errors[] = 'drivingorder.form.error.routingError';
         return null;
     }
     if (null === $route or null === $pickupTime) {
         $errors[] = 'drivingorder.form.error.routingError';
         $this->logger->error('Driving order: routing error (' . "Direction => {$direction}, " . "From => " . $fromAddress->getStreet() . ' ' . $fromAddress->getCity() . ', ' . "To => " . $toAddress->getStreet() . ', ' . $toAddress->getCity() . ')');
         return null;
     } else {
         $drivingOrder = DrivingOrder::registerDrivingOrder($passenger, $registerDTO->anchorDate, $pickupTime, $registerDTO->compagnion, $registerDTO->memo, $status, false, $registerDTO->additionalTime);
         $drivingOrder->assignRoute($route);
         $drivingOrder->assignZone($zone);
         $passenger->assignDrivingOrder($drivingOrder);
         return $drivingOrder;
     }
     return null;
 }