コード例 #1
0
ファイル: CustomerDataProvider.php プロジェクト: antrampa/crm
 /**
  * @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();
 }
コード例 #2
0
 /**
  * @expectedException \Oro\Bundle\ChartBundle\Exception\BadMethodCallException
  * @expectedExceptionMessage Can't build result when setData() was not called.
  */
 public function testGetViewFailsWhenDataNotSet()
 {
     $chartName = 'foo';
     $options = array('name' => $chartName);
     $chartConfig = array('template' => 'foo.html.twig', 'default_settings' => array('bar' => 'baz'));
     $this->setExpectedChartConfig($chartName, $chartConfig);
     $this->builder->setOptions($options)->getView();
 }
コード例 #3
0
ファイル: OrderDataProvider.php プロジェクト: dairdr/crm
 /**
  * @param ChartViewBuilder $viewBuilder
  * @return ChartView
  */
 public function getAverageOrderAmountChartView(ChartViewBuilder $viewBuilder)
 {
     /** @var OrderRepository $orderRepository */
     $orderRepository = $this->registry->getRepository('OroCRMMagentoBundle:Order');
     $result = $orderRepository->getAverageOrderAmount($this->aclHelper);
     // prepare chart items
     $items = [];
     foreach ($result as $channel) {
         $channelName = $channel['name'];
         $channelData = $channel['data'];
         $items[$channelName] = [];
         foreach ($channelData as $year => $monthData) {
             foreach ($monthData as $month => $amount) {
                 $items[$channelName][] = ['month' => sprintf('%04d-%02d-01', $year, $month), 'amount' => $amount];
             }
         }
     }
     $orderAmountLabel = $this->translator->trans('orocrm.magento.dashboard.average_order_amount_chart.order_amount');
     $chartOptions = ['name' => 'multiline_chart', 'data_schema' => ['label' => ['field_name' => 'month', 'label' => null, 'type' => 'month'], 'value' => ['field_name' => 'amount', 'label' => $orderAmountLabel, 'type' => 'currency']]];
     return $viewBuilder->setOptions($chartOptions)->setArrayData($items)->getView();
 }
コード例 #4
0
ファイル: PurchaseDataProvider.php プロジェクト: CopeX/crm
 /**
  * @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();
 }
コード例 #5
0
ファイル: OrderDataProvider.php プロジェクト: antrampa/crm
 /**
  * @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();
 }