/** -------------------------
  * Check the new or persisted driving assertion plan against all others
  *
  * There should be at least one repeated driving assertion in each plan,
  * where no driving assertions should ever have duplicate shifts, to be
  * precise: a driver shift relationship is 1:1, never 1:many.
  *
  * @param RepeatedDrivingAssertionPlan $assertionPlan
  * @param RepeatedDrivingAssertion[] $repeatedAssertions
  * @return array of validation errors (translated)
  */
 public function checkAssertionPlan($assertionPlan, $repeatedAssertions)
 {
     $errors = array();
     $planId = $assertionPlan->getId();
     $driver = $assertionPlan->getDriver();
     $flatPlan = $this->flatAssertionPlan($assertionPlan, $repeatedAssertions);
     if (count($flatPlan) == 0) {
         $errors[] = $this->translate('repeateddrivingassertion.error.empty');
         return $errors;
     }
     $this->checkTimeRange($assertionPlan, $errors);
     /** @var RepeatedDrivingAssertionPlanRepository $assertionPlanRepository */
     $assertionPlanRepository = $this->container->get('repeateddrivingassertionplan_repository');
     /** @var RepeatedDrivingAssertionPlan[] $repositoryPlans */
     $repositoryPlans = $assertionPlanRepository->findAllProspectiveForDriver($driver);
     $flatRepo = array();
     foreach ($repositoryPlans as $repositoryPlan) {
         if ($repositoryPlan->getId() != $planId) {
             $flatRepo[] = $this->flatAssertionPlan($repositoryPlan, $repositoryPlan->getRepeatedDrivingAssertionsAsArray());
         }
     }
     /** @var DrivingAssertionManagementDTO $plan */
     foreach ($flatPlan as $plan) {
         foreach ($flatRepo as $array) {
             /** @var DrivingAssertionManagementDTO $repo */
             foreach ($array as $repo) {
                 $c1 = ($plan->enddate >= $repo->anchordate and $plan->enddate <= $repo->enddate);
                 $c2 = ($plan->anchordate >= $repo->anchordate and $plan->anchordate <= $repo->enddate);
                 $c3 = ($plan->weekdayAsText == $repo->weekdayAsText and $plan->shiftTypeName == $repo->shiftTypeName);
                 if (($c1 or $c2) and $c3) {
                     $errors[] = $this->translate('repeateddrivingassertion.error.duplicate') . " " . $this->translate($plan->weekdayAsText) . " " . $plan->shiftTypeName;
                 }
             }
         }
     }
     return $errors;
 }