Example #1
0
 /**
  * @EXT\Route(
  *     "/update_desktop_widget_config/{widgetInstance}",
  *     name="claro_log_update_desktop_widget_config"
  * )
  * @EXT\Method("POST")
  */
 public function updateLogDesktopWidgetConfig(WidgetInstance $widgetInstance)
 {
     if (!$this->authorization->isGranted('edit', $widgetInstance)) {
         throw new AccessDeniedException();
     }
     $em = $this->getDoctrine()->getManager();
     $config = $this->get('claroline.log.manager')->getLogConfig($widgetInstance);
     if ($widgetInstance->isAdmin()) {
         $user = null;
         $hiddenConfigs = array();
         $workspaces = array();
     } else {
         $user = $this->tokenStorage->getToken()->getUser();
         $hiddenConfigs = $em->getRepository('ClarolineCoreBundle:Log\\LogHiddenWorkspaceWidgetConfig')->findBy(array('user' => $user));
         $workspaces = $this->workspaceManager->getWorkspacesByUserAndRoleNames($user, array('ROLE_WS_COLLABORATOR', 'ROLE_WS_MANAGER'));
     }
     $form = $this->get('form.factory')->create(new LogDesktopWidgetConfigType(), null, array('workspaces' => $workspaces));
     $form->bind($this->getRequest());
     if ($form->isValid()) {
         if (!$config) {
             $config = new LogWidgetConfig();
             $config->setWidgetInstance($widgetInstance);
         }
         $data = $form->getData();
         //remove all hiddenConfigs for user
         foreach ($hiddenConfigs as $hiddenConfig) {
             $em->remove($hiddenConfig);
         }
         $em->flush();
         foreach ($data as $workspaceId => $visible) {
             if ($workspaceId != 'amount' and $visible !== true) {
                 $hiddenConfig = new LogHiddenWorkspaceWidgetConfig();
                 $hiddenConfig->setUser($user);
                 $hiddenConfig->setWorkspaceId($workspaceId);
                 $em->persist($hiddenConfig);
             }
         }
         // save amount
         $config->setAmount($data['amount']);
         $em->persist($config);
         $em->flush();
     } else {
         return $this->render('ClarolineCoreBundle:Log:config_desktop_widget_form.html.twig', array('form' => $form->createView(), 'instance' => $widgetInstance));
     }
     return new Response('', 204);
 }
Example #2
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);
 }
Example #3
0
 /**
  * @DI\Observe("copy_widget_config_core_resource_logger")
  *
  * @param CopyWidgetConfigurationEvent $event
  */
 public function onCopyWidgetConfiguration(CopyWidgetConfigurationEvent $event)
 {
     $source = $event->getWidgetInstance();
     $copy = $event->getWidgetInstanceCopy();
     $widgetConfig = $this->logManager->getLogConfig($source);
     if (!is_null($widgetConfig)) {
         $widgetConfigCopy = new LogWidgetConfig();
         $widgetConfigCopy->setWidgetInstance($copy);
         $widgetConfigCopy->setAmount($widgetConfig->getAmount());
         $widgetConfigCopy->setRestrictions($widgetConfig->getRestrictions());
         $this->om->persist($widgetConfigCopy);
         $this->om->flush();
     }
     $event->validateCopy();
     $event->stopPropagation();
 }
 public function copy(LogWidgetConfig $source = null)
 {
     if ($source !== null) {
         $this->setRestrictions($source->getRestrictions());
         $this->setAmount($source->getAmount());
     }
 }