public function associateWorkspaceRolesByImport(Workspace $workspace, array $datas) { $this->om->startFlushSuite(); $i = 1; foreach ($datas as $data) { $username = $data[0]; $roleName = $data[1]; $user = $this->userRepo->findOneUserByUsername($username); $roles = $this->roleRepo->findRolesByWorkspaceCodeAndTranslationKey($workspace->getCode(), $roleName); if (!is_null($user) && count($roles) > 0) { $this->associateRoles($user, $roles); } if ($i % 100 === 0) { $this->om->forceFlush(); } $i++; } $this->om->endFlushSuite(); }
/** * 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; }
/** * Full workspace export. */ public function export(Workspace $workspace) { $this->log("Exporting {$workspace->getCode()}..."); foreach ($this->listImporters as $importer) { $importer->setListImporters($this->listImporters); } $data = []; $files = []; $data['parameters']['code'] = $workspace->getCode(); $data['parameters']['name'] = $workspace->getName(); $data['roles'] = $this->getImporterByName('roles')->export($workspace, $files, null); $data['tools'] = $this->getImporterByName('tools')->export($workspace, $files, null); $_resManagerData = []; foreach ($data['tools'] as &$_tool) { if ($_tool['tool']['type'] === 'resource_manager') { $_resManagerData =& $_tool['tool']; } } //then we parse and replace the text, we also add missing files in $resManagerData $files = $this->container->get('claroline.importer.rich_text_formatter')->setPlaceHolders($files, $_resManagerData); //throw new \Exception(); //generate the archive in a temp dir $content = Yaml::dump($data, 10); //zip and returns the archive $archDir = $this->container->get('claroline.config.platform_config_handler')->getParameter('tmp_dir') . DIRECTORY_SEPARATOR . uniqid(); $archPath = $archDir . DIRECTORY_SEPARATOR . 'archive.zip'; mkdir($archDir); $manifestPath = $archDir . DIRECTORY_SEPARATOR . 'manifest.yml'; file_put_contents($manifestPath, $content); $archive = new \ZipArchive(); $success = $archive->open($archPath, \ZipArchive::CREATE); if ($success === true) { $archive->addFile($manifestPath, 'manifest.yml'); foreach ($files as $uid => $file) { $archive->addFile($file, $uid); } $archive->close(); } else { throw new \Exception('Unable to create archive . ' . $archPath . ' (error ' . $success . ')'); } $this->container->get('claroline.core_bundle.listener.kernel_terminate_listener')->addElementToRemove($archPath); return $archPath; }
public function toArray(Workspace $workspace) { $data = array(); $data['id'] = $workspace->getId(); $data['name'] = $workspace->getName(); $data['code'] = $workspace->getCode(); $data['expiration_date'] = $workspace->getEndDate()->getTimeStamp(); return $data; }
public function createWidgetInstance($name, Widget $widget, HomeTab $homeTab, Workspace $workspace = null, $isAdmin = false, $isLocked = false) { $this->log("Create widget {$name} in {$workspace->getCode()}"); $widgetInstance = new WidgetInstance(); $widgetHomeTabConfig = new WidgetHomeTabConfig(); if ($workspace) { $type = 'workspace'; $isDesktop = false; } else { $type = 'user'; $isDesktop = true; } $widgetInstance->setWorkspace($workspace); $widgetInstance->setName($name); $widgetInstance->setIsAdmin($isAdmin); $widgetInstance->setIsDesktop($isDesktop); $widgetInstance->setWidget($widget); $widgetHomeTabConfig->setHomeTab($homeTab); $widgetHomeTabConfig->setWidgetInstance($widgetInstance); $widgetHomeTabConfig->setWorkspace($workspace); $widgetHomeTabConfig->setLocked($isLocked); $widgetHomeTabConfig->setWidgetOrder(1); $widgetHomeTabConfig->setType($type); $this->om->persist($widgetInstance); $this->om->persist($widgetHomeTabConfig); return $widgetInstance; }
public function getTabsScheduledForInsert(Workspace $workspace) { $scheduledForInsert = $this->om->getUnitOfWork()->getScheduledEntityInsertions(); $res = []; foreach ($scheduledForInsert as $entity) { if (get_class($entity) === 'Claroline\\CoreBundle\\Entity\\Home\\HomeTab') { if ($entity->getWorkspace()->getCode() === $workspace->getCode()) { $res[] = $entity; } } } return $res; }