/**
  * Publish steps for the path
  * @param  integer                        $level
  * @param  \Innova\PathBundle\Entity\Step $parent
  * @param  array                          $steps
  * @param  array                          $propagatedResources
  * @return array
  */
 protected function publishSteps($level = 0, Step $parent = null, array $steps = array(), $propagatedResources = array())
 {
     $currentOrder = 0;
     $processedSteps = array();
     // Retrieve existing steps for this path
     $existingSteps = $this->path->getSteps();
     //        //echo "DB steps : <br>";var_dump($existingSteps);
     foreach ($steps as $stepStructure) {
         //echo "before : stepStructure->resourceId=";//echo $stepStructure->resourceId."<br>\n";
         if (empty($stepStructure->resourceId) || !$existingSteps->containsKey($stepStructure->resourceId)) {
             //echo "create step <br>";//echo 'level'.$level."<br>\n";
             // Current step has never been published or step entity has been deleted => create it
             $step = $this->stepManager->create($this->path, $level, $parent, $currentOrder, $stepStructure);
             $uniqId = "_STEP" . uniqid();
             $this->uniqId2step[$uniqId] = $step;
             // Update json structure with new resource ID
             $stepStructure->resourceId = $uniqId;
             //echo "after create step : stepStructure->resourceId =";//echo $stepStructure->resourceId."<br>\n";
         } else {
             //echo "update step <br>";//echo 'level'.$level.' stepStructure->resourceId:'.$stepStructure->resourceId.' parent'.$parent."<br>\n";
             // Step already exists => update it
             $step = $existingSteps->get($stepStructure->resourceId);
             $step = $this->stepManager->edit($this->path, $level, $parent, $currentOrder, $stepStructure, $step);
         }
         //condition management
         $publishedStepConditions = $this->publishStepConditions($step, $stepStructure);
         // Manage resources inheritance
         $excludedResources = !empty($stepStructure->excludedResources) ? $stepStructure->excludedResources : array();
         $this->publishPropagatedResources($step, $propagatedResources, $excludedResources);
         // Store step to know it doesn't have to be deleted when we will clean the path
         $processedSteps[] = $step;
         // Process children of current step
         if (!empty($stepStructure->children)) {
             // Add propagated resources of current step for children
             $currentPropagatedResources = array();
             if (!empty($stepStructure->resources)) {
                 foreach ($stepStructure->resources as $resource) {
                     if (!empty($resource->propagateToChildren) && $resource->propagateToChildren) {
                         // Resource is propagated
                         $currentPropagatedResources[] = array('id' => $resource->id, 'resourceId' => $resource->resourceId, 'lvl' => $level);
                     }
                 }
             }
             $childrenLevel = $level + 1;
             $propagatedResourcesTemp = array_merge($propagatedResources, $currentPropagatedResources);
             $childrenSteps = $this->publishSteps($childrenLevel, $step, $stepStructure->children, $propagatedResourcesTemp);
             // Store children steps
             $processedSteps = array_merge($processedSteps, $childrenSteps);
         }
         $currentOrder++;
     }
     return $processedSteps;
 }
 /**
  * Publish steps for the path.
  *
  * @param int                            $level
  * @param \Innova\PathBundle\Entity\Step $parent
  * @param array                          $steps
  * @param array                          $propagatedResources
  *
  * @return array
  */
 protected function publishSteps($level = 0, Step $parent = null, array $steps = [], $propagatedResources = [])
 {
     $currentOrder = 0;
     $processedSteps = [];
     // Retrieve existing steps for this path
     $existingSteps = $this->path->getSteps();
     foreach ($steps as $stepStructure) {
         if (empty($stepStructure->resourceId) || !$existingSteps->containsKey($stepStructure->resourceId)) {
             // Current step has never been published or step entity has been deleted => create it
             $step = $this->stepManager->create($this->path, $level, $parent, $currentOrder, $stepStructure);
         } else {
             // Step already exists => update it
             $step = $existingSteps->get($stepStructure->resourceId);
             $step = $this->stepManager->edit($this->path, $level, $parent, $currentOrder, $stepStructure, $step);
         }
         // Manage resources inheritance
         $excludedResources = !empty($stepStructure->excludedResources) ? $stepStructure->excludedResources : [];
         $this->publishPropagatedResources($step, $propagatedResources, $excludedResources);
         // Store step to know it doesn't have to be deleted when we will clean the path
         $processedSteps[] = $step;
         // Process children of current step
         if (!empty($stepStructure->children)) {
             // Add propagated resources of current step for children
             $currentPropagatedResources = [];
             if (!empty($stepStructure->resources)) {
                 foreach ($stepStructure->resources as $resource) {
                     if (!empty($resource->propagateToChildren) && $resource->propagateToChildren) {
                         // Resource is propagated
                         $currentPropagatedResources[] = ['id' => $resource->id, 'resourceId' => $resource->resourceId, 'lvl' => $level];
                     }
                 }
             }
             $childrenLevel = $level + 1;
             $propagatedResourcesTemp = array_merge($propagatedResources, $currentPropagatedResources);
             $childrenSteps = $this->publishSteps($childrenLevel, $step, $stepStructure->children, $propagatedResourcesTemp);
             // Store children steps
             $processedSteps = array_merge($processedSteps, $childrenSteps);
         }
         ++$currentOrder;
     }
     return $processedSteps;
 }