Displays home on Desktop.

@DI\Observe("open_tool_desktop_home")

@param DisplayToolEvent $event
189665
public function onDisplayDesktop(DisplayToolEvent $event)
    {
        $currentUser = $this->tokenStorage->getToken()->getUser();

        $allTabs = $this->finder->search(HomeTab::class, [
            'filters' => ['user' => $currentUser->getUuid()],
        ]);

        // Order tabs. We want :
        //   - Administration tabs to be at first
        //   - Tabs to be ordered by position
        // For this, we separate administration tabs and user ones, order them by position
        // and then concat all tabs with admin in first (I don't have a easier solution to achieve this)

        $adminTabs = [];
        $userTabs = [];
        foreach ($allTabs['data'] as $tab) {
            if (!empty($tab)) {
                // we use the define position for array keys for easier sort
                if (HomeTab::TYPE_ADMIN_DESKTOP === $tab['type']) {
                    $adminTabs[$tab['position']] = $tab;
                } else {
                    $userTabs[$tab['position']] = $tab;
                }
            }
        }

        // order tabs by position
        ksort($adminTabs);
        ksort($userTabs);

        // generate the final list of tabs
        $orderedTabs = array_merge(array_values($adminTabs), array_values($userTabs));

        // we rewrite tab position because an admin and a user tab may have the same position
        foreach ($orderedTabs as $index => &$tab) {
            $tab['position'] = $index;
        }

        $content = $this->templating->render(
            'ClarolineCoreBundle:tool:home.html.twig', [
                'editable' => true,
                'context' => [
                    'type' => Widget::CONTEXT_DESKTOP,
                ],
                'tabs' => $orderedTabs,
            ]
        );

        $event->setContent($content);
        $event->stopPropagation();
    }
502728
public function beforeRender($event)
    {
        $this->Controller->set('authUser', $this->Controller->authUser);

        // beforeRender-event
        $_event = new Event('Component.Manager.beforeRender', $this, [
        ]);
        $this->Controller->eventManager()->dispatch($_event);

        if ($this->isPrefix()) {
            $this->_runCallback("beforeRender", $event);

            // beforeRender-event with Prefix
            $this->_runEvent("beforeRender");
        }
    }
79996
public function onTopBarLeftMenuConfigureDesktopTool(ConfigureMenuEvent $event)
    {
        $user = $this->tokenStorage->getToken()->getUser();
        $tool = $event->getTool();

        if ($user !== 'anon.' && !is_null($tool)) {
            $toolName = $tool->getName();
            $translatedName = $this->translator->trans($toolName, array(), 'tools');
            $route = $this->router->generate(
                'claro_desktop_open_tool',
                array('toolName' => $toolName)
            );

            $menu = $event->getMenu();
            $menu->addChild(
                $translatedName,
                array('uri' => $route)
            )->setExtra('icon', 'fa fa-' . $tool->getClass())
            ->setExtra('title', $translatedName);

            return $menu;
        }
    }
859212
public function onCreatePropertyCondition(CreatePropertyConditionEvent $event)
    {
        if (!$this->scopeMatcher->currentScopeIsFrontend()) {
            return;
        }

        $meta = $event->getData();

        if ('conditionpropertyvalueis' !== $meta['type']) {
            return;
        }

        $metaModel = $event->getMetaModel();
        $attribute = $metaModel->getAttributeById($meta['attr_id']);
        if (!($attribute instanceof Checkbox)) {
            return;
        }

        if ((bool) $meta['value']) {
            $event->setInstance(new PropertyTrueCondition($attribute->getColName()));
            return;
        }
        $event->setInstance(new PropertyFalseCondition($attribute->getColName()));
    }
820003
public function onWorkspaceToolOpen(DisplayToolEvent $event)
    {
        $workspace = $event->getWorkspace();

        if (!$this->authorization->isGranted(['claroline_planned_notification_tool', 'OPEN'], $workspace)) {
            throw new AccessDeniedException();
        }
        $content = $this->templating->render(
            'ClarolinePlannedNotificationBundle:planned_notification_tool:tool_open.html.twig', [
                'workspace' => $workspace,
                'canEdit' => $this->authorization->isGranted(['claroline_planned_notification_tool', 'EDIT'], $workspace),
            ]
        );
        $event->setContent($content);
        // /    $event->stopPropagation();
    }
