Beispiel #1
0
 /**
  * Loads the core Home Tabs.
  *
  * @param ObjectManager $manager
  */
 public function load(ObjectManager $manager)
 {
     $translator = $this->container->get('translator');
     $infoName = $translator->trans('informations', array(), 'platform');
     $desktopHomeTab = new HomeTab();
     $desktopHomeTab->setType('admin_desktop');
     $desktopHomeTab->setName($infoName);
     $manager->persist($desktopHomeTab);
     $desktopHomeTabConfig = new HomeTabConfig();
     $desktopHomeTabConfig->setHomeTab($desktopHomeTab);
     $desktopHomeTabConfig->setType('admin_desktop');
     $desktopHomeTabConfig->setVisible(true);
     $desktopHomeTabConfig->setLocked(false);
     $desktopHomeTabConfig->setTabOrder(1);
     $manager->persist($desktopHomeTabConfig);
     $workspaceHomeTab = new HomeTab();
     $workspaceHomeTab->setType('admin_workspace');
     $workspaceHomeTab->setName($infoName);
     $manager->persist($workspaceHomeTab);
     $workspaceHomeTabConfig = new HomeTabConfig();
     $workspaceHomeTabConfig->setHomeTab($workspaceHomeTab);
     $workspaceHomeTabConfig->setType('admin_workspace');
     $workspaceHomeTabConfig->setVisible(true);
     $workspaceHomeTabConfig->setLocked(false);
     $workspaceHomeTabConfig->setTabOrder(1);
     $manager->persist($workspaceHomeTabConfig);
 }
 /**
  * Constructor.
  */
 public function __construct(HomeTab $homeTab, WidgetHomeTabConfig $whtc, WidgetDisplayConfig $wdc = null)
 {
     $widgetInstance = $whtc->getWidgetInstance();
     $widget = $widgetInstance->getWidget();
     $details = [];
     $details['tabId'] = $homeTab->getId();
     $details['tabName'] = $homeTab->getName();
     $details['tabType'] = $homeTab->getType();
     $details['tabIcon'] = $homeTab->getIcon();
     $details['widgetId'] = $widget->getId();
     $details['widgetName'] = $widget->getName();
     $details['widgetIsConfigurable'] = $widget->isConfigurable();
     $details['widgetIsExportable'] = $widget->isExportable();
     $details['widgetIsDisplayableInWorkspace'] = $widget->isDisplayableInWorkspace();
     $details['widgetIsDisplayableInDesktop'] = $widget->isDisplayableInDesktop();
     $details['id'] = $widgetInstance->getId();
     $details['name'] = $widgetInstance->getName();
     $details['icon'] = $widgetInstance->getIcon();
     $details['isAdmin'] = $widgetInstance->isAdmin();
     $details['isDesktop'] = $widgetInstance->isDesktop();
     $details['widgetHomeTabConfigId'] = $whtc->getId();
     $details['order'] = $whtc->getWidgetOrder();
     $details['type'] = $whtc->getType();
     $details['visible'] = $whtc->isVisible();
     $details['locked'] = $whtc->isLocked();
     if (!is_null($wdc)) {
         $details['widgetDisplayConfigId'] = $wdc->getId();
         $details['row'] = $wdc->getRow();
         $details['column'] = $wdc->getColumn();
         $details['width'] = $wdc->getWidth();
         $details['height'] = $wdc->getHeight();
         $details['color'] = $wdc->getColor();
     }
     parent::__construct(self::ACTION, $details);
 }
Beispiel #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;
 }
Beispiel #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();
 }
 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 checkAdminHomeTab(HomeTab $homeTab, $homeTabType)
 {
     if (!is_null($homeTab->getUser()) || !is_null($homeTab->getWorkspace()) || $homeTab->getType() !== 'admin_' . $homeTabType) {
         throw new AccessDeniedException();
     }
 }
 private function checkRoleAccessToHomeTab(HomeTab $homeTab)
 {
     $workspace = $homeTab->getWorkspace();
     $this->checkToolAccess($workspace);
     $canEdit = $this->hasWorkspaceEditionAccess($workspace);
     $homeTabRoles = $homeTab->getRoles();
     $hasAccess = $canEdit || count($homeTabRoles) === 0;
     if (!$hasAccess) {
         $userRoleNames = $this->utils->getRoles($this->tokenStorage->getToken());
         foreach ($homeTabRoles as $role) {
             $homeTabRoleName = $role->getName();
             if (in_array($homeTabRoleName, $userRoleNames)) {
                 $hasAccess = true;
                 break;
             }
         }
     }
     if (!$hasAccess) {
         $exception = new WorkspaceAccessDeniedException();
         $exception->setWorkspace($workspace);
         throw $exception;
     }
 }
 protected static function createWorkspaceHomeTab($name, Workspace $workspace)
 {
     $homeTab = new HomeTab();
     $homeTab->setName($name);
     $homeTab->setType('workspace');
     $homeTab->setWorkspace($workspace);
     self::create($name, $homeTab);
     self::$om->flush();
 }
 private function checkHomeTabEdition(HomeTab $homeTab, User $user)
 {
     $homeTabUser = $homeTab->getUser();
     $homeTabType = $homeTab->getType();
     if ($homeTabType !== 'desktop' || $user !== $homeTabUser) {
         throw new AccessDeniedException();
     }
 }
Beispiel #11
0
 private function checkWorkspaceAccessForHomeTab(HomeTab $homeTab, Workspace $workspace)
 {
     $homeTabWorkspace = $homeTab->getWorkspace();
     if (is_null($homeTabWorkspace) || $homeTabWorkspace->getId() !== $workspace->getId()) {
         throw new AccessDeniedException();
     }
 }