docs: migrated the Reports component from the old docs to the new docs#238
docs: migrated the Reports component from the old docs to the new docs#238OfficialJhimmy wants to merge 11 commits intomautic:5.xfrom
Conversation
|
This pull request migrates over the documentation for the Reports Component in the reStructuredText (RST) format. It addresses #199. |
RCheesley
left a comment
There was a problem hiding this comment.
Thanks for making a start at this @OfficialJhimmy - there's a lot of Vale fixes to address and probably more lurking beneath your use of vale off.
Please remove all of those, and we'll tell you where to use it if it's absolutely necessary.
Shout if you need some help running Vale in your editor, it should have picked all of these up while you were typing!
| Example: HelloWorld Report Subscriber | ||
| ===================================== | ||
|
|
||
| .. vale on | ||
|
|
||
| Below is an example Plugin file located at ``plugins\HelloWorldBundle\EventListener\ReportSubscriber.php``. | ||
|
|
||
| This file subscribes to Report events and provides custom logic for adding new tables, columns, filters, and graphs. |
There was a problem hiding this comment.
This part is not available in the original version. Content-wise, is this correct?
There was a problem hiding this comment.
I don't know, one for @mautic/core-team to review.
There was a problem hiding this comment.
@mautic/core-team please refer to this live preview page for easy view:
https://mautic-developer--238.org.readthedocs.build/en/238/components/reports.html
And here's the original version:
https://github.com/mautic/developer-documentation/blob/main/source/includes/_plugin_extending_reports.md
| .. code-block:: php | ||
|
|
||
| namespace MauticPlugin\HelloWorldBundle\EventListener; | ||
|
|
||
| use Mautic\CoreBundle\EventListener\CommonSubscriber; | ||
| use Mautic\CoreBundle\Helper\GraphHelper; | ||
| use Mautic\ReportBundle\Event\ReportBuilderEvent; | ||
| use Mautic\ReportBundle\Event\ReportGeneratorEvent; | ||
| use Mautic\ReportBundle\Event\ReportGraphEvent; | ||
| use Mautic\ReportBundle\ReportEvents; | ||
| use Mautic\CoreBundle\Helper\Chart\ChartQuery; | ||
| use Mautic\CoreBundle\Helper\Chart\LineChart; | ||
|
|
||
| class ReportSubscriber extends CommonSubscriber | ||
| { | ||
| public static function getSubscribedEvents() | ||
| { | ||
| return [ | ||
| ReportEvents::REPORT_ON_BUILD => ['onReportBuilder', 0], | ||
| ReportEvents::REPORT_ON_GENERATE => ['onReportGenerate', 0], | ||
| ReportEvents::REPORT_ON_GRAPH_GENERATE => ['onReportGraphGenerate', 0], | ||
| ]; | ||
| } | ||
|
|
||
| public function onReportBuilder(ReportBuilderEvent $event) | ||
| { | ||
| if ($event->checkContext(['worlds'])) { | ||
| $prefix = 'w.'; | ||
| $columns = [ | ||
| $prefix . 'visit_count' => [ | ||
| 'label' => 'mautic.hellobundle.report.visit_count', | ||
| 'type' => 'int', | ||
| ], | ||
| $prefix . 'world' => [ | ||
| 'label' => 'mautic.hellobundle.report.world', | ||
| 'type' => 'text', | ||
| ], | ||
| ]; | ||
|
|
||
| $columns = $filters = array_merge( | ||
| $columns, | ||
| $event->getStandardColumns($prefix), | ||
| $event->getCategoryColumns() | ||
| ); | ||
|
|
||
| $filters[$prefix . 'world']['type'] = 'select'; | ||
| $filters[$prefix . 'world']['list'] = [ | ||
| 'earth' => 'Earth', | ||
| 'mars' => 'Mars', | ||
| ]; | ||
|
|
||
| $event->addTable('worlds', [ | ||
| 'display_name' => 'mautic.helloworld.worlds', | ||
| 'columns' => $columns, | ||
| 'filters' => $filters, | ||
| ]); | ||
|
|
||
| $event->addGraph('worlds', 'line', 'mautic.hellobundle.graph.line.visits'); | ||
| } | ||
| } | ||
|
|
||
| public function onReportGenerate(ReportGeneratorEvent $event) | ||
| { | ||
| $context = $event->getContext(); | ||
| if ($context == 'worlds') { | ||
| $qb = $event->getQueryBuilder(); | ||
| $qb->from(MAUTIC_TABLE_PREFIX . 'worlds', 'w'); | ||
| $event->addCategoryLeftJoin($qb, 'w'); | ||
| $event->setQueryBuilder($qb); | ||
| } | ||
| } | ||
|
|
||
| public function onReportGraphGenerate(ReportGraphEvent $event) | ||
| { | ||
| if (!$event->checkContext('worlds')) { | ||
| return; | ||
| } | ||
|
|
||
| $graphs = $event->getRequestedGraphs(); | ||
| $qb = $event->getQueryBuilder(); | ||
|
|
||
| foreach ($graphs as $graph) { | ||
| $queryBuilder = clone $qb; | ||
| $options = $event->getOptions($graph); | ||
| $chartQuery = clone $options['chartQuery']; | ||
| $chartQuery->applyDateFilters($queryBuilder, 'date_added', 'v'); | ||
|
|
||
| switch ($graph) { | ||
| case 'mautic.hellobundle.graph.line.visits': | ||
| $chart = new LineChart(null, $options['dateFrom'], $options['dateTo']); | ||
| $chartQuery->modifyTimeDataQuery($queryBuilder, 'date_added', 'v'); | ||
| $visits = $chartQuery->loadAndBuildTimeData($queryBuilder); | ||
| $chart->setDataset( | ||
| $options['translator']->trans('mautic.hellobundle.graph.line.visits'), | ||
| $visits | ||
| ); | ||
| $data = $chart->render(); | ||
| $data['name'] = $graph; | ||
| $data['iconClass'] = 'fa-tachometer'; | ||
| $event->setGraph($graph, $data); | ||
| break; | ||
| } | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
The code-block here is different with the original one. This one doesn't have comments. Do we want to follow the original or use this one?
Please refer to the original version here: https://github.com/mautic/developer-documentation/blob/main/source/includes/_plugin_extending_reports.md#extending-reports
There was a problem hiding this comment.
One for @mautic/core-team to discuss/review.
| To add and render custom Reports in Mautic, your Plugin needs to listen to three events: | ||
|
|
||
| * ``\Mautic\ReportBundle\ReportEvents::REPORT_ON_BUILD`` | ||
| * ``ReportEvents::REPORT_ON_GENERATE`` | ||
| * ``ReportEvents::REPORT_ON_GRAPH_GENERATE`` | ||
|
|
||
| This guide walks you through defining a custom Report, generating Report data, and rendering graphs. | ||
|
|
||
| .. vale off | ||
|
|
||
| Defining the Report | ||
| ******************* | ||
|
|
||
| .. vale on | ||
|
|
||
| Use the ``ReportEvents::REPORT_ON_BUILD`` event to define: | ||
|
|
||
| * The Report context | ||
| * Available columns | ||
| * Available filters - defaults to columns | ||
| * Available graphs |
There was a problem hiding this comment.
In the original version, there's no introduction.
Also, the Defining the Report section is different. Which one should we use? Please refer to original one here: https://github.com/mautic/developer-documentation/blob/main/source/includes/_plugin_extending_reports.md#defining-the-report
There was a problem hiding this comment.
For @mautic/core-team to review/consider.
There was a problem hiding this comment.
I don't understand the question. I also think this is getting too deep into the weeds of code. A developer (my personal view) rather study the actual code. Looks at the event class and knows exactly what it can do. I think it's OK to mention the event, but I wouldn't go too deep. The internal implementation changes in time and then it's hard to keep the docs up to date.
There was a problem hiding this comment.
I think the original poster elaborate the section more by adding an introduction. Would getting back to the original work better?
Here's the original version of this section:
https://github.com/mautic/developer-documentation/blob/main/source/includes/_plugin_extending_reports.md#defining-the-report
There was a problem hiding this comment.
Yep, I don't see an issue in the original
No description provided.