Exemplo n.º 1
0
 public function deleteSubtree(Section $section)
 {
     //Update deleted subtree
     $queryBuilder = $this->_em->createQueryBuilder();
     $queryBuilder->update('Icap\\WikiBundle\\Entity\\Section', 'section')->set('section.left', 0)->set('section.right', 0)->set('section.level', -1)->set('section.parent', '?1')->set('section.deleted', '?2')->set('section.deletionDate', '?3')->andWhere('section.root = :root')->andWhere($queryBuilder->expr()->gte('section.left', $section->getLeft()))->andWhere($queryBuilder->expr()->lte('section.right', $section->getRight()))->setParameter(1, null)->setParameter(2, true)->setParameter(3, new \DateTime('NOW'))->setParameter('root', $section->getRoot());
     $queryBuilder->getQuery()->getSingleScalarResult();
     $boundaryWidth = $section->getRight() - $section->getLeft() + 1;
     //Update boundaries (left and right) for all nodes after deleted node
     $queryBuilder = $this->_em->createQueryBuilder();
     $queryBuilder->update('Icap\\WikiBundle\\Entity\\Section', 'section')->set('section.right', 'section.right-?1')->andWhere('section.root = :root')->andWhere($queryBuilder->expr()->gt('section.right', $section->getRight()))->setParameter(1, $boundaryWidth)->setParameter('root', $section->getRoot());
     $queryBuilder->getQuery()->getSingleScalarResult();
     $queryBuilder = $this->_em->createQueryBuilder();
     $queryBuilder->update('Icap\\WikiBundle\\Entity\\Section', 'section')->set('section.left', 'section.left-?1')->andWhere('section.root = :root')->andWhere($queryBuilder->expr()->gt('section.left', $section->getRight()))->setParameter(1, $boundaryWidth)->setParameter('root', $section->getRoot());
     $queryBuilder->getQuery()->getSingleScalarResult();
 }
 /**
  * @param Wiki    $wiki
  * @param Section $section
  */
 public function __construct(Wiki $wiki, Section $section)
 {
     $details = array('section' => array('wiki' => $wiki->getId(), 'id' => $section->getId(), 'title' => $section->getActiveContribution()->getTitle(), 'text' => $section->getActiveContribution()->getText(), 'author' => $section->getAuthor()->getFirstName() . ' ' . $section->getAuthor()->getLastName()));
     parent::__construct($wiki->getResourceNode(), $details);
 }
 /**
  * @param Wiki    $wiki
  * @param Section $section
  * @param array   $changeSet
  */
 public function __construct(Wiki $wiki, Section $section, $changeSet)
 {
     $details = array('section' => array('wiki' => $wiki->getId(), 'id' => $section->getId(), 'title' => $section->getActiveContribution()->getTitle(), 'text' => $section->getActiveContribution()->getText(), 'visible' => $section->getVisible(), 'changeSet' => $changeSet));
     parent::__construct($wiki->getResourceNode(), $details);
 }
 /**
  * @param Wiki    $wiki
  * @param Section $section
  */
 public function __construct(Wiki $wiki, Section $section)
 {
     $this->wiki = $wiki;
     $this->details = array('section' => array('wiki' => $wiki->getId(), 'id' => $section->getId(), 'title' => $section->getActiveContribution()->getTitle(), 'text' => $section->getActiveContribution()->getText(), 'visible' => $section->getVisible()));
     parent::__construct($wiki->getResourceNode(), $this->details);
 }
Exemplo n.º 5
0
 /**
  * Returns the changeSet data when a section has been moved.
  *
  * @param Section $oldParent
  * @param int     $oldLeft
  * @param Section $newParent
  *
  * @return array $changeSet
  */
 public function getMoveEventChangeSet(Section $oldParent, $oldLeft, Section $newParent)
 {
     /* Create change set for move log event
      * If section's parent has changed, return old and new parent
      * Otherwise return old and new left to mark move up or down in the same parent
      */
     $newLeft = $this->getLeft();
     $changeSet = array('parentId' => array($oldParent->getId(), $newParent->getId()), 'parentName' => array($oldParent->getActiveContribution()->getTitle(), $newParent->getActiveContribution()->getTitle()), 'isParentRoot' => array($oldParent->isRoot(), $newParent->isRoot()), 'left' => array($oldLeft, $newLeft));
     return $changeSet;
 }
