當前位置: 首頁>>代碼示例>>PHP>>正文


PHP ObjectManager::refresh方法代碼示例

本文整理匯總了PHP中Claroline\CoreBundle\Persistence\ObjectManager::refresh方法的典型用法代碼示例。如果您正苦於以下問題:PHP ObjectManager::refresh方法的具體用法?PHP ObjectManager::refresh怎麽用?PHP ObjectManager::refresh使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Claroline\CoreBundle\Persistence\ObjectManager的用法示例。


在下文中一共展示了ObjectManager::refresh方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: 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();
 }
開發者ID:claroline,項目名稱:distribution,代碼行數:86,代碼來源:WorkspaceManager.php


注:本文中的Claroline\CoreBundle\Persistence\ObjectManager::refresh方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。