/** ------------------------- * Assign dto->drivingAssertions to dto->shifts if empty driving pools are * available. Otherwise do nothing. * * @param DispositionResourcesDTO $dto * @return mixed * @throws \Exception */ public function assignAssertionsToDrivingPools(DispositionResourcesDTO $dto) { if ($dto->countShifts() !== $dto->countDrivingAssertions()) { throw new \Exception('assignAssertionsToDrivingPools: ' . 'Unbalanced arrays: shifts(' . $dto->countShifts() . '), ' . 'assertions(' . $dto->countDrivingAssertions() . ')'); } $success = false; /** @var Shift $shift */ foreach ($dto->getShifts() as $idx => $shift) { /** @var DrivingAssertion $drivingAssertion */ $drivingAssertion = $dto->getDrivingAssertions()->get($idx); /** @var DrivingPool $drivingPool */ foreach ($shift->getDrivingPools() as $drivingPool) { if (!$drivingPool->hasAssociatedDriver()) { /* assign driving assertion to empty driving pool */ $drivingAssertion->assignDrivingPool($drivingPool); $success = true; break; // assertion-pool is a one to one association } } } return $success; }
/** ------------------------- * Assign a vehicle to a driver and driving pool(s). * Check resource availability and compatibility with driver preferences, * if applicable register the resource(s) and assign vehicle to the * specified driving pool(s). * * @param DispositionResourcesDTO $dto * @param Shift[] $shifts * @return bool success = true */ public function assignVehicleToDriverAndDrivingPools(DispositionResourcesDTO $dto, array $shifts) { $vehicle = null; $driver = $dto->getDriver(); if ($driver->hasSupervisedVehicles()) { $vehicle = $this->findAvailableSupervisedVehicle($dto); } if (null === $vehicle) { $vehicle = $this->findAvailableRandomVehicle($dto); } if (null !== $vehicle) { $this->assignVehicleToDrivingPools($vehicle, $dto); return true; } return false; }