34898
public function onDisplayTool(OpenAdministrationToolEvent $event)
    {
        $workspaceTools = $this->toolManager->getAvailableWorkspaceTools();

        $content = $this->templating->render(
            'ClarolineCoreBundle:administration:workspaces.html.twig',
            [
                'parameters' => $this->parametersSerializer->serialize(),
                'tools' => array_map(function (Tool $tool) {
                    return ['name' => $tool->getName()];
                }, $workspaceTools),
                'models' => $this->finder->search(
                    Workspace::class,
                    ['filters' => ['model' => true]],
                    [Options::SERIALIZE_MINIMAL]
                ),
            ]
        );

        $event->setResponse(new Response($content));
        $event->stopPropagation();
    }
761546
public function onDesktopOpen(DisplayToolEvent $event)
    {
        $content = $this->templating->render(
            'ClarolineDashboardBundle:tool:dashboards.html.twig',
            []
        );
        $event->setContent($content);
    }
1191608
public function onOpenPlatformLogs(OpenAdministrationToolEvent $event)
    {
        $params = array();
        $params['_controller'] = 'ClarolineCoreBundle:Administration\Logs:logList';
        $params['page'] = 1;
        $this->redirect($params, $event);
    }
1059798
public function onPlatformContentItemAdd(PlatformContentItemEvent $event)
    {
        $event->addItem([
            'item' => 'portfolio',
            'label' => $this->translator->trans('portfolio', [], 'icap_portfolio'),
            'value' => $this->portfolioManager->countAll(),
        ]);
    }
283614
public function onDisplayWorkspaceResourceManager(DisplayToolEvent $event)
    {
        $event->setContent($this->resourceWorkspace($event->getWorkspace()->getId()));
    }
513779
public function onDisplayTool(OpenAdministrationToolEvent $event)
    {
        $content = $this->templating->render(
            'ClarolineCoreBundle:administration:users.html.twig', [
                // todo : put it in the async load of form
                'parameters' => $this->parametersSerializer->serialize(),
                'profile' => $this->profileSerializer->serialize(),
                'platformRoles' => $this->finder->search('Claroline\CoreBundle\Entity\Role', [
                    'filters' => ['type' => Role::PLATFORM_ROLE],
                ]),
            ]
        );

        $event->setResponse(new Response($content));
        $event->stopPropagation();
    }
137894
public function onDisplayTool(OpenAdministrationToolEvent $event)
    {
        $this->competencyManager->ensureHasScale();

        $content = $this->templating->render('HeVinciCompetencyBundle:administration:competencies.html.twig');

        $event->setResponse(new Response($content));
        $event->stopPropagation();
    }
933469
public function onDisplayWorkspace(DisplayToolEvent $event)
    {
        $orderedTabs = [];
        $workspace = $event->getWorkspace();

        $tabs = $this->finder->search(HomeTab::class, [
            'filters' => ['workspace' => $workspace->getUuid()],
        ]);

        // but why ? finder should never give you an empty row
        $tabs = array_filter($tabs['data'], function ($data) {
            return $data !== [];
        });

        foreach ($tabs as $tab) {
            $orderedTabs[$tab['position']] = $tab;
        }
        ksort($orderedTabs);

        $content = $this->templating->render(
            'ClarolineCoreBundle:tool:home.html.twig', [
                'workspace' => $workspace,
                'editable' => $this->authorization->isGranted(['home', 'edit'], $workspace),
                'context' => [
                    'type' => Widget::CONTEXT_WORKSPACE,
                    'data' => $this->serializer->serialize($workspace),
                ],
                'tabs' => array_values($orderedTabs),
            ]
        );

        $event->setContent($content);
        $event->stopPropagation();
    }
