Exemplo n.º 1
0
 public function import(array $data, WidgetInstance $widgetInstance)
 {
     $widgetText = new SimpleTextConfig();
     $content = '';
     if ($data[0]['content']) {
         $content = file_get_contents($this->getRootPath() . DIRECTORY_SEPARATOR . $data[0]['content']);
     }
     $widgetText->setContent($content);
     $widgetText->setWidgetInstance($widgetInstance);
     $this->om->persist($widgetText);
     $this->om->flush();
 }
 /**
  * @EXT\Route(
  *     "/simple_text_update/config/{widget}",
  *     name="claro_simple_text_update_config"
  * )
  * @EXT\Method("POST")
  */
 public function updateSimpleTextWidgetConfig(WidgetInstance $widget, Request $request)
 {
     if (!$this->get('security.authorization_checker')->isGranted('edit', $widget)) {
         throw new AccessDeniedException();
     }
     $simpleTextConfig = $this->get('claroline.manager.simple_text_manager')->getTextConfig($widget);
     //wtf !
     $keys = array_keys($request->request->all());
     $id = array_pop($keys);
     $form = $this->get('form.factory')->create(new SimpleTextType($id));
     $form->bind($this->getRequest());
     if ($form->isValid()) {
         $formDatas = $form->get('content')->getData();
         $content = is_null($formDatas) ? '' : $formDatas;
         if ($simpleTextConfig) {
             $simpleTextConfig->setContent($content);
         } else {
             $simpleTextConfig = new SimpleTextConfig();
             $simpleTextConfig->setWidgetInstance($widget);
             $simpleTextConfig->setContent($content);
         }
     } else {
         $simpleTextConfig = new SimpleTextConfig();
         $simpleTextConfig->setWidgetInstance($widget);
         $errorForm = $this->container->get('form.factory')->create(new SimpleTextType('widget_text_' . rand(0, 1000000000)), $simpleTextConfig);
         $errorForm->setData($form->getData());
         $children = $form->getIterator();
         $errorChildren = $errorForm->getIterator();
         foreach ($children as $key => $child) {
             $errors = $child->getErrors();
             foreach ($errors as $error) {
                 $errorChildren[$key]->addError($error);
             }
         }
         return $this->render('ClarolineCoreBundle:Widget:config_simple_text_form.html.twig', array('form' => $errorForm->createView(), 'config' => $widget));
     }
     $em = $this->get('doctrine.orm.entity_manager');
     $em->persist($simpleTextConfig);
     $em->flush();
     return new Response('success', 204);
 }
 /**
  * @DI\Observe("copy_widget_config_simple_text")
  *
  * @param CopyWidgetConfigurationEvent $event
  */
 public function onCopyWidgetConfiguration(CopyWidgetConfigurationEvent $event)
 {
     $source = $event->getWidgetInstance();
     $copy = $event->getWidgetInstanceCopy();
     $widgetConfig = $this->simpleTextManager->getTextConfig($source);
     if (!is_null($widgetConfig)) {
         $widgetConfigCopy = new SimpleTextConfig();
         $widgetConfigCopy->setWidgetInstance($copy);
         $content = $this->replaceResourceLinks($widgetConfig->getContent(), $event->getResourceInfos());
         $widgetConfigCopy->setContent($this->replaceTabsLinks($content, $event->getTabsInfos()));
         $this->om->persist($widgetConfigCopy);
         $this->om->flush();
     }
     $event->validateCopy();
     $event->stopPropagation();
 }
Exemplo n.º 4
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();
 }