/** * 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 = []) { // 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']); $path->setCompleteBlockingCondition($pathData['completeBlockingCondition']); $path->setManualProgressionAllowed($pathData['manualProgressionAllowed']); // Create steps $stepData = $data['data']['steps']; if (!empty($stepData)) { $createdSteps = []; 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; }
/** * Fired when a ResourceNode of type Path is duplicated * @param \Claroline\CoreBundle\Event\CopyResourceEvent $event * @throws \Exception */ public function onCopy(CopyResourceEvent $event) { $om = $this->container->get('claroline.persistence.object_manager'); // Start the transaction. We'll copy every resource in one go that way. $om->startFlushSuite(); // Get Path to duplicate $pathToCopy = $event->getResource(); // Create new Path $path = new Path(); // Set up new Path properties $path->setName($pathToCopy->getName()); $path->setDescription($pathToCopy->getDescription()); $parent = $event->getParent(); $structure = json_decode($pathToCopy->getStructure()); // Process steps $processedNodes = array(); foreach ($structure->steps as $step) { $processedNodes = $this->copyStepContent($step, $parent, $processedNodes); } // End the transaction $om->endFlushSuite(); // We need the resources ids $om->forceFlush(); //update the structure tree foreach ($structure->steps as $step) { $this->updateStep($step, $processedNodes); } $path->setStructure(json_encode($structure)); $event->setCopy($path); // Force the unpublished state (the publication will recreate the correct links, and create new Activities) // If we directly copy all the published Entities we can't remap some relations $event->setPublish(false); $event->stopPropagation(); }
/** * Fired when a ResourceNode of type Path is duplicated * @param \Claroline\CoreBundle\Event\CopyResourceEvent $event * @throws \Exception */ public function onCopy(CopyResourceEvent $event) { // Get Path to duplicate $pathToCopy = $event->getResource(); // Create new Path $path = new Path(); // Set up new Path properties $path->setName($pathToCopy->getName()); $path->setDescription($pathToCopy->getDescription()); $parent = $event->getParent(); $structure = json_decode($pathToCopy->getStructure()); // Process steps $processedNodes = array(); foreach ($structure->steps as $step) { $processedNodes = $this->copyStepContent($step, $parent, $processedNodes); } // Store the new structure of the Path $path->setStructure(json_encode($structure)); $event->setCopy($path); // Force the unpublished state (the publication will recreate the correct links, and create new Activities) // If we directly copy all the published Entities we can't remap some relations $event->setPublish(false); $event->stopPropagation(); }