Exemplo n.º 1
0
 public function copyWiki(Wiki $orgWiki, $loggedUser)
 {
     $orgRoot = $orgWiki->getRoot();
     $sections = $this->sectionRepository->children($orgRoot);
     array_unshift($sections, $orgRoot);
     $newSectionsMap = array();
     $newWiki = new Wiki();
     $newWiki->setWikiCreator($loggedUser);
     foreach ($sections as $section) {
         $newSection = new Section();
         $newSection->setWiki($newWiki);
         $newSection->setVisible($section->getVisible());
         $newSection->setAuthor($loggedUser);
         $activeContribution = new Contribution();
         $activeContribution->setTitle($section->getActiveContribution()->getTitle());
         $activeContribution->setText($section->getActiveContribution()->getText());
         $activeContribution->setSection($newSection);
         $activeContribution->setContributor($loggedUser);
         $newSection->setActiveContribution($activeContribution);
         if ($section->isRoot()) {
             $newWiki->setRoot($newSection);
             $this->om->persist($newWiki);
             $this->sectionRepository->persistAsFirstChild($newSection);
         } else {
             $newSectionParent = $newSectionsMap[$section->getParent()->getId()];
             $newSection->setParent($newSectionParent);
             $this->sectionRepository->persistAsLastChildOf($newSection, $newSectionParent);
         }
         $this->om->persist($activeContribution);
         $newSectionsMap[$section->getId()] = $newSection;
     }
     return $newWiki;
 }
Exemplo n.º 2
0
 /**
  * Update section configuration (visibility or position in tree) but not the current contribution.
  *
  * @param Wiki         $wiki
  * @param Section      $section
  * @param ParamFetcher $paramFetcher
  *
  * @return mixed[]
  *
  * @Route(
  *     requirements = { "wiki" = "\d+", "section" = "\d+" }
  * )
  * @QueryParam(
  *     name="visible",
  *     requirements="(true|false)",
  *     description="Sets the visibility of the section"
  * )
  * @QueryParam(
  *     name="referenceSectionId",
  *     requirements="\d+",
  *     nullable=true,
  *     description="Id of the section serving as new parent or sibling"
  * )
  * @QueryParam(
  *     name="isBrother",
  *     requirements="(true|false)",
  *     nullable=true,
  *     description="Should the section be treated as sibling of the reference section ?"
  * )
  */
 public function putWikiSectionAction(Wiki $wiki, Section $section, ParamFetcher $paramFetcher)
 {
     $this->checkAccess('EDIT', $wiki);
     // Adjust visibility
     $oldVisibility = $section->getVisible();
     $newVisibility = $paramFetcher->get('visible') === 'true';
     if ($oldVisibility !== $newVisibility) {
         $collection = $collection = new ResourceCollection([$wiki->getResourceNode()]);
         $isAdmin = $this->isUserGranted('EDIT', $wiki, $collection);
         $visible = $newVisibility && $wiki->getMode() === 0 || $newVisibility && $isAdmin;
         $section->setVisible($visible);
     }
     // Move section in the tree
     $referenceSectionId = $paramFetcher->get('referenceSectionId');
     $sectionRepository = $this->get('icap.wiki.section_repository');
     if ($referenceSectionId !== null) {
         $oldParent = $section->getParent();
         $oldLeft = $section->getLeft();
         $isBrother = $paramFetcher->get('isBrother') === 'true';
         $referenceSection = $this->getSection($wiki, $referenceSectionId);
         if ($isBrother && !$referenceSection->isRoot() && $referenceSection !== $oldLeft) {
             $sectionRepository->persistAsNextSiblingOf($section, $referenceSection);
             $newParent = $referenceSection->getParent();
             $changeSet = $section->getMoveEventChangeSet($oldParent, $oldLeft, $newParent);
             $this->dispatchSectionMoveEvent($wiki, $section, $changeSet);
         } elseif ($referenceSection !== $oldParent) {
             $sectionRepository->persistAsFirstChildOf($section, $referenceSection);
             $newParent = $referenceSection;
             $changeSet = $section->getMoveEventChangeSet($oldParent, $oldLeft, $newParent);
             $this->dispatchSectionMoveEvent($wiki, $section, $changeSet);
         }
     }
     // Save section in database
     $em = $this->getDoctrine()->getManager();
     $em->persist($section);
     $em->flush();
     $isAdmin = $this->isUserGranted('EDIT', $wiki);
     return ['section' => ['id' => $section->getId(), 'visible' => $section->getVisible(), 'parent' => $section->getParent()->getId(), 'left' => $section->getLeft()], 'sections' => $sectionRepository->buildSectionTree($wiki, $isAdmin, $this->getLoggedUser())];
 }