/** * Copy a resource node. * * @param \Claroline\CoreBundle\Entity\Resource\ResourceNode $node * @param \Claroline\CoreBundle\Entity\Resource\ResourceNode $newParent * @param \Claroline\CoreBundle\Entity\User $user * @param \Claroline\CoreBundle\Entity\Resource\ResourceNode $last * @param boolean $withRights * Defines if the rights of the copied node have to be created * @param array $rights * If defined, the copied node will have exactly the given rights * * @return \Claroline\CoreBundle\Entity\Resource\ResourceNode */ private function copyNode(ResourceNode $node, ResourceNode $newParent, User $user, $withRights = true, array $rights = array(), $index = null) { $newNode = $this->om->factory('Claroline\\CoreBundle\\Entity\\Resource\\ResourceNode'); $newNode->setResourceType($node->getResourceType()); $newNode->setCreator($user); $newNode->setWorkspace($newParent->getWorkspace()); $newNode->setParent($newParent); $newParent->addChild($newNode); $newNode->setName($this->getUniqueName($node, $newParent, true)); $newNode->setIcon($node->getIcon()); $newNode->setClass($node->getClass()); $newNode->setMimeType($node->getMimeType()); $newNode->setAccessibleFrom($node->getAccessibleFrom()); $newNode->setAccessibleUntil($node->getAccessibleUntil()); $newNode->setPublished($node->isPublished()); $newNode->setLicense($node->getLicense()); $newNode->setAuthor($node->getAuthor()); $newNode->setIndex($index); if ($withRights) { //if everything happens inside the same workspace and no specific rights have been given, //rights are copied if ($newParent->getWorkspace() === $node->getWorkspace() && count($rights) === 0) { $this->rightsManager->copy($node, $newNode); } else { //otherwise we use the parent rights or the given rights if not empty $this->setRights($newNode, $newParent, $rights); } } $this->om->persist($newNode); return $newNode; }
/** * @param integer|array $permissions * @param \Claroline\CoreBundle\Entity\Role $role * @param \Claroline\CoreBundle\Entity\Resource\ResourceNode $node * @param array $creations */ public function nonRecursiveCreation($permissions, Role $role, ResourceNode $node, array $creations = array()) { $rights = $this->om->factory('Claroline\\CoreBundle\\Entity\\Resource\\ResourceRights'); $rights->setRole($role); $rights->setResourceNode($node); $rights->setCreatableResourceTypes($creations); is_int($permissions) ? $rights->setMask($permissions) : $this->setPermissions($rights, $permissions); $this->om->persist($rights); $this->om->flush(); }
/** * Extract the files from a the template configuration array * * @param string $archpath * @param array $confTools * * @return array */ public function extractFiles($archpath, $confTools) { $extractPath = sys_get_temp_dir() . DIRECTORY_SEPARATOR . uniqid('claro_ws_tmp_', true); $archive = $this->om->factory('ZipArchive'); $archive->open($archpath); $archive->extractTo($extractPath); $realPaths = array(); if (isset($confTools['files'])) { foreach ($confTools['files'] as $path) { $realPaths[] = $extractPath . DIRECTORY_SEPARATOR . $path; } } return $realPaths; }
/** * @param \Claroline\CoreBundle\Entity\Tool\Tool $tool * @param \Claroline\CoreBundle\Entity\User $user * @param int $position * @param string $name * * @throws ToolPositionAlreadyOccupiedException */ public function addDesktopTool(Tool $tool, User $user, $position, $name, $type = 0) { $switchTool = $this->orderedToolRepo->findOneBy(['user' => $user, 'order' => $position, 'type' => $type]); if (!$switchTool) { $desktopTool = $this->om->factory('Claroline\\CoreBundle\\Entity\\Tool\\OrderedTool'); $desktopTool->setUser($user); $desktopTool->setTool($tool); $desktopTool->setOrder($position); $desktopTool->setName($name); $desktopTool->setVisibleInDesktop(true); $desktopTool->setType($type); $this->om->persist($desktopTool); $this->om->flush(); } elseif ($switchTool->getTool() === $tool) { $switchTool->setVisibleInDesktop(true); $this->om->flush(); } else { throw new ToolPositionAlreadyOccupiedException('A tool already exists at this position'); } }
/** * Creates a custom ResourceIcon entity from a File (wich should contain an image). * (for instance if the thumbnail of a resource is changed) * * @param File $file * @param Workspace $workspace (for the storage directory...) * * @return \Claroline\CoreBundle\Entity\Resource\ResourceIcon */ public function createCustomIcon(File $file, Workspace $workspace = null) { $this->om->startFlushSuite(); $extension = pathinfo($file->getFilename(), PATHINFO_EXTENSION); if (is_null($workspace)) { $dest = $this->thumbDir; $hashName = $this->ut->generateGuid() . "." . $extension; } else { $dest = $this->thumbDir . DIRECTORY_SEPARATOR . $workspace->getCode(); $hashName = $workspace->getCode() . DIRECTORY_SEPARATOR . $this->ut->generateGuid() . "." . $extension; } $file->move($dest, $hashName); //entity creation $icon = $this->om->factory('Claroline\\CoreBundle\\Entity\\Resource\\ResourceIcon'); $icon->setRelativeUrl("{$this->basepath}/{$hashName}"); $icon->setMimeType('custom'); $icon->setShortcut(false); $this->om->persist($icon); $this->createShortcutIcon($icon, $workspace); $this->om->endFlushSuite(); return $icon; }
public function testFactory() { $om = new ObjectManager($this->mock('Doctrine\\Common\\Persistence\\ObjectManager')); $this->assertInstanceOf('stdClass', $om->factory('stdClass')); }