Example #1
0
 /**
  * @param ChartViewBuilder $viewBuilder
  * @param array            $dateRange
  *
  * @return ChartView
  */
 public function getNewCustomerChartView(ChartViewBuilder $viewBuilder, $dateRange)
 {
     /** @var CustomerRepository $customerRepository */
     $customerRepository = $this->registry->getRepository('OroCRMMagentoBundle:Customer');
     /** @var ChannelRepository $channelRepository */
     $channelRepository = $this->registry->getRepository('OroCRMChannelBundle:Channel');
     list($past, $now) = $this->dateHelper->getPeriod($dateRange, 'OroCRMMagentoBundle:Customer', 'createdAt');
     $items = [];
     // get all integration channels
     $channels = $channelRepository->getAvailableChannelNames($this->aclHelper, ChannelType::TYPE);
     $channelIds = array_keys($channels);
     $dates = $this->dateHelper->getDatePeriod($past, $now);
     $data = $customerRepository->getGroupedByChannelArray($this->aclHelper, $this->dateHelper, $past, $now, $channelIds);
     foreach ($data as $row) {
         $key = $this->dateHelper->getKey($past, $now, $row);
         $channelId = (int) $row['channelId'];
         $channelName = $channels[$channelId]['name'];
         if (!isset($items[$channelName])) {
             $items[$channelName] = $dates;
         }
         if (isset($items[$channelName][$key])) {
             $items[$channelName][$key]['cnt'] = (int) $row['cnt'];
         }
     }
     // restore default keys
     foreach ($items as $channelName => $item) {
         $items[$channelName] = array_values($item);
     }
     $chartOptions = array_merge_recursive(['name' => 'multiline_chart'], $this->configProvider->getChartConfig('new_web_customers'));
     $chartType = $this->dateHelper->getFormatStrings($past, $now)['viewType'];
     $chartOptions['data_schema']['label']['type'] = $chartType;
     $chartOptions['data_schema']['label']['label'] = sprintf('oro.dashboard.chart.%s.label', $chartType);
     return $viewBuilder->setOptions($chartOptions)->setArrayData($items)->getView();
 }
Example #2
0
 /**
  * @param ChartViewBuilder $viewBuilder
  * @param string           $chart
  * @param string           $type
  * @param array            $data
  *
  * @return ChartView
  */
 protected function createPeriodChartView(ChartViewBuilder $viewBuilder, $chart, $type, array $data)
 {
     $chartOptions = array_merge_recursive(['name' => 'multiline_chart'], $this->configProvider->getChartConfig($chart));
     $chartOptions['data_schema']['label']['type'] = $type;
     $chartOptions['data_schema']['label']['label'] = sprintf('oro.dashboard.chart.%s.label', $type);
     return $viewBuilder->setOptions($chartOptions)->setArrayData($data)->getView();
 }
