/**
  * Constructor.
  */
 public function __construct(WidgetInstance $widgetInstance, WidgetHomeTabConfig $whtc = null, WidgetDisplayConfig $wdc = null)
 {
     $workspace = $widgetInstance->getWorkspace();
     $widget = $widgetInstance->getWidget();
     $homeTab = !is_null($whtc) ? $whtc->getHomeTab() : null;
     $details = [];
     if (!is_null($homeTab)) {
         $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['workspaceId'] = $workspace->getId();
     $details['workspaceCode'] = $workspace->getCode();
     $details['workspaceName'] = $workspace->getName();
     $details['workspaceGuid'] = $workspace->getGuid();
     if (!is_null($whtc)) {
         $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, null, null, null, null, $workspace);
 }
 /**
  * @EXT\Route(
  *     "/api/home/tab/widget/{widgetInstance}/content/configure/form",
  *     name="api_get_widget_instance_content_configuration_form",
  *     options = {"expose"=true}
  * )
  * @EXT\ParamConverter("user", options={"authenticatedUser" = true})
  *
  * Returns the widget instance content configuration form
  */
 public function getWidgetInstanceContentConfigurationFormAction(WidgetInstance $widgetInstance)
 {
     $widget = $widgetInstance->getWidget();
     if ($widget->isConfigurable()) {
         $event = $this->eventDispatcher->dispatch("widget_{$widgetInstance->getWidget()->getName()}_configuration", new ConfigureWidgetEvent($widgetInstance));
         $content = $event->getContent();
     } else {
         $content = null;
     }
     return new JsonResponse($content);
 }
Exemplo n.º 3
0
 /**
  * @EXT\Route(
  *     "/widget/content/{widgetInstance}",
  *     name="claro_widget_content",
  *     options={"expose"=true}
  * )
  *
  * Asks a widget to render its content.
  *
  * @param WidgetInstance $widgetInstance
  *
  * @return Response
  */
 public function getWidgetContentAction(WidgetInstance $widgetInstance)
 {
     $event = $this->eventDispatcher->dispatch("widget_{$widgetInstance->getWidget()->getName()}", 'DisplayWidget', array($widgetInstance));
     return new Response($event->getContent());
 }
Exemplo n.º 4
0
 public function getDesktopWidgetList(WidgetInstance $instance)
 {
     $user = $this->container->get('security.token_storage')->getToken()->getUser();
     $em = $this->container->get('doctrine.orm.entity_manager');
     $hiddenConfigs = $em->getRepository('ClarolineCoreBundle:Log\\LogHiddenWorkspaceWidgetConfig')->findBy(array('user' => $user));
     $workspaceIds = array();
     foreach ($hiddenConfigs as $hiddenConfig) {
         $workspaceIds[] = $hiddenConfig->getWorkspaceId();
     }
     // Get manager and collaborator workspaces config
     /** @var \Claroline\CoreBundle\Entity\Workspace\Workspace[] $workspaces */
     $workspaces = $em->getRepository('ClarolineCoreBundle:Workspace\\Workspace')->findByUserAndRoleNamesNotIn($user, array('ROLE_WS_COLLABORATOR', 'ROLE_WS_MANAGER'), $workspaceIds);
     $configs = array();
     if (count($workspaces) > 0) {
         //add this method to the repository @see ligne 68
         $configs = $em->getRepository('ClarolineCoreBundle:Log\\LogWidgetConfig')->findByWorkspaces($workspaces);
     }
     $defaultInstance = $em->getRepository('ClarolineCoreBundle:Widget\\WidgetInstance')->findOneBy(array('widget' => $instance->getWidget(), 'isAdmin' => true, 'workspace' => null, 'user' => null, 'isDesktop' => false));
     $defaultConfig = $this->getLogConfig($defaultInstance);
     if ($defaultConfig === null) {
         $defaultConfig = new LogWidgetConfig();
         $defaultConfig->setRestrictions($this->container->get('claroline.log.manager')->getDefaultWorkspaceConfigRestrictions());
         $defaultConfig->setAmount(5);
     }
     // Complete missing configs
     foreach ($workspaces as $workspace) {
         $config = null;
         for ($i = 0, $countConfigs = count($configs); $i < $countConfigs && $config === null; ++$i) {
             $current = $configs[$i];
             if ($current->getWidgetInstance()->getWorkspace()->getId() == $workspace->getId()) {
                 $config = $current;
             }
         }
         if ($config === null) {
             $config = new LogWidgetConfig();
             $config->copy($defaultConfig);
             $widgetInstance = new WidgetInstance();
             $widgetInstance->setWorkspace($workspace);
             $config->setWidgetInstance($widgetInstance);
             $configs[] = $config;
         }
     }
     // Remove configs which hasAllRestriction
     $configsCleaned = array();
     $events = $this->container->get('claroline.event.manager')->getEvents(LogGenericEvent::DISPLAYED_WORKSPACE);
     foreach ($configs as $config) {
         if ($config->hasAllRestriction($events) === false) {
             $configsCleaned[] = $config;
         }
     }
     $configs = $configsCleaned;
     if (count($configs) === 0) {
         return null;
     }
     /** @var \CLaroline\CoreBundle\Repository\Log\LogRepository $logRepository */
     $logRepository = $em->getRepository('ClarolineCoreBundle:Log\\Log');
     $desktopConfig = $this->getLogConfig($instance);
     $desktopConfig = $desktopConfig === null ? $defaultConfig : $desktopConfig;
     $query = $logRepository->findLogsThroughConfigs($configs, $desktopConfig->getAmount());
     $logs = $query->getResult();
     $chartData = $logRepository->countByDayThroughConfigs($configs, $this->getDefaultRange());
     //List item delegation
     $views = $this->renderLogs($logs);
     return array('logs' => $logs, 'listItemViews' => $views, 'chartData' => $chartData, 'logAmount' => $desktopConfig->getAmount(), 'isDesktop' => true, 'title' => $this->container->get('translator')->trans('your_workspace_activity_overview', array(), 'platform'));
 }