예제 #1
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())];
 }