Exemplo n.º 1
0
 /**
  * @param \Claroline\CoreBundle\Entity\Resource\ResourceNode $directory
  * @param \Claroline\CoreBundle\Entity\Resource\ResourceNode $directoryCopy
  * @param \Claroline\CoreBundle\Entity\User $user
  * @param array $workspaceRoles
  */
 private function duplicateDirectoryContent(ResourceNode $directory, ResourceNode $directoryCopy, User $user, array $workspaceRoles)
 {
     $children = $directory->getChildren();
     $copies = array();
     $resourcesErrors = array();
     foreach ($children as $child) {
         try {
             $copy = $this->resourceManager->copy($child, $directoryCopy, $user, false, false);
             $copies[] = $copy;
         } catch (NotPopulatedEventException $e) {
             $resourcesErrors[] = array('resourceName' => $child->getName(), 'resourceType' => $child->getResourceType()->getName(), 'type' => 'copy', 'error' => $e->getMessage());
             continue;
         }
         /*** Copies rights ***/
         $this->duplicateRights($child, $copy->getResourceNode(), $workspaceRoles);
         /*** Recursive call for a directory ***/
         if ($child->getResourceType()->getName() === 'directory') {
             $errors = $this->duplicateDirectoryContent($child, $copy->getResourceNode(), $user, $workspaceRoles);
             $resourcesErrors = array_merge_recursive($resourcesErrors, $errors);
         }
     }
     $this->linkResourcesArray($copies);
     $this->om->flush();
     return $resourcesErrors;
 }
Exemplo n.º 2
0
 /**
  * @param ResourceNode $parent
  * @param integer      $index
  */
 public function shiftLeftAt(ResourceNode $parent, $index)
 {
     $nodes = $parent->getChildren();
     foreach ($nodes as $node) {
         if ($node->getIndex() <= $index) {
             $node->setIndex($node->getIndex());
         }
         $this->om->persist($node);
     }
     $this->om->flush();
 }