本文整理汇总了PHP中Claroline\CoreBundle\Persistence\ObjectManager::getUnitOfWork方法的典型用法代码示例。如果您正苦于以下问题:PHP ObjectManager::getUnitOfWork方法的具体用法?PHP ObjectManager::getUnitOfWork怎么用?PHP ObjectManager::getUnitOfWork使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Claroline\CoreBundle\Persistence\ObjectManager
的用法示例。
在下文中一共展示了ObjectManager::getUnitOfWork方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testGetUnitOfWork
public function testGetUnitOfWork()
{
$oom = $this->mock('Doctrine\\ORM\\EntityManagerInterface');
$oom->shouldReceive('getUnitOfWork')->once()->andReturn('uow');
$om = new ObjectManager($oom);
$this->assertEquals('uow', $om->getUnitOfWork());
}
示例2: getNodeScheduledForInsert
/**
* Search a ResourceNode wich is persisted but not flushed yet
*
* @param Workspace $workspace
* @param $name
* @param ResourceNode $parent
*
* @return ResourceNode
*/
public function getNodeScheduledForInsert(Workspace $workspace, $name, $parent = null)
{
$scheduledForInsert = $this->om->getUnitOfWork()->getScheduledEntityInsertions();
$res = null;
foreach ($scheduledForInsert as $entity) {
if (get_class($entity) === 'Claroline\\CoreBundle\\Entity\\Resource\\ResourceNode') {
if ($entity->getWorkspace()->getCode() === $workspace->getCode() && $entity->getName() === $name && $entity->getParent() == $parent) {
return $entity;
}
}
}
return $res;
}
示例3: getTagFromIdentityMap
private function getTagFromIdentityMap($name)
{
$map = $this->objectManager->getUnitOfWork()->getIdentityMap();
if (!array_key_exists('Icap\\BlogBundle\\Entity\\Tag', $map)) {
return;
}
//so it was in the identityMap hey !
foreach ($map['Icap\\BlogBundle\\Entity\\Tag'] as $tag) {
if ($tag->getName() === $name) {
return $tag;
}
}
return;
}
示例4: getRightsFromIdentityMap
public function getRightsFromIdentityMap($roleName, ResourceNode $resourceNode)
{
$map = $this->om->getUnitOfWork()->getIdentityMap();
$result = null;
if (!array_key_exists('Claroline\\CoreBundle\\Entity\\Resource\\ResourceRights', $map)) {
return null;
}
//so it was in the identityMap hey !
foreach ($map['Claroline\\CoreBundle\\Entity\\Resource\\ResourceRights'] as $right) {
if ($right->getRole()->getName() === $roleName && $right->getResourceNode() === $resourceNode) {
$result = $right;
}
}
return $result;
}
示例5: importWorkspaces
/**
* Import a workspace list from a csv data.
*
* @param array $workspaces
*/
public function importWorkspaces(array $workspaces, $logger = null)
{
$this->om->clear();
$ds = DIRECTORY_SEPARATOR;
$i = 0;
$j = 0;
$workspaceModelManager = $this->container->get('claroline.manager.workspace_model_manager');
foreach ($workspaces as $workspace) {
$this->om->startFlushSuite();
$model = null;
$name = $workspace[0];
$code = $workspace[1];
$isVisible = $workspace[2];
$selfRegistration = $workspace[3];
$registrationValidation = $workspace[4];
$selfUnregistration = $workspace[5];
if (isset($workspace[6])) {
$user = $this->om->getRepository('ClarolineCoreBundle:User')->findOneByUsername($workspace[6]);
} else {
$user = $this->container->get('security.context')->getToken()->getUser();
}
if (isset($workspace[7])) {
$model = $this->om->getRepository('ClarolineCoreBundle:Model\\WorkspaceModel')->findOneByName($workspace[7]);
}
if ($model) {
$guid = $this->ut->generateGuid();
$workspace = new Workspace();
$this->createWorkspace($workspace);
$workspace->setName($name);
$workspace->setCode($code);
$workspace->setDisplayable($isVisible);
$workspace->setSelfRegistration($selfRegistration);
$workspace->setSelfUnregistration($selfUnregistration);
$workspace->setRegistrationValidation($registrationValidation);
$workspace->setGuid($guid);
$date = new \Datetime(date('d-m-Y H:i'));
$workspace->setCreationDate($date->getTimestamp());
$workspace->setCreator($user);
$workspaceModelManager->addDataFromModel($model, $workspace, $user, $errors);
} else {
//this should be changed later
$configuration = new Configuration($this->templateDir . $ds . 'default.zip');
$configuration->setWorkspaceName($name);
$configuration->setWorkspaceCode($code);
$configuration->setDisplayable($isVisible);
$configuration->setSelfRegistration($selfRegistration);
$configuration->setSelfUnregistration($registrationValidation);
$this->container->get('claroline.manager.transfert_manager')->createWorkspace($configuration, $user);
}
$i++;
$j++;
if ($i % self::MAX_WORKSPACE_BATCH_SIZE === 0) {
if ($logger) {
$logger(" [UOW size: " . $this->om->getUnitOfWork()->size() . "]");
}
$i = 0;
$this->om->forceFlush();
if ($logger) {
$logger(" Workspace {$j} ({$name}) being created");
}
$this->om->clear();
}
$this->om->endFlushSuite();
}
}
示例6: importWorkspaces
/**
* Import a workspace list from a csv data.
*
* @param array $workspaces
*/
public function importWorkspaces(array $workspaces, $logger = null, $update = false)
{
$i = 0;
$workspaceModelManager = $this->container->get('claroline.manager.workspace_model_manager');
foreach ($workspaces as $workspace) {
++$i;
$this->om->startFlushSuite();
$endDate = null;
$model = null;
$name = $workspace[0];
$code = $workspace[1];
$isVisible = $workspace[2];
$selfRegistration = $workspace[3];
$registrationValidation = $workspace[4];
$selfUnregistration = $workspace[5];
if (isset($workspace[6]) && trim($workspace[6]) !== '') {
$user = $this->om->getRepository('ClarolineCoreBundle:User')->findOneByUsername($workspace[6]);
} else {
$user = $this->container->get('security.context')->getToken()->getUser();
}
if (isset($workspace[7])) {
$model = $this->om->getRepository('ClarolineCoreBundle:Model\\WorkspaceModel')->findOneByName($workspace[7]);
}
if (isset($workspace[8])) {
$endDate = new \DateTime();
$endDate->setTimestamp($workspace[8]);
}
if ($update) {
$workspace = $this->getOneByCode($code);
if (!$workspace) {
//if the workspace doesn't exists, just keep going...
continue;
}
if ($logger) {
$logger('Updating ' . $code . ' (' . $i . '/' . count($workspaces) . ') ...');
}
} else {
$workspace = new Workspace();
}
$workspace->setName($name);
$workspace->setCode($code);
$workspace->setDisplayable($isVisible);
$workspace->setSelfRegistration($selfRegistration);
$workspace->setSelfUnregistration($selfUnregistration);
$workspace->setRegistrationValidation($registrationValidation);
$workspace->setCreator($user);
if ($endDate) {
$workspace->setEndDate($endDate);
}
if (!$update) {
if ($logger) {
$logger('Creating ' . $code . ' (' . $i . '/' . count($workspaces) . ') ...');
}
if ($model) {
$guid = $this->ut->generateGuid();
$this->createWorkspace($workspace);
$workspace->setGuid($guid);
$date = new \Datetime(date('d-m-Y H:i'));
$workspace->setCreationDate($date->getTimestamp());
$workspaceModelManager->addDataFromModel($model, $workspace, $user);
} else {
$template = new File($this->container->getParameter('claroline.param.default_template'));
$this->container->get('claroline.manager.transfer_manager')->createWorkspace($workspace, $template, true);
}
} else {
if ($model) {
$workspaceModelManager->updateDataFromModel($model, $workspace);
}
}
$this->om->persist($workspace);
$logger('UOW: ' . $this->om->getUnitOfWork()->size());
if ($i % 100 === 0) {
$this->om->forceFlush();
$user = $this->om->getRepository('ClarolineCoreBundle:User')->find($user->getId());
$this->om->merge($user);
$this->om->refresh($user);
}
}
$logger('Final flush...');
$this->om->endFlushSuite();
}