Exemplo n.º 1
0
 /**
  * Publish path
  * Create all needed Entities from JSON structure created by the Editor
  * @param  \Innova\PathBundle\Entity\Path\Path $path
  * @throws \Exception
  * @return boolean
  */
 public function publish(Path $path)
 {
     // We need to publish all linked resources to have a full working Path
     // Start Publishing
     $this->start($path);
     // Store existing steps to remove steps which no longer exist
     $existingSteps = $path->getSteps()->toArray();
     // Publish steps for this path
     $toProcess = !empty($this->pathStructure->steps) ? $this->pathStructure->steps : array();
     /*//echo "JSON steps : <br>\n";var_dump($this->pathStructure->steps);*/
     $publishedSteps = $this->publishSteps(0, null, $toProcess);
     // Clean steps to remove
     $this->cleanSteps($publishedSteps, $existingSteps);
     // flush all steps
     $this->om->flush();
     // replace ids
     $json = $this->replaceStepIds();
     $json = $this->replaceStepConditionId($json);
     $json = $this->replaceCriteriagroupId($json);
     $json = $this->replaceCriteriaId($json);
     //echo "json final :".$json;
     // Re encode updated structure and update Path
     $this->path->setStructure($json);
     // Manage rights
     $this->manageRights();
     // Mark Path as published
     $this->path->setPublished(true);
     $this->path->setModified(false);
     // Persist data
     $this->om->persist($this->path);
     $this->om->flush();
     // End Publishing
     $this->end();
     return true;
 }
Exemplo n.º 2
0
 /**
  * Publish path
  * Create all needed Entities from JSON structure created by the Editor.
  *
  * @param \Innova\PathBundle\Entity\Path\Path $path
  *
  * @throws \Exception
  *
  * @return bool
  */
 public function publish(Path $path)
 {
     // We need to publish all linked resources to have a full working Path
     // Start Publishing
     $this->start($path);
     // Store existing steps to remove steps which no longer exist
     $existingSteps = $path->getSteps()->toArray();
     // Publish steps for this path
     $toProcess = !empty($this->pathStructure->steps) ? $this->pathStructure->steps : [];
     $publishedSteps = $this->publishSteps(0, null, $toProcess);
     // Clean steps to remove
     $this->cleanSteps($publishedSteps, $existingSteps);
     // Flush all created Entities in order to generate their IDs (needed to update the JSON structure of the Path)
     $this->om->flush();
     // Mark Path as published and not modified
     $this->path->setPublished(true);
     $this->path->setModified(false);
     // Re encode updated structure and update Path
     // When the Path is published, the structure is built from generated Entities
     // So we want to do this now to inject Entities IDs into the JSON structure
     $updatedStructure = $this->path->getStructure();
     $this->path->setStructure($updatedStructure);
     // Manage rights
     $this->manageRights();
     // Persist data
     $this->om->persist($this->path);
     $this->om->flush();
     // End Publishing
     $this->end();
     return true;
 }
Exemplo n.º 3
0
 /**
  * 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();
 }
Exemplo n.º 4
0
 /**
  * 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();
 }