/**
  * @param WorkingMonth $workingMonth
  * @return array
  */
 private function setOrphans(WorkingMonth $workingMonth)
 {
     $orphans = array();
     // index = shiftId, content array with driver names
     if (null !== $workingMonth) {
         /** @var WorkingDay $workingDay */
         foreach ($workingMonth->getWorkingDays() as $workingDay) {
             /** @var Shift $shift */
             foreach ($workingDay->getShifts() as $shift) {
                 $drivernames = array();
                 /** @var DrivingAssertion $drivingAssertion */
                 foreach ($shift->getDrivingAssertions() as $drivingAssertion) {
                     if (null === $drivingAssertion->getDrivingPool()) {
                         $drivernames[] = $drivingAssertion->getDriver()->getNameStringForContact();
                     }
                 }
                 if ($drivernames !== array()) {
                     $orphans[$shift->getId()] = $drivernames;
                 }
             }
         }
     }
     return $orphans;
     // list(s) of orphaned drivers indexed by shiftId
 }
 /** -------------------------
  * Create driving assertions for a working month
  *
  * Triggered by a NEW Repeated Driving Assertion Plan.
  * Error condition: duplicates not allowed.
  *
  * Also by changes in existing (persisted) driving assertion plans.
  * Error condition: if duplicate has another assertionId.
  *
  * @param RepeatedDrivingAssertionPlan $repeatedDrivingAssertionPlan
  * @param WorkingMonth $workingMonth
  * @param array $errors
  * @return mixed
  */
 protected function handleRepeatedDrivingAssertionsForWorkingMonth($repeatedDrivingAssertionPlan, $workingMonth, &$errors)
 {
     $workingDays = $workingMonth->getWorkingDays();
     /** @var WorkingDay $workingDay */
     foreach ($workingDays as $workingDay) {
         $this->handleRepeatedDrivingAssertionsForWorkingDay($repeatedDrivingAssertionPlan, $workingDay, $errors);
     }
 }
 /**
  * Create DTO for the selected working month
  * @param WorkingMonth $workingMonth
  * @return array
  */
 public function workingMonthToEditDTO(WorkingMonth $workingMonth)
 {
     $tr = $this->container->get('translator');
     $dto = new MonthlyPlanGetDTO();
     $dto->targetSrc = $this->container->get('router')->generate('tixiapi_dispo_monthlyplan_edit', array('workingMonthId' => $workingMonth->getId(), 'workingDayId' => '__workingDayId__', 'editParams' => 'edit'));
     $dto->closeUrl = $this->container->get('router')->generate('tixiapi_dispo_monthlyplans_get');
     /** @var WorkingDay $workingDay */
     foreach ($workingMonth->getWorkingDays() as $workingDay) {
         $dayDto = new MonthlyPlanGetDayDTO();
         $dayDto->workingDayId = $workingDay->getId();
         $dayDto->swissDate = $workingDay->getDate()->format('d.m.Y');
         $dayDto->dayOfWeek = $tr->trans(DateTimeService::getDayOfWeek($workingDay->getDate()));
         $shifts = $workingDay->getShifts();
         /** @var Shift $shift */
         foreach ($shifts as $shift) {
             $dayDto->shifts[] = $this->getMonthlyPlanGetShiftDTO($shift);
         }
         $dto->workingDays[] = $dayDto;
     }
     /** @var Shift $shift */
     foreach ($workingMonth->getWorkingDays()[0]->getShifts() as $shift) {
         $dto->shiftNames[] = $shift->getShiftType()->getName();
     }
     return $dto;
 }
 /**
  * @param ProductionPlanEditDTO $editDTO
  * @param WorkingMonth $workingMonth
  * @return array
  * @throws \LogicException
  * @throws \InvalidArgumentException
  */
 public function editDtoToWorkingMonth(ProductionPlanEditDTO $editDTO, WorkingMonth $workingMonth)
 {
     $messages = array();
     $workingMonth->setMemo($editDTO->memo);
     $today = new \DateTime();
     $today->setTime(0, 0, 0);
     foreach ($workingMonth->getWorkingDays() as $workingDay) {
         if ($workingDay->getDate() >= $today) {
             /* only plan data is considered here, ignore past data */
             /** @var ProductionViewWorkingDayDTO $formWorkingDay */
             $formWorkingDay = $editDTO->getWorkingDayPerId($workingDay->getId());
             $workingDay->setComment($formWorkingDay->comment);
             $workingShifts = $workingDay->getShifts();
             foreach ($workingShifts as $workingShift) {
                 /** @var ProductionViewWorkingShiftDTO $formWorkingShift */
                 $formWorkingShift = $formWorkingDay->getWorkingShiftPerId($workingShift->getId());
                 if ($formWorkingShift->amountOfDrivers < 0) {
                     throw new \InvalidArgumentException();
                 }
                 if ($workingShift->getAmountOfDrivers() !== $formWorkingShift->amountOfDrivers) {
                     try {
                         $this->dispoService->processChangeInAmountOfDriversPerShift($workingShift, $workingShift->getAmountOfDrivers(), $formWorkingShift->amountOfDrivers, $messages);
                     } catch (\LogicException $e) {
                         throw new \LogicException($workingShift->getDate()->format('Y-m-d') . ', ' . $workingShift->getShiftType()->getName() . ': ' . $e->getFile() . ' ' . $e->getLine() . ' ' . $e->getMessage());
                     }
                 }
             }
         }
     }
     return $messages;
 }