Esempio n. 1
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();
 }
Esempio n. 2
0
 /**
  * @EXT\Route(
  *     "/update_workspace_widget_config/{widgetInstance}",
  *     name="claro_log_update_workspace_widget_config"
  * )
  * @EXT\Method("POST")
  */
 public function updateLogWorkspaceWidgetConfig(WidgetInstance $widgetInstance)
 {
     if (!$this->authorization->isGranted('edit', $widgetInstance)) {
         throw new AccessDeniedException();
     }
     $config = $this->get('claroline.log.manager')->getLogConfig($widgetInstance);
     $form = $this->get('form.factory')->create($this->get('claroline.form.logWorkspaceWidgetConfig'), $config);
     $form->bind($this->getRequest());
     if ($form->isValid()) {
         if ($config) {
             $config->setAmount($form->get('amount')->getData());
             $config->setRestrictions($form->get('restrictions')->getData());
         } else {
             $config = new LogWidgetConfig();
             $config->setAmount($form->get('amount')->getData());
             $config->setRestrictions($form->get('restrictions')->getData());
             $config->setWidgetInstance($widgetInstance);
         }
     } else {
         return $this->render('ClarolineCoreBundle:Log:config_workspace_widget_form.html.twig', array('form' => $form->createView(), 'instance' => $widgetInstance));
     }
     $em = $this->get('doctrine.orm.entity_manager');
     $em->persist($config);
     $em->flush();
     return new Response('success', 204);
 }
Esempio n. 3
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);
 }