/** * 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; }
/** * Import a Path into the Platform * @param string $structure * @param array $data * @param array $resourcesCreated * @return Path */ public function import($structure, array $data, array $resourcesCreated = array()) { // Create a new Path object which will be populated with exported data $path = new Path(); $pathData = $data['data']['path']; // Populate Path properties $path->setBreadcrumbs(!empty($pathData['breadcrumbs']) ? $pathData['breadcrumbs'] : false); $path->setDescription($pathData['description']); $path->setModified($pathData['modified']); $path->setSummaryDisplayed($pathData['summaryDisplayed']); // Create steps $stepData = $data['data']['steps']; if (!empty($stepData)) { $createdSteps = array(); foreach ($stepData as $step) { $createdSteps = $this->stepManager->import($path, $step, $resourcesCreated, $createdSteps); } } // Inject empty structure into path (will be replaced by a version with updated IDs later in the import process) $path->setStructure($structure); return $path; }