本文整理汇总了PHP中Claroline\CoreBundle\Persistence\ObjectManager::factory方法的典型用法代码示例。如果您正苦于以下问题:PHP ObjectManager::factory方法的具体用法?PHP ObjectManager::factory怎么用?PHP ObjectManager::factory使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Claroline\CoreBundle\Persistence\ObjectManager
的用法示例。
在下文中一共展示了ObjectManager::factory方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: copyNode
/**
* 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;
}
示例2: nonRecursiveCreation
/**
* @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();
}
示例3: extractFiles
/**
* 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;
}
示例4: addDesktopTool
/**
* @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');
}
}
示例5: createCustomIcon
/**
* 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;
}
示例6: testFactory
public function testFactory()
{
$om = new ObjectManager($this->mock('Doctrine\\Common\\Persistence\\ObjectManager'));
$this->assertInstanceOf('stdClass', $om->factory('stdClass'));
}