/**
  * @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;
 }
示例#2
0
 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;
     }
 }
示例#3
0
 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();
 }
 /**
  * @EXT\Route(
  *     "/api/admin/home/tab/{homeTab}/type/{homeTabType}/widget/create",
  *     name="api_post_admin_widget_instance_creation",
  *     options = {"expose"=true}
  * )
  * @EXT\ParamConverter("user", options={"authenticatedUser" = true})
  *
  * Creates a new widget instance
  */
 public function postAdminWidgetInstanceCreationAction(HomeTab $homeTab, $homeTabType = 'desktop')
 {
     $this->checkAdminHomeTab($homeTab, $homeTabType);
     $isDesktop = $homeTabType === 'desktop';
     $formType = new WidgetInstanceConfigType('admin', $this->bundles);
     $formType->enableApi();
     $form = $this->createForm($formType);
     $form->submit($this->request);
     if ($form->isValid()) {
         $formDatas = $form->getData();
         $widget = $formDatas['widget'];
         $color = $form->get('color')->getData();
         $textTitleColor = $form->get('textTitleColor')->getData();
         $locked = $form->get('locked')->getData();
         $visible = $form->get('visible')->getData();
         $widgetInstance = new WidgetInstance();
         $widgetHomeTabConfig = new WidgetHomeTabConfig();
         $widgetDisplayConfig = new WidgetDisplayConfig();
         $widgetInstance->setName($formDatas['name']);
         $widgetInstance->setWidget($widget);
         $widgetInstance->setIsAdmin(true);
         $widgetInstance->setIsDesktop($isDesktop);
         $widgetHomeTabConfig->setHomeTab($homeTab);
         $widgetHomeTabConfig->setWidgetInstance($widgetInstance);
         $widgetHomeTabConfig->setVisible($visible);
         $widgetHomeTabConfig->setLocked($locked);
         $widgetHomeTabConfig->setWidgetOrder(1);
         $widgetHomeTabConfig->setType('admin');
         $widgetDisplayConfig->setWidgetInstance($widgetInstance);
         $widgetDisplayConfig->setWidth($widget->getDefaultWidth());
         $widgetDisplayConfig->setHeight($widget->getDefaultHeight());
         $widgetDisplayConfig->setColor($color);
         $widgetDisplayConfig->setDetails(['textTitleColor' => $textTitleColor]);
         $this->widgetManager->persistWidgetConfigs($widgetInstance, $widgetHomeTabConfig, $widgetDisplayConfig);
         $event = new LogWidgetAdminCreateEvent($homeTab, $widgetHomeTabConfig, $widgetDisplayConfig);
         $this->eventDispatcher->dispatch('log', $event);
         $widgetDatas = ['config' => $this->serializer->serialize($widgetHomeTabConfig, 'json', SerializationContext::create()->setGroups(['api_widget'])), 'display' => $this->serializer->serialize($widgetDisplayConfig, 'json', SerializationContext::create()->setGroups(['api_widget'])), 'configurable' => $widget->isConfigurable()];
         return new JsonResponse($widgetDatas, 200);
     } else {
         $options = ['http_code' => 400, 'extra_parameters' => null, 'serializer_group' => 'api_widget'];
         return $this->apiManager->handleFormView('ClarolineCoreBundle:API:Widget\\widgetInstanceCreateForm.html.twig', $form, $options);
     }
 }
示例#5
0
 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;
 }