/** * @param FormBuilderInterface $builder * @param array $options */ public function buildForm(FormBuilderInterface $builder, array $options) { $choices = []; if ($reports = $this->model->getReportsWithGraphs()) { foreach ($reports as $report) { $choices[$report['name']] = []; $graphs = unserialize($report['graphs']); foreach ($graphs as $graph) { $graphValue = $report['id'] . ":" . $graph; $choices[$report['name']][$graphValue] = $graph; } } } // Build a list of data sources $builder->add('graph', 'choice', ['choices' => $choices, 'expanded' => false, 'multiple' => false, 'label' => 'mautic.report.report.form.choose_graphs', 'label_attr' => ['class' => 'control-label'], 'empty_value' => false, 'required' => false, 'attr' => ['class' => 'form-control']]); if (!empty($options["action"])) { $builder->setAction($options["action"]); } }
/** * Set a widget detail when needed * * @param WidgetDetailEvent $event * * @return void */ public function onWidgetDetailGenerate(WidgetDetailEvent $event) { $this->checkPermissions($event); if ($event->getType() == 'report') { $widget = $event->getWidget(); $params = $widget->getParams(); if (!$event->isCached()) { list($reportId, $graph) = explode(':', $params['graph']); $report = $this->model->getEntity($reportId); if ($report && $this->security->hasEntityAccess('report:reports:viewown', 'report:reports:viewother', $report->getCreatedBy())) { $reportData = $this->model->getReportData($report, null, ['ignoreTableData' => true, 'graphName' => $graph, 'dateFrom' => $params['dateFrom'], 'dateTo' => $params['dateTo']]); if (isset($reportData['graphs'][$graph])) { $graphData = $reportData['graphs'][$graph]; $event->setTemplateData(['chartData' => $graphData['data'], 'chartType' => $graphData['type'], 'chartHeight' => $widget->getHeight() - 90, 'reportId' => $report->getId(), 'dateFrom' => $params['dateFrom'], 'dateTo' => $params['dateTo']]); } } } $event->setTemplate('MauticReportBundle:SubscribedEvents\\Dashboard:widget.html.php'); $event->stopPropagation(); } }
/** * @param MauticEvents\CommandListEvent $event */ public function onBuildCommandList(MauticEvents\CommandListEvent $event) { if ($this->security->isGranted(['report:reports:viewown', 'report:reports:viewother'], 'MATCH_ONE')) { $event->addCommands('mautic.report.reports', $this->reportModel->getCommandList()); } }