/** * @param \Claroline\CoreBundle\Entity\Workspace\Workspace $source * @param \Claroline\CoreBundle\Entity\Workspace\Workspace $workspace * @param array $homeTabs */ private function duplicateHomeTabs(Workspace $source, Workspace $workspace, array $homeTabs, $resourceInfos) { $this->om->startFlushSuite(); $homeTabConfigs = $this->homeTabManager->getHomeTabConfigsByWorkspaceAndHomeTabs($source, $homeTabs); $order = 1; $widgetCongigErrors = array(); $widgetDisplayConfigs = array(); foreach ($homeTabConfigs as $homeTabConfig) { $homeTab = $homeTabConfig->getHomeTab(); $widgetHomeTabConfigs = $homeTab->getWidgetHomeTabConfigs(); $wdcs = $this->widgetManager->getWidgetDisplayConfigsByWorkspaceAndWidgetHTCs($source, $widgetHomeTabConfigs->toArray()); foreach ($wdcs as $wdc) { $widgetInstanceId = $wdc->getWidgetInstance()->getId(); $widgetDisplayConfigs[$widgetInstanceId] = $wdc; } $newHomeTab = new HomeTab(); $newHomeTab->setType('workspace'); $newHomeTab->setWorkspace($workspace); $newHomeTab->setName($homeTab->getName()); $this->om->persist($newHomeTab); $newHomeTabConfig = new HomeTabConfig(); $newHomeTabConfig->setHomeTab($newHomeTab); $newHomeTabConfig->setWorkspace($workspace); $newHomeTabConfig->setType('workspace'); $newHomeTabConfig->setVisible($homeTabConfig->isVisible()); $newHomeTabConfig->setLocked($homeTabConfig->isLocked()); $newHomeTabConfig->setTabOrder($order); $this->om->persist($newHomeTabConfig); $order++; foreach ($widgetHomeTabConfigs as $widgetConfig) { $widgetInstance = $widgetConfig->getWidgetInstance(); $widgetInstanceId = $widgetInstance->getId(); $widget = $widgetInstance->getWidget(); $newWidgetInstance = new WidgetInstance(); $newWidgetInstance->setIsAdmin(false); $newWidgetInstance->setIsDesktop(false); $newWidgetInstance->setWorkspace($workspace); $newWidgetInstance->setWidget($widget); $newWidgetInstance->setName($widgetInstance->getName()); $this->om->persist($newWidgetInstance); $newWidgetConfig = new WidgetHomeTabConfig(); $newWidgetConfig->setType('workspace'); $newWidgetConfig->setWorkspace($workspace); $newWidgetConfig->setHomeTab($newHomeTab); $newWidgetConfig->setWidgetInstance($newWidgetInstance); $newWidgetConfig->setVisible($widgetConfig->isVisible()); $newWidgetConfig->setLocked($widgetConfig->isLocked()); $newWidgetConfig->setWidgetOrder($widgetConfig->getWidgetOrder()); $this->om->persist($newWidgetConfig); $newWidgetDisplayConfig = new WidgetDisplayConfig(); $newWidgetDisplayConfig->setWorkspace($workspace); $newWidgetDisplayConfig->setWidgetInstance($newWidgetInstance); if (isset($widgetDisplayConfigs[$widgetInstanceId])) { $newWidgetDisplayConfig->setColor($widgetDisplayConfigs[$widgetInstanceId]->getColor()); $newWidgetDisplayConfig->setRow($widgetDisplayConfigs[$widgetInstanceId]->getRow()); $newWidgetDisplayConfig->setColumn($widgetDisplayConfigs[$widgetInstanceId]->getColumn()); $newWidgetDisplayConfig->setWidth($widgetDisplayConfigs[$widgetInstanceId]->getWidth()); $newWidgetDisplayConfig->setHeight($widgetDisplayConfigs[$widgetInstanceId]->getHeight()); } else { $newWidgetDisplayConfig->setWidth($widget->getDefaultWidth()); $newWidgetDisplayConfig->setHeight($widget->getDefaultHeight()); } $this->om->persist($newWidgetDisplayConfig); if ($widget->isConfigurable()) { try { $this->dispatcher->dispatch('copy_widget_config_' . $widget->getName(), 'CopyWidgetConfiguration', array($widgetInstance, $newWidgetInstance, $resourceInfos)); } catch (NotPopulatedEventException $e) { $widgetCongigErrors[] = array('widgetName' => $widget->getName(), 'widgetInstanceName' => $widgetInstance->getName(), 'error' => $e->getMessage()); } } } } $this->om->endFlushSuite(); return $widgetCongigErrors; }
private function checkAdminAccessForWidgetDisplayConfig(WidgetDisplayConfig $wdc) { if (!is_null($wdc->getUser()) || !is_null($wdc->getWorkspace())) { throw new AccessDeniedException(); } }
public function import(array $array, $workspace) { $homeTabOrder = 1; foreach ($array['data'] as $tab) { $homeTab = new HomeTab(); $homeTab->setName($tab['tab']['name']); $homeTab->setWorkspace($this->getWorkspace()); $homeTab->setType('workspace'); $this->om->persist($homeTab); $homeTabConfig = new HomeTabConfig(); $homeTabConfig->setHomeTab($homeTab); $homeTabConfig->setType('workspace'); $homeTabConfig->setWorkspace($this->getWorkspace()); $homeTabConfig->setLocked(false); $homeTabConfig->setVisible(true); $homeTabConfig->setTabOrder($homeTabOrder); $this->om->persist($homeTabConfig); $this->container->get('claroline.manager.home_tab_manager')->insertHomeTabConfig($homeTabConfig); $widgetOrder = 1; foreach ($tab['tab']['widgets'] as $widget) { $widgetType = $this->om->getRepository('ClarolineCoreBundle:Widget\\Widget')->findOneByName($widget['widget']['type']); $widgetInstance = new WidgetInstance(); $widgetInstance->setName($widget['widget']['name']); $widgetInstance->setWidget($widgetType); $widgetInstance->setWorkspace($this->getWorkspace()); $widgetInstance->setIsAdmin(false); $widgetInstance->setIsDesktop(false); $this->om->persist($widgetInstance); $widgetConfig = new WidgetDisplayConfig(); if ($widget['widget']['row']) { $widgetConfig->setRow($widget['widget']['row']); } if ($widget['widget']['column']) { $widgetConfig->setColumn($widget['widget']['column']); } if ($widget['widget']['width']) { $widgetConfig->setWidth($widget['widget']['width']); } if ($widget['widget']['height']) { $widgetConfig->setHeight($widget['widget']['height']); } if ($widget['widget']['color']) { $widgetConfig->setColor($widget['widget']['color']); } $widgetConfig->setWorkspace($workspace); $widgetConfig->setWidgetInstance($widgetInstance); $this->om->persist($widgetConfig); $widgetHomeTabConfig = new WidgetHomeTabConfig(); $widgetHomeTabConfig->setWidgetInstance($widgetInstance); $widgetHomeTabConfig->setHomeTab($homeTab); $widgetHomeTabConfig->setWorkspace($this->getWorkspace()); $widgetHomeTabConfig->setType('workspace'); $widgetHomeTabConfig->setVisible(true); $widgetHomeTabConfig->setLocked(false); $widgetHomeTabConfig->setWidgetOrder($widgetOrder); $this->om->persist($widgetHomeTabConfig); $importer = $this->getImporterByName($widget['widget']['type']); if (isset($widget['widget']['data']) && $importer) { $widgetdata = $widget['widget']['data']; $importer->import($widgetdata, $widgetInstance); } ++$widgetOrder; } ++$homeTabOrder; } }
private function checkWorkspaceWidgetDisplayConfig(Workspace $workspace, WidgetDisplayConfig $wdc) { $htWorkspace = $wdc->getWorkspace(); if ($workspace !== $htWorkspace) { $exception = new WorkspaceAccessDeniedException(); $exception->setWorkspace($workspace); throw $exception; } }
private function checkWidgetDisplayConfigEdition(User $authenticatedUser, WidgetDisplayConfig $wdc) { $user = $wdc->getUser(); if ($authenticatedUser !== $user) { throw new AccessDeniedException(); } }
public function importTextFromCsv($file) { $data = file_get_contents($file); $data = $this->container->get('claroline.utilities.misc')->formatCsvOutput($data); $lines = str_getcsv($data, PHP_EOL); $textWidget = $this->om->getRepository('ClarolineCoreBundle:Widget\\Widget')->findOneByName('simple_text'); $this->om->startFlushSuite(); $i = 0; foreach ($lines as $line) { $values = str_getcsv($line, ';'); $code = $values[0]; $workspace = $this->om->getRepository('ClarolineCoreBundle:Workspace\\Workspace')->findOneByCode($code); $name = $values[1]; $title = $values[2]; $width = isset($values[4]) ? $values[4] : 4; $height = isset($values[5]) ? $values[5] : 3; $tab = $this->om->getRepository('ClarolineCoreBundle:Home\\HomeTab')->findOneBy(['workspace' => $workspace, 'name' => $name]); $widgetHomeTabConfig = $this->om->getRepository('ClarolineCoreBundle:Widget\\WidgetHomeTabConfig')->findByWorkspaceAndHomeTabAndWidgetInstanceName($workspace, $tab, $title); if (!$widgetHomeTabConfig) { $widgetInstance = $this->createWidgetInstance($title, $textWidget, $tab, $workspace); } else { $this->log("Widget {$title} already exists in workspace {$code}: Updating..."); $widgetInstance = $widgetHomeTabConfig->getWidgetInstance(); } $simpleTextConfig = $this->container->get('claroline.manager.simple_text_manager')->getTextConfig($widgetInstance); if (!$simpleTextConfig) { $simpleTextConfig = new SimpleTextConfig(); $simpleTextConfig->setWidgetInstance($widgetInstance); } $widgetDisplayConfigs = $widgetInstance->getWidgetDisplayConfigs(); $widgetDisplayConfig = $widgetDisplayConfigs[0]; if (!$widgetDisplayConfig) { $widgetDisplayConfig = new WidgetDisplayConfig(); $widgetDisplayConfig->setWidgetInstance($widgetInstance); $widgetDisplayConfig->setWorkspace($workspace); $widgetDisplayConfig->setWidth($width); $widgetDisplayConfig->setHeight($height); $this->om->persist($widgetDisplayConfig); } $widgetDisplayConfig->setHeight($height); $widgetDisplayConfig->setWidth($width); $this->om->persist($widgetDisplayConfig); $content = file_get_contents($values[3]); $simpleTextConfig->setContent($content); $this->om->persist($simpleTextConfig); ++$i; if ($i % 100 === 0) { $this->om->forceFlush(); $this->om->clear(); $textWidget = $this->om->getRepository('ClarolineCoreBundle:Widget\\Widget')->findOneByName('simple_text'); $this->om->merge($textWidget); } } $this->om->endFlushSuite(); }
private function checkWorkspaceAccessForWidgetDisplayConfig(WidgetDisplayConfig $widgetDisplayConfig, Workspace $workspace) { $widgetDisplayConfigWorkspace = $widgetDisplayConfig->getWorkspace(); if (is_null($widgetDisplayConfigWorkspace) || $widgetDisplayConfigWorkspace->getId() !== $workspace->getId()) { throw new AccessDeniedException(); } }
public function generateWidgetDisplayConfigsForAdmin(array $widgetHTCs) { $results = array(); $widgetInstances = array(); $adminTab = array(); foreach ($widgetHTCs as $htc) { $widgetInstances[] = $htc->getWidgetInstance(); } $adminWDCs = $this->getWidgetDisplayConfigsByWidgetsForAdmin($widgetInstances); foreach ($adminWDCs as $wdc) { $widgetInstanceId = $wdc->getWidgetInstance()->getId(); $adminTab[$widgetInstanceId] = $wdc; } $this->om->startFlushSuite(); foreach ($widgetInstances as $widgetInstance) { $id = $widgetInstance->getId(); if (isset($adminTab[$id])) { $results[$id] = $adminTab[$id]; } else { $widget = $widgetInstance->getWidget(); $wdc = new WidgetDisplayConfig(); $wdc->setWidgetInstance($widgetInstance); $wdc->setWidth($widget->getDefaultWidth()); $wdc->setHeight($widget->getDefaultHeight()); $this->om->persist($wdc); $results[$id] = $wdc; } } $this->om->endFlushSuite(); return $results; }