Exemplo n.º 6
0
 /**
  * Imports wiki object from array
  * (see WikiImporter for structure and description).
  *
  * @param array $data
  * @param $rootPath
  * @param $loggedUser
  *
  * @return Wiki
  */
 public function importWiki(array $data, $rootPath, $loggedUser)
 {
     $wiki = new Wiki();
     if (isset($data['data'])) {
         $wikiData = $data['data'];
         $wiki->setMode($wikiData['options']['mode']);
         $sectionsMap = array();
         foreach ($wikiData['sections'] as $section) {
             $entitySection = new Section();
             $entitySection->setWiki($wiki);
             $entitySection->setDeleted($section['deleted']);
             $entitySection->setDeletionDate($section['deletion_date']);
             $entitySection->setCreationDate($section['creation_date']);
             $author = null;
             if ($section['author'] !== null) {
                 $author = $this->userRepository->findOneByUsername($section['author']);
             }
             if ($author === null) {
                 $author = $loggedUser;
             }
             $entitySection->setAuthor($author);
             $parentSection = null;
             if ($section['parent_id'] !== null) {
                 $parentSection = $sectionsMap[$section['parent_id']];
                 $entitySection->setParent($parentSection);
             }
             if ($section['is_root']) {
                 $wiki->setRoot($entitySection);
                 $this->om->persist($wiki);
             }
             foreach ($section['contributions'] as $contribution) {
                 $contributionData = $contribution['contribution'];
                 $entityContribution = new Contribution();
                 $entityContribution->setSection($entitySection);
                 $entityContribution->setTitle($contributionData['title']);
                 $entityContribution->setCreationDate($contributionData['creation_date']);
                 $contributor = null;
                 if ($contributionData['contributor'] !== null) {
                     $contributor = $this->userRepository->findOneByUsername($contributionData['contributor']);
                 }
                 if ($contributor === null) {
                     $contributor = $loggedUser;
                 }
                 $entityContribution->setContributor($contributor);
                 $text = file_get_contents($rootPath . DIRECTORY_SEPARATOR . $contributionData['path']);
                 $entityContribution->setText($text);
                 if ($contributionData['is_active']) {
                     $entitySection->setActiveContribution($entityContribution);
                     if ($parentSection !== null) {
                         $this->sectionRepository->persistAsLastChildOf($entitySection, $parentSection);
                     } else {
                         $this->sectionRepository->persistAsFirstChild($entitySection);
                     }
                 }
                 $this->om->persist($entityContribution);
             }
             $sectionsMap[$section['id']] = $entitySection;
         }
     }
     return $wiki;
 }
 /**
  * @param Wiki         $wiki
  * @param Section      $section
  * @param Contribution $contribution
  */
 public function __construct(Wiki $wiki, Section $section, Contribution $contribution)
 {
     $this->wiki = $wiki;
     $this->details = array('contribution' => array('wiki' => $wiki->getId(), 'section' => $section->getId(), 'id' => $contribution->getId(), 'title' => $contribution->getTitle(), 'text' => $contribution->getText(), 'contributor' => $contribution->getContributor()->getFirstName() . ' ' . $contribution->getContributor()->getLastName()));
     parent::__construct($wiki->getResourceNode(), $this->details);
 }
Exemplo n.º 8
0
 /**
  * @ORM\PostPersist
  */
 public function createRoot(LifecycleEventArgs $event)
 {
     if ($this->getRoot() == null) {
         $em = $event->getEntityManager();
         $rootSection = $this->getRoot();
         if ($rootSection == null) {
             $rootSection = new Section();
             $rootSection->setWiki($this);
             if ($this->getResourceNode() !== null) {
                 $rootSection->setAuthor($this->getResourceNode()->getCreator());
             } else {
                 $rootSection->setAuthor($this->getWikiCreator());
             }
             $this->setRoot($rootSection);
             $em->getRepository('IcapWikiBundle:Section')->persistAsFirstChild($rootSection);
             $em->flush();
         }
     }
 }
Exemplo n.º 9
0
 /**
  * Obtain a diff between two contributions from the same section.
  *
  * @param Wiki    $wiki
  * @param Section $section
  * @param int     $oldContributionId
  * @param int     $newContributionId
  *
  * @return mixed[]
  *
  * @Get(
  *     "/api/wikis/{wiki}/sections/{section}/contributions/{oldContributionId}/{newContributionId}",
  *     name="icap_wiki_api_get_wiki_section_contribution_diff",
  *     requirements={ "wiki" = "\d+", "section" = "\d+", "oldContributionId" = "\d+", "newContribution  " = "\d+" },
  *     options = { "expose" = true }
  * )
  */
 public function getWikiSectionContributionDiff(Wiki $wiki, Section $section, $oldContributionId, $newContributionId)
 {
     $response = new JsonResponse();
     $data = ['response' => []];
     if ($section->getVisible() === true) {
         $contributions = $this->get('icap.wiki.contribution_manager')->compareContributions($section, [$oldContributionId, $newContributionId]);
         if (count($contributions) === 2) {
             $data = ['response' => [['title' => $contributions[0]->getTitle(), 'text' => $contributions[0]->getText(), 'contributor' => ['userName' => $contributions[0]->getContributor()->getUserName(), 'firstName' => $contributions[0]->getContributor()->getFirstName(), 'lastName' => $contributions[0]->getContributor()->getLastName()], 'creationDate' => $contributions[0]->getCreationDate()], ['title' => $contributions[1]->getTitle(), 'text' => $contributions[1]->getText(), 'contributor' => ['userName' => $contributions[1]->getContributor()->getUserName(), 'firstName' => $contributions[1]->getContributor()->getFirstName(), 'lastName' => $contributions[1]->getContributor()->getLastName()], 'creationDate' => $contributions[1]->getCreationDate()]]];
         }
     }
     return $response->setData($data);
 }