コード例 #1
0
ファイル: yamarket.php プロジェクト: JexyRu/Ksenmart
 public function getShopStatisticByPlacesFull($fromDate, $toDate, $groupBy)
 {
     $this->onExecuteBefore('getShopStatisticByPlacesFull', array(&$fromDate, &$toDate, &$groupBy));
     if (!empty($this->_sid) && $this->_sid > 0) {
         $fromDate = new DateTime($fromDate);
         $fromDate = $fromDate->format('d-m-Y');
         $toDate = new DateTime($toDate);
         $toDate = $toDate->format('d-m-Y');
         $function = array('campaigns', $this->_sid, 'stats', 'main-' . $groupBy);
         $params = array('fromDate' => $fromDate, 'toDate' => $toDate, 'byPlaces' => 1);
         $statistic = KSSystem::getYaMarketData($function, 'GET', $params);
         if ($statistic && count($statistic->mainStats) > 0) {
             //$statistic          = $this->setShopStatisticPlaces($statistic->mainStats);
             $statistic_group = new stdClass();
             $total->{3}['clicks'] = 0;
             $total->{3}['spending'] = 0;
             $total->{4}['clicks'] = 0;
             $total->{4}['spending'] = 0;
             $total->{5}['clicks'] = 0;
             $total->{5}['spending'] = 0;
             $total->{6}['clicks'] = 0;
             $total->{6}['spending'] = 0;
             foreach ($statistic->mainStats as $stat) {
                 $date = date("d.m.Y", strtotime($stat->date));
                 $statistic_group->{$date}->{$stat->placeGroup}['clicks'] = $stat->clicks;
                 $statistic_group->{$date}->{$stat->placeGroup}['spending'] = $stat->spending;
                 $total->{$stat->placeGroup}['clicks'] += $stat->clicks;
                 $total->{$stat->placeGroup}['spending'] += $stat->spending;
                 if (!isset($statistic_group->{$date}->{3})) {
                     $statistic_group->{$date}->{3}['clicks'] = 0;
                     $statistic_group->{$date}->{3}['spending'] = 0;
                 }
                 if (!isset($statistic_group->{$date}->{4})) {
                     $statistic_group->{$date}->{4}['clicks'] = 0;
                     $statistic_group->{$date}->{4}['spending'] = 0;
                 }
                 if (!isset($statistic_group->{$date}->{5})) {
                     $statistic_group->{$date}->{5}['clicks'] = 0;
                     $statistic_group->{$date}->{5}['spending'] = 0;
                 }
                 if (!isset($statistic_group->{$date}->{6})) {
                     $statistic_group->{$date}->{6}['clicks'] = 0;
                     $statistic_group->{$date}->{6}['spending'] = 0;
                 }
                 $statistic_group->{$date}->totalClicks += $stat->clicks;
                 $statistic_group->{$date}->totalSpending += $stat->spending;
                 $total->totalSpending += $stat->spending;
                 $total->totalClicks += $stat->clicks;
             }
             $statistic_group->km_total = $total;
             $this->onExecuteAfter('getShopStatisticByPlacesFull', array(&$statistic_group));
             return $statistic_group;
         }
     }
     return new stdClass();
 }