Example #3
0
 /**
  * @return array
  * @throws InvalidArgumentException
  */
 protected function getChartConfig()
 {
     if (null === $this->chartConfig) {
         $chartConfig = $this->configProvider->getChartConfig($this->options['name']);
         $this->chartConfig = $chartConfig;
     }
     return $this->chartConfig;
 }
 /**
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function testGetPurchaseChartView()
 {
     $from = new DateTime();
     $expectedArrayData = [['label' => 'orocrm.magento.dashboard.purchase_chart.visited', 'value' => 10, 'isNozzle' => false], ['label' => 'orocrm.magento.dashboard.purchase_chart.deeply_visited', 'value' => 5, 'isNozzle' => false], ['label' => 'orocrm.magento.dashboard.purchase_chart.added_to_cart', 'value' => 30, 'isNozzle' => false], ['label' => 'orocrm.magento.dashboard.purchase_chart.purchased', 'value' => 13, 'isNozzle' => true]];
     $expectedOptions = ['name' => 'flow_chart', 'settings' => ['quarterDate' => $from], 'data_schema' => ['label' => ['field_name' => 'label', 'label' => null, 'type' => 'string'], 'value' => ['field_name' => 'value', 'label' => null, 'type' => 'integer'], 'isNozzle' => ['field_name' => 'isNozzle', 'label' => null, 'type' => 'boolean']]];
     $chartConfig = ['data_schema' => $expectedOptions['data_schema']];
     $this->trackingVisitProvider->expects($this->once())->method('getVisitedCount')->will($this->returnValue(10));
     $this->trackingVisitProvider->expects($this->once())->method('getDeeplyVisitedCount')->will($this->returnValue(5));
     $cartRepository = $this->getMockBuilder('OroCRM\\Bundle\\MagentoBundle\\Entity\\Repository\\CartRepository')->disableOriginalConstructor()->getMock();
     $cartRepository->expects($this->once())->method('getCustomersCountWhatMakeCarts')->will($this->returnValue(30));
     $this->registry->expects($this->at(0))->method('getRepository')->with('OroCRMMagentoBundle:Cart')->will($this->returnValue($cartRepository));
     $orderRepository = $this->getMockBuilder('OroCRM\\Bundle\\MagentoBundle\\Entity\\Repository\\OrderRepository')->disableOriginalConstructor()->getMock();
     $orderRepository->expects($this->once())->method('getUniqueBuyersCount')->will($this->returnValue(13));
     $this->registry->expects($this->at(1))->method('getRepository')->with('OroCRMMagentoBundle:Order')->will($this->returnValue($orderRepository));
     $chartView = $this->getMockBuilder('Oro\\Bundle\\ChartBundle\\Model\\ChartView')->disableOriginalConstructor()->getMock();
     $chartViewBuilder = $this->getMockBuilder('Oro\\Bundle\\ChartBundle\\Model\\ChartViewBuilder')->disableOriginalConstructor()->getMock();
     $chartViewBuilder->expects($this->once())->method('setOptions')->with($expectedOptions)->will($this->returnSelf());
     $chartViewBuilder->expects($this->once())->method('setArrayData')->with($expectedArrayData)->will($this->returnSelf());
     $chartViewBuilder->expects($this->once())->method('getView')->will($this->returnValue($chartView));
     $this->configProvider->expects($this->once())->method('getChartConfig')->with('purchase_chart')->will($this->returnValue($chartConfig));
     $this->dataProvider->getPurchaseChartView($chartViewBuilder, $from, new DateTime());
 }
Example #5
0
 /**
  * @expectedException \Oro\Bundle\ChartBundle\Exception\InvalidConfigurationException
  * @expectedExceptionMessage Can't find configuration for chart: any name
  */
 public function testGetChartConfigThrowAnException()
 {
     $configProvider = new ConfigProvider(array());
     $configProvider->getChartConfig('any name');
 }
Example #6
0
 /**
  * @param ChartViewBuilder $viewBuilder
  * @param DateTime $from
  * @param DateTime $to
  *
  * @return ChartView
  */
 public function getPurchaseChartView(ChartViewBuilder $viewBuilder, DateTime $from, DateTime $to)
 {
     $items = [['label' => $this->translator->trans('orocrm.magento.dashboard.purchase_chart.visited'), 'value' => $this->trackingVisitProvider->getVisitedCount($from, $to), 'isNozzle' => false], ['label' => $this->translator->trans('orocrm.magento.dashboard.purchase_chart.deeply_visited'), 'value' => $this->trackingVisitProvider->getDeeplyVisitedCount($from, $to), 'isNozzle' => false], ['label' => $this->translator->trans('orocrm.magento.dashboard.purchase_chart.added_to_cart'), 'value' => $this->getCartRepository()->getCustomersCountWhatMakeCarts($this->aclHelper, $from, $to), 'isNozzle' => false], ['label' => $this->translator->trans('orocrm.magento.dashboard.purchase_chart.purchased'), 'value' => $this->getOrderRepository()->getUniqueBuyersCount($this->aclHelper, $from, $to), 'isNozzle' => true]];
     $chartOptions = array_merge_recursive(['name' => 'flow_chart', 'settings' => ['quarterDate' => $from]], $this->configProvider->getChartConfig('purchase_chart'));
     return $viewBuilder->setOptions($chartOptions)->setArrayData($items)->getView();
 }