コード例 #1
0
 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);
 }
コード例 #2
0
 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);
 }
コード例 #3
0
ファイル: TimePeriod.php プロジェクト: ahmadrabie/Sylius
 /**
  * {@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;
 }