Example #1
0
 function it_renders_data_with_given_configuration(ReportInterface $report, Data $reportData, $templating)
 {
     $reportData->getData()->willReturn(array('month1' => '50', 'month2' => '40'));
     $renderData = array('report' => $report, 'values' => array('month1' => '50', 'month2' => '40'), 'labels' => array('month1', 'month2'));
     $report->getRendererConfiguration()->willReturn(array('template' => 'SyliusReportBundle:Chart:default.html.twig'));
     $templating->render('SyliusReportBundle:Chart:default.html.twig', array('data' => $renderData, 'configuration' => array('template' => 'SyliusReportBundle:Chart:default.html.twig')))->willReturn('<div>Chart Report</div>');
     $this->render($report, $reportData)->shouldReturn('<div>Chart Report</div>');
 }
Example #2
0
 /**
  * {@inheritdoc}
  */
 public function render(ReportInterface $report, Data $data)
 {
     if (null !== $data->getData()) {
         $data = array('report' => $report, 'values' => $data->getData(), 'labels' => $data->getLabels(), 'fields' => array_keys($data->getData()));
         $rendererConfiguration = $report->getRendererConfiguration();
         return $this->templating->render($rendererConfiguration["template"], array('data' => $data, 'configuration' => $rendererConfiguration));
     }
     return $this->templating->render("SyliusReportBundle::noDataTemplate.html.twig", array('report' => $report));
 }
Example #3
0
 /**
  * {@inheritdoc}
  */
 public function render(ReportInterface $report, Data $data)
 {
     if (null !== $data->getData()) {
         $rendererData = ['report' => $report, 'values' => $data->getData(), 'labels' => array_keys($data->getData())];
         $rendererConfiguration = $report->getRendererConfiguration();
         return $this->templating->render($rendererConfiguration['template'], ['data' => $rendererData, 'configuration' => $rendererConfiguration]);
     }
     return $this->templating->render('SyliusReportBundle::noDataTemplate.html.twig', ['report' => $report]);
 }
 function it_renders_data_with_given_configuration(ReportInterface $report, Response $response, Data $reportData, $templating)
 {
     $reportData->getLabels()->willReturn(array('month', 'user_total'));
     $reportData->getData()->willReturn(array('month1' => '50', 'month2' => '40'));
     $renderData = array('report' => $report, 'values' => array('month1' => '50', 'month2' => '40'), 'labels' => array('month', 'user_total'), 'fields' => array('month1', 'month2'));
     $report->getRendererConfiguration()->willReturn(array('template' => 'SyliusReportBundle:Table:default.html.twig'));
     $templating->renderResponse('SyliusReportBundle:Table:default.html.twig', array('data' => $renderData, 'configuration' => array('template' => 'SyliusReportBundle:Table:default.html.twig')))->willReturn($response);
     $this->render($report, $reportData)->shouldReturn($response);
 }
Example #5
0
 function it_renders_data_with_given_configuration(ReportInterface $report, Data $reportData, $templating)
 {
     $reportData->getLabels()->willReturn(['month', 'user_total']);
     $reportData->getData()->willReturn(['month1' => '50', 'month2' => '40']);
     $renderData = ['report' => $report, 'values' => ['month1' => '50', 'month2' => '40'], 'labels' => ['month', 'user_total'], 'fields' => ['month1', 'month2']];
     $report->getRendererConfiguration()->willReturn(['template' => 'SyliusReportBundle:Table:default.html.twig']);
     $templating->render('SyliusReportBundle:Table:default.html.twig', ['data' => $renderData, 'configuration' => ['template' => 'SyliusReportBundle:Table:default.html.twig']])->willReturn('<div>Table Report</div>');
     $this->render($report, $reportData)->shouldReturn('<div>Table Report</div>');
 }
 public function it_fills_gaps($orderRepository)
 {
     $rawData = array(array('date' => '2014-12-30', 'number_of_orders' => '20'), array('date' => '2015-01-01', 'number_of_orders' => '2'));
     $configuration = array('start' => new \DateTime('2014-11-01 00:00:00.000000'), 'end' => new \DateTime('2015-01-03 00:00:00.000000'), 'period' => 'month', 'empty_records' => true);
     $orderRepository->ordersBetweenDatesGroupByDate(Argument::type('array'))->willReturn($rawData);
     $data = new Data();
     $data->setLabels(array_keys($rawData[0]));
     $data->setData(array('November 2014' => '0', 'December 2014' => '20', 'January 2015' => '2'));
     $this->fetch($configuration)->shouldBeLike($data);
 }
 public function it_fills_gaps($userRepository)
 {
     $rawData = [['date' => '2014-12-30', 'user_total' => '20'], ['date' => '2015-01-01', 'user_total' => '2']];
     $configuration = ['start' => new \DateTime('2014-11-01 00:00:00.000000'), 'end' => new \DateTime('2015-01-03 00:00:00.000000'), 'period' => 'month', 'empty_records' => true];
     $userRepository->getRegistrationStatistic(Argument::type('array'))->willReturn($rawData);
     $data = new Data();
     $data->setLabels(array_keys($rawData[0]));
     $data->setData(['November 2014' => '0', 'December 2014' => '20', 'January 2015' => '2']);
     $this->fetch($configuration)->shouldBeLike($data);
 }
Example #8
0
 /**
  * {@inheritdoc}
  */
 public function fetch(array $configuration)
 {
     $data = new Data();
     //There is added 23 hours 59 minutes 59 seconds to the end date to provide records for whole end date
     $configuration['end'] = $configuration['end']->add(new \DateInterval('PT23H59M59S'));
     //This should be removed after implementation hourly periods
     switch ($configuration['period']) {
         case self::PERIOD_DAY:
             $this->setExtraConfiguration($configuration, 'P1D', '%a', 'Y-m-d', ['date']);
             break;
         case self::PERIOD_MONTH:
             $this->setExtraConfiguration($configuration, 'P1M', '%m', 'F Y', ['month', 'year']);
             break;
         case self::PERIOD_YEAR:
             $this->setExtraConfiguration($configuration, 'P1Y', '%y', 'Y', ['year']);
             break;
         default:
             throw new \InvalidArgumentException('Wrong data fetcher period');
     }
     $rawData = $this->getData($configuration);
     if (empty($rawData)) {
         return $data;
     }
     $labels = array_keys($rawData[0]);
     $data->setLabels($labels);
     $fetched = [];
     if ($configuration['empty_records']) {
         $fetched = $this->fillEmptyRecords($fetched, $configuration);
     }
     foreach ($rawData as $row) {
         $date = new \DateTime($row[$labels[0]]);
         $fetched[$date->format($configuration['presentationFormat'])] = $row[$labels[1]];
     }
     $data->setData($fetched);
     return $data;
 }