/** * 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(); }
/** * @DI\Observe("copy_file") * * @param CopyResourceEvent $event */ public function onCopy(CopyResourceEvent $event) { $newFile = $this->copy($event->getResource(), $event->getParent()); $event->setCopy($newFile); $event->stopPropagation(); }
/** * @DI\Observe("copy_claroline_survey") * * @param CopyResourceEvent $event */ public function onCopy(CopyResourceEvent $event) { $workspace = $event->getParent()->getWorkspace(); $survey = $event->getResource(); $copy = new Survey(); $copy->setPublished($survey->isPublished()); $copy->setClosed($survey->isClosed()); $copy->setHasPublicResult($survey->getHasPublicResult()); $copy->setAllowAnswerEdition($survey->getAllowAnswerEdition()); $copy->setStartDate($survey->getStartDate()); $copy->setEndDate($survey->getEndDate()); $this->om->persist($copy); $relations = $survey->getQuestionRelations(); foreach ($relations as $relation) { $question = $relation->getQuestion(); $type = $question->getType(); $copyQuestion = new Question(); $copyQuestion->setTitle($question->getTitle()); $copyQuestion->setQuestion($question->getQuestion()); $copyQuestion->setWorkspace($workspace); $copyQuestion->setType($type); $copyQuestion->setCommentAllowed($question->isCommentAllowed()); $copyQuestion->setCommentLabel($question->getCommentLabel()); $this->om->persist($copyQuestion); switch ($type) { case 'multiple_choice_single': case 'multiple_choice_multiple': $multiChoiceQuestion = $this->surveyManager->getMultipleChoiceQuestionByQuestion($question); $choices = $multiChoiceQuestion->getChoices(); $copyMultiQuestion = new MultipleChoiceQuestion(); $copyMultiQuestion->setHorizontal($multiChoiceQuestion->getHorizontal()); $copyMultiQuestion->setQuestion($copyQuestion); foreach ($choices as $choice) { $copyChoice = new Choice(); $copyChoice->setContent($choice->getContent()); $copyChoice->setOther($choice->isOther()); $copyChoice->setChoiceQuestion($copyMultiQuestion); $this->om->persist($copyChoice); } $this->om->persist($copyMultiQuestion); break; case 'open-ended': default: break; } $copyRelation = new SurveyQuestionRelation(); $copyRelation->setSurvey($copy); $copyRelation->setQuestion($copyQuestion); $copyRelation->setQuestionOrder($relation->getQuestionOrder()); $this->om->persist($copyRelation); } $event->setCopy($copy); $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(); }