/** * Set a widget detail when needed. * * @param WidgetDetailEvent $event */ public function onWidgetDetailGenerate(WidgetDetailEvent $event) { if ($event->getType() == 'recent.activity') { if (!$event->isCached()) { $height = $event->getWidget()->getHeight(); $limit = round(($height - 80) / 75); $logs = $this->auditLogModel->getLogForObject(null, null, null, $limit); // Get names of log's items foreach ($logs as $key => &$log) { if (!empty($log['bundle']) && !empty($log['object']) && !empty($log['objectId'])) { try { $model = $this->factory->getModel($log['bundle'] . '.' . $log['object']); $item = $model->getEntity($log['objectId']); if (method_exists($item, $model->getNameGetter())) { $log['objectName'] = $item->{$model->getNameGetter()}(); if ($log['bundle'] == 'lead' && $log['objectName'] == 'mautic.lead.lead.anonymous') { $log['objectName'] = $this->translator->trans('mautic.lead.lead.anonymous'); } } else { $log['objectName'] = ''; } $routeName = 'mautic_' . $log['bundle'] . '_action'; if ($this->router->getRouteCollection()->get($routeName) !== null) { $log['route'] = $this->router->generate('mautic_' . $log['bundle'] . '_action', ['objectAction' => 'view', 'objectId' => $log['objectId']]); } else { $log['route'] = false; } } catch (\Exception $e) { unset($logs[$key]); } } } $iconEvent = new IconEvent($this->security); $this->dispatcher->dispatch(CoreEvents::FETCH_ICONS, $iconEvent); $event->setTemplateData(['logs' => $logs, 'icons' => $iconEvent->getIcons()]); } $event->setTemplate('MauticDashboardBundle:Dashboard:recentactivity.html.php'); $event->stopPropagation(); } }
/** * 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); }
/** * Set a widget detail when needed * * @param WidgetDetailEvent $event * * @return void */ public function checkPermissions(WidgetDetailEvent $event) { $widgetTypes = array_keys($this->types); if ($this->permissions && !$event->hasPermissions($this->permissions) && in_array($event->getType(), $widgetTypes)) { $translator = $event->getTranslator(); $event->setErrorMessage($translator->trans('mautic.dashboard.missing.permission', array('%section%' => $this->bundle))); $event->stopPropagation(); return; } }