Ejemplo n.º 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;
 }
Ejemplo n.º 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();
 }
Ejemplo n.º 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();
     }
 }
Ejemplo n.º 4
0
 /**
  * @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;
 }
Ejemplo n.º 5
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/workspace/home/tab/{homeTab}/widget/create",
  *     name="api_post_workspace_widget_instance_creation",
  *     options = {"expose"=true}
  * )
  *
  * Creates a new widget instance
  */
 public function postWorkspaceWidgetInstanceCreationAction(HomeTab $homeTab)
 {
     $workspace = $homeTab->getWorkspace();
     $this->checkToolEditionAccess($homeTab->getWorkspace());
     $formType = new WidgetInstanceConfigType('workspace', $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();
         $visible = $form->get('visible')->getData();
         $widgetInstance = new WidgetInstance();
         $widgetHomeTabConfig = new WidgetHomeTabConfig();
         $widgetDisplayConfig = new WidgetDisplayConfig();
         $widgetInstance->setName($formDatas['name']);
         $widgetInstance->setWidget($widget);
         $widgetInstance->setIsAdmin(false);
         $widgetInstance->setIsDesktop(false);
         $widgetInstance->setWorkspace($workspace);
         $widgetHomeTabConfig->setHomeTab($homeTab);
         $widgetHomeTabConfig->setWidgetInstance($widgetInstance);
         $widgetHomeTabConfig->setVisible($visible);
         $widgetHomeTabConfig->setWidgetOrder(1);
         $widgetHomeTabConfig->setType('workspace');
         $widgetHomeTabConfig->setWorkspace($workspace);
         $widgetDisplayConfig->setWidgetInstance($widgetInstance);
         $widgetDisplayConfig->setWorkspace($workspace);
         $widgetDisplayConfig->setWidth($widget->getDefaultWidth());
         $widgetDisplayConfig->setHeight($widget->getDefaultHeight());
         $widgetDisplayConfig->setColor($color);
         $widgetDisplayConfig->setDetails(['textTitleColor' => $textTitleColor]);
         $this->widgetManager->persistWidgetConfigs($widgetInstance, $widgetHomeTabConfig, $widgetDisplayConfig);
         $event = new LogWidgetWorkspaceCreateEvent($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);
     }
 }
Ejemplo n.º 7
0
 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();
 }
Ejemplo n.º 8
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;
 }
Ejemplo n.º 9
0
 public function getWorkspaceWidgetList(WidgetInstance $instance)
 {
     $workspace = $instance->getWorkspace();
     if (!$this->isAllowedToViewLogs($workspace)) {
         return null;
     }
     $em = $this->container->get('doctrine.orm.entity_manager');
     /** @var \Claroline\CoreBundle\Repository\Log\LogRepository $repository */
     $repository = $em->getRepository('ClarolineCoreBundle:Log\\Log');
     $config = $this->getLogConfig($instance);
     if ($config === null) {
         $defaultConfig = $em->getRepository('ClarolineCoreBundle:Widget\\WidgetInstance')->findOneBy(array('isDesktop' => false, 'isAdmin' => true));
         $config = new LogWidgetConfig();
         if ($defaultConfig !== null) {
             $config->copy($this->getLogConfig($defaultConfig));
         }
         $config->setRestrictions($this->container->get('claroline.log.manager')->getDefaultWorkspaceConfigRestrictions());
         $widgetInstance = new WidgetInstance();
         $widgetInstance->setWorkspace($workspace);
         $config->setWidgetInstance($widgetInstance);
     }
     /** @var \Claroline\CoreBundle\Manager\EventManager $eventManager */
     $eventManager = $this->container->get('claroline.event.manager');
     if ($config->hasNoRestriction()) {
         return null;
     }
     $query = $repository->findLogsThroughConfigs(array($config), $config->getAmount());
     $logs = $query->getResult();
     $chartData = $repository->countByDayThroughConfigs(array($config), $this->getDefaultRange());
     //List item delegation
     $views = $this->renderLogs($logs);
     $workspaceEvents = $eventManager->getEvents(LogGenericEvent::DISPLAYED_WORKSPACE);
     if ($config->hasAllRestriction(count($workspaceEvents))) {
         $title = $this->container->get('translator')->trans('recent_all_workspace_activities_overview', array('%workspaceName%' => $workspace->getName()), 'platform');
     } else {
         $title = $this->container->get('translator')->trans('Overview of recent activities in %workspaceName%', array('%workspaceName%' => $workspace->getName()), 'platform');
     }
     return array('logs' => $logs, 'listItemViews' => $views, 'chartData' => $chartData, 'workspace' => $workspace, 'logAmount' => $config->getAmount(), 'title' => $title, 'isDesktop' => false);
 }