/**
  * Set the widget entity
  *
  * @param Widget $widget
  */
 public function setWidget(Widget $widget)
 {
     $this->widget = $widget;
     $params = $widget->getParams();
     // Set required params if undefined
     if (!isset($params['timeUnit'])) {
         $params['timeUnit'] = null;
     }
     if (!isset($params['amount'])) {
         $params['amount'] = null;
     }
     if (!isset($params['dateFormat'])) {
         $params['dateFormat'] = null;
     }
     if (!isset($params['filter'])) {
         $params['filter'] = array();
     }
     $widget->setParams($params);
     $this->setType($widget->getType());
     $this->setCacheTimeout($widget->getCacheTimeout());
 }
Beispiel #2
0
 /**
  * Load widget content from the onWidgetDetailGenerate event
  *
  * @param Widget $widget
  * @param array  $filter
  */
 public function populateWidgetContent(Widget &$widget, $filter = array())
 {
     $cacheDir = $this->factory->getParameter('cached_data_dir', $this->factory->getSystemPath('cache', true));
     $dispatcher = $this->factory->getDispatcher();
     if ($widget->getCacheTimeout() == null || $widget->getCacheTimeout() == -1) {
         $widget->setCacheTimeout($this->factory->getParameter('cached_data_timeout'));
     }
     // Merge global filter with widget params
     $widgetParams = $widget->getParams();
     $resultParams = array_merge($widgetParams, $filter);
     // Add the user timezone
     if (empty($resultParams['timezone'])) {
         $resultParams['timezone'] = $this->factory->getUser()->getTimezone();
     }
     // Clone the objects in param array to avoid reference issues if some subscriber changes them
     foreach ($resultParams as &$param) {
         if (is_object($param)) {
             $param = clone $param;
         }
     }
     $widget->setParams($resultParams);
     $event = new WidgetDetailEvent($this->translator);
     $event->setWidget($widget);
     $event->setCacheDir($cacheDir, $this->factory->getUser()->getId());
     $event->setSecurity($this->factory->getSecurity());
     $dispatcher->dispatch(DashboardEvents::DASHBOARD_ON_MODULE_DETAIL_GENERATE, $event);
 }