示例#1
0
 /**
  * Creates a widget instance.
  *
  * @param \Claroline\CoreBundle\Entity\Widget\Widget               $widget
  * @param boolean                                                  $isAdmin
  * @param boolean                                                  $isDesktop
  * @param \Claroline\CoreBundle\Entity\User                        $user
  * @param \Claroline\CoreBundle\Entity\Workspace\Workspace $ws
  *
  * @return \Claroline\CoreBundle\Entity\Widget\WidgetInstance
  *
  * @throws \Exception
  */
 public function createInstance(Widget $widget, $isAdmin, $isDesktop, User $user = null, Workspace $ws = null)
 {
     if (!$widget->isDisplayableInDesktop()) {
         if ($isDesktop || $user) {
             throw new \Exception("This widget doesn't support the desktop");
         }
     }
     if (!$widget->isDisplayableInWorkspace()) {
         if (!$isDesktop || $ws) {
             throw new \Exception("This widget doesn't support the workspace");
         }
     }
     $instance = new WidgetInstance($widget);
     $instance->setName($this->translator->trans($widget->getName(), array(), 'widget'));
     $instance->setIsAdmin($isAdmin);
     $instance->setIsDesktop($isDesktop);
     $instance->setWidget($widget);
     $instance->setUser($user);
     $instance->setWorkspace($ws);
     $this->om->persist($instance);
     $this->om->flush();
     return $instance;
 }
示例#2
0
 private function repairWorkspaceWidgetInstances()
 {
     $this->log('Repairing workspace widget instances...');
     $dql = '
         SELECT wic, wi FROM ClarolineCoreBundle:Widget\\WidgetHomeTabConfig wic
         JOIN wic.widgetInstance wi
         WHERE wic.type = \'workspace\'
         AND wi.workspace IS NULL
     ';
     $configs = $this->em->createQuery($dql)->getResult();
     foreach ($configs as $config) {
         $adminWidgetInstance = $config->getWidgetInstance();
         $workspaceWidgetInstance = new WidgetInstance();
         $workspaceWidgetInstance->setIsAdmin(false);
         $workspaceWidgetInstance->setIsDesktop(false);
         $workspaceWidgetInstance->setName($adminWidgetInstance->getName());
         $workspaceWidgetInstance->setWidget($adminWidgetInstance->getWidget());
         $workspaceWidgetInstance->setWorkspace($config->getWorkspace());
         $this->em->persist($workspaceWidgetInstance);
         $config->setWidgetInstance($workspaceWidgetInstance);
     }
     $this->em->flush();
 }