1271440
public function startup(Event $event) {
		$layout = $this->request->getSession()->read('Setup.layout');
		if ($layout) {
			$this->Controller->viewBuilder()->setLayout($layout);
		}
	}
769269
public function command(ConsoleCommandEvent $event)
    {
        /** @var BridgeCommand $command */
        $command = $event->getCommand();

        if (!in_array($command->getName(), $this->getSupportedCommands())) {
            return;
        }

        $command->setRegistry($this->registry);
    }
164183
public function display()
    {
        if (!$this->visible) {
            return;
        }

        parent::display();

        $flydown = $this->getCompositeWidget('action_flydown');
        foreach ($this->action_items as $item) {
            if ($item->visible) {
                if ($item instanceof SwatActionItemDivider) {
                    $flydown->addDivider();
                } else {
                    $flydown->addOption($item->id, $item->title);
                }
            }
        }

        // set the flydown back to its initial state (no persistence). The
        // flydown is never reset if there is a selected item and the selected
        // items has a widget with one or more messages.
        if (
            $this->auto_reset &&
            ($this->selected === null ||
                $this->selected->widget === null ||
                !$this->selected->widget->hasMessage())
        ) {
            $flydown->reset();
        }

        // select the current action item based upon the flydown value
        if (isset($this->action_items_by_id[$flydown->value])) {
            $this->selected = $this->action_items_by_id[$flydown->value];
        } else {
            $this->selected = null;
        }

        $div_tag = new SwatHtmlTag('div');
        $div_tag->id = $this->id;
        $div_tag->class = $this->getCSSClassString();
        $div_tag->open();

        echo '<div class="swat-actions-controls">';

        $label = new SwatHtmlTag('label');
        $label->for = $flydown->getFocusableHtmlId();
        $label->setContent(Swat::_('Action: '));
        $label->display();

        $flydown->display();
        echo ' ';
        $this->displayButton();

        echo '</div>';

        foreach ($this->action_items as $item) {
            if ($item->widget !== null) {
                $div = new SwatHtmlTag('div');

                $div->class =
                    $item == $this->selected ? 'swat-visible' : 'swat-hidden';

                $div->id = $this->id . '_' . $item->id;

                $div->open();
                $item->display();
                $div->close();
            }
        }

        echo '<div class="swat-actions-note">';
        echo Swat::_('Actions apply to checked items.');
        echo '</div>';

        $div_tag->close();

        Swat::displayInlineJavaScript($this->getInlineJavaScript());
    }
439769
public function onDisplayDesktopParameters(DisplayToolEvent $event)
    {
        $user = $this->tokenStorage->getToken()->getUser();

        if ('anon.' === $user) {
            throw new AccessDeniedException();
        }
        $toolsRolesConfig = $this->toolManager->getUserDesktopToolsConfiguration($user);
        $desktopTools = $this->finder->get(Tool::class)->find(
            ['isDisplayableInDesktop' => true],
            ['property' => 'name', 'direction' => 1]
        );
        $tools = [];

        foreach ($desktopTools as $desktopTool) {
            $toolName = $desktopTool->getName();

            if (!in_array($toolName, ToolsOptions::EXCLUDED_TOOLS)) {
                $tools[] = $desktopTool;
            }
        }
        $orderedTools = $this->toolManager->computeUserOrderedTools($user, $toolsRolesConfig);
        $toolsConfig = [];

        foreach ($orderedTools as $orderedTool) {
            $toolName = $orderedTool->getTool()->getName();
            $toolsConfig[$toolName] = [
                'visible' => $orderedTool->isVisibleInDesktop(),
                'locked' => $orderedTool->isLocked(),
            ];
        }

        $event->setContent(
            $this->templating->render(
                'ClarolineCoreBundle:tool\desktop\parameters:parameters.html.twig',
                [
                    'tools' => array_map(function (Tool $tool) {
                        return $this->serializer->serialize($tool);
                    }, $tools),
                    'toolsConfig' => 0 < count($toolsConfig) ? $toolsConfig : new \stdClass(),
                ]
            )
        );
    }