示例#3
0
 public function generateCopyOfAdminWorkspaceHomeTabs(Workspace $workspace)
 {
     $adminHomeTabConfigs = $this->homeTabConfigRepo->findAdminWorkspaceHomeTabConfigs();
     foreach ($adminHomeTabConfigs as $adminHomeTabConfig) {
         // Create HomeTab
         $adminHomeTab = $adminHomeTabConfig->getHomeTab();
         $homeTab = new HomeTab();
         $homeTab->setName($adminHomeTab->getName());
         $homeTab->setType('workspace');
         $homeTab->setWorkspace($workspace);
         $this->om->persist($homeTab);
         $this->om->flush();
         // Create HomeTabConfig
         $homeTabConfig = new HomeTabConfig();
         $homeTabConfig->setHomeTab($homeTab);
         $homeTabConfig->setWorkspace($workspace);
         $homeTabConfig->setType('workspace');
         $homeTabConfig->setVisible($adminHomeTabConfig->isVisible());
         $homeTabConfig->setLocked(false);
         $homeTabConfig->setTabOrder($adminHomeTabConfig->getTabOrder());
         $this->om->persist($homeTabConfig);
         // Create WidgetHomeTabConfig
         $adminWidgetHomeTabConfigs = $this->widgetHomeTabConfigRepo->findAdminWidgetConfigs($adminHomeTab);
         foreach ($adminWidgetHomeTabConfigs as $adminWidgetHomeTabConfig) {
             $widgetHomeTabConfig = new WidgetHomeTabConfig();
             $widgetHomeTabConfig->setHomeTab($homeTab);
             $adminWidgetInstance = $adminWidgetHomeTabConfig->getWidgetInstance();
             $workspaceWidgetInstance = new WidgetInstance();
             $workspaceWidgetInstance->setIsAdmin(false);
             $workspaceWidgetInstance->setIsDesktop(false);
             $workspaceWidgetInstance->setName($adminWidgetInstance->getName());
             $workspaceWidgetInstance->setWidget($adminWidgetInstance->getWidget());
             $workspaceWidgetInstance->setWorkspace($workspace);
             $this->om->persist($workspaceWidgetInstance);
             $widgetHomeTabConfig->setWidgetInstance($workspaceWidgetInstance);
             $widgetHomeTabConfig->setWorkspace($workspace);
             $widgetHomeTabConfig->setType('workspace');
             $widgetHomeTabConfig->setVisible($adminWidgetHomeTabConfig->isVisible());
             $widgetHomeTabConfig->setLocked(false);
             $widgetHomeTabConfig->setWidgetOrder($adminWidgetHomeTabConfig->getWidgetOrder());
             $this->om->persist($widgetHomeTabConfig);
         }
         $this->om->flush();
     }
 }
 /**
  * @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;
 }
示例#5
0
 private function reinitializeDesktopTabs()
 {
     $this->log('Reinitializing desktop tabs...');
     $this->conn->query("\n            DELETE FROM claro_home_tab\n            WHERE type IN ('desktop', 'admin_desktop')\n        ");
     $em = $this->container->get('doctrine.orm.entity_manager');
     $em->clear();
     // weird but needed...
     $widgetRepo = $em->getRepository('ClarolineCoreBundle:Widget\\Widget');
     $widgets = array('claroline_announcement_widget', 'my_workspaces');
     $users = $em->getRepository('ClarolineCoreBundle:User')->findAll();
     foreach ($users as $user) {
         $tab = new HomeTab();
         $tab->setName('Informations');
         $tab->setType('desktop');
         $tab->setUser($user);
         $em->persist($tab);
         $tabConfig = new HomeTabConfig();
         $tabConfig->setHomeTab($tab);
         $tabConfig->setType('desktop');
         $tabConfig->setTabOrder(1);
         $tabConfig->setUser($user);
         $em->persist($tabConfig);
         for ($i = 0, $count = count($widgets); $i < $count; ++$i) {
             $widget = $widgetRepo->findOneByName($widgets[$i]);
             $instance = new WidgetInstance($widget);
             $instance->setName($this->translator->trans($widget->getName(), array(), 'widget'));
             $instance->setIsAdmin(false);
             $instance->setIsDesktop(true);
             $instance->setWidget($widget);
             $instance->setUser($user);
             $em->persist($instance);
             $widgetTabConfig = new WidgetHomeTabConfig();
             $widgetTabConfig->setType('desktop');
             $widgetTabConfig->setHomeTab($tab);
             $widgetTabConfig->setWidgetInstance($instance);
             $widgetTabConfig->setWidgetOrder($i + 1);
             $widgetTabConfig->setUser($user);
             $em->persist($widgetTabConfig);
         }
     }
     $em->flush();
 }
示例#6
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;
     }
 }
 /**
  * @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);
     }
 }
 protected static function createWidgetInstance(Widget $widget, Workspace $workspace, $name, $isAdmin, $isDesktop)
 {
     $instance = new WidgetInstance();
     $instance->setIsAdmin($isAdmin);
     $instance->setIsDesktop($isDesktop);
     $instance->setName($name);
     $instance->setWorkspace($workspace);
     $instance->setWidget($widget);
     self::$om->persist($instance);
     self::$om->flush();
 }
示例#9
0
 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;
 }