55 return 'b_seo_yandex_direct_stat';
67 'data_type' =>
'integer',
69 'autocomplete' =>
true,
71 'CAMPAIGN_ID' => array(
72 'data_type' =>
'integer',
76 'data_type' =>
'integer',
80 'data_type' =>
'date',
84 'data_type' =>
'string',
87 'data_type' =>
'float',
89 'SUM_SEARCH' => array(
90 'data_type' =>
'float',
92 'SUM_CONTEXT' => array(
93 'data_type' =>
'float',
96 'data_type' =>
'integer',
98 'CLICKS_SEARCH' => array(
99 'data_type' =>
'integer',
101 'CLICKS_CONTEXT' => array(
102 'data_type' =>
'integer',
105 'data_type' =>
'integer',
107 'SHOWS_SEARCH' => array(
108 'data_type' =>
'integer',
110 'SHOWS_CONTEXT' => array(
111 'data_type' =>
'integer',
114 'data_type' =>
'Bitrix\Seo\Adv\YandexCampaignTable',
115 'reference' => array(
'=this.CAMPAIGN_ID' =>
'ref.ID'),
118 'data_type' =>
'Bitrix\Seo\Adv\YandexBannerTable',
119 'reference' => array(
'=this.BANNER_ID' =>
'ref.ID'),
128 $dbRes = static::getList(array(
130 'BANNER_ID' =>
'ASC',
134 '=BANNER_ID' => $bannerId,
135 '>=DATE_DAY' => $dateStart,
136 '<=DATE_DAY' => $dateFinish,
140 while($statEntry = $dbRes->fetch())
142 $result[$statEntry[
'DATE_DAY']->toString()] = $statEntry;
152 $dbRes = static::getList(array(
156 'group' => array(
'CAMPAIGN_ID',
'DATE_DAY',
'CURRENCY'),
158 '=CAMPAIGN_ID' => $campaignId,
159 '>=DATE_DAY' => $dateStart,
160 '<=DATE_DAY' => $dateFinish,
163 'CAMPAIGN_ID',
'DATE_DAY',
'CURRENCY',
164 'CAMPAIGN_SUM',
'CAMPAIGN_SUM_SEARCH',
'CAMPAIGN_SUM_CONTEXT',
165 'CAMPAIGN_SHOWS',
'CAMPAIGN_SHOWS_SEARCH',
'CAMPAIGN_SHOWS_CONTEXT',
166 'CAMPAIGN_CLICKS',
'CAMPAIGN_CLICKS_SEARCH',
'CAMPAIGN_CLICKS_CONTEXT',
181 while($statEntry = $dbRes->fetch())
183 $result[$statEntry[
'DATE_DAY']->toString()] = $statEntry;
193 $dbRes = YandexBannerTable::getList(array(
196 '=ENGINE_ID' => $directEngine->getId()
200 'CAMPAIGN_XML_ID' =>
'CAMPAIGN.XML_ID'
204 $banner = $dbRes->fetch();
207 $result = static::loadStat($directEngine, $banner[
'CAMPAIGN_XML_ID'], $dateStart, $dateFinish);
210 static::processStatsResult($banner[
'CAMPAIGN_ID'], $result, $directEngine);
222 $dbRes = YandexCampaignTable::getList(array(
224 '=ID' => $campaignId,
225 '=ENGINE_ID' => $directEngine->getId()
232 $campaign = $dbRes->fetch();
235 $result = static::loadStat($directEngine, $campaign[
'XML_ID'], $dateStart, $dateFinish);
238 static::processStatsResult($campaignId, $result, $directEngine);
246 protected static function loadStat(
YandexDirect $directEngine, $campaignXmlId, $dateStart, $dateFinish, $skipCurrency =
false)
248 $dateStart =
new Date($dateStart);
249 $dateFinish =
new Date($dateFinish);
252 "CampaignID" => $campaignXmlId,
253 "StartDate" => $dateStart->format(
"Y-m-d"),
254 'EndDate' => $dateFinish->format(
"Y-m-d"),
255 'GroupByColumns' => array(
261 if(!$skipCurrency && Loader::includeModule(
'currency'))
263 $baseCurrency = \CCurrency::GetBaseCurrency();
264 if($baseCurrency ==
'RUR')
266 $baseCurrency =
'RUB';
269 if(in_array($baseCurrency, $directEngine->allowedCurrency))
271 $currency = $baseCurrency;
277 $queryData[
'Currency'] = $currency;
283 $result[
'Currency'] = $currency;
287 if($currency !=
'' && $e->getCode() == YandexDirect::ERROR_WRONG_CURRENCY)
289 $result = static::loadStat($directEngine, $campaignXmlId, $dateStart, $dateFinish,
true);
304 $bannerIds = array();
305 foreach($result[
'Stat'] as $statEntry)
307 $bannerIds[] = $statEntry[
'BannerID'];
310 if(count($bannerIds) > 0)
312 $dbRes = YandexBannerTable::getList(array(
314 '=XML_ID' => array_values(array_unique($bannerIds)),
315 '=ENGINE_ID' => $directEngine->
getId()
321 $bannerList = array();
322 while($bannerData = $dbRes->fetch())
324 $bannerList[$bannerData[
'XML_ID']] = $bannerData[
'ID'];
327 if(count($bannerList) > 0)
329 foreach($result[
'Stat'] as $statEntry)
331 if(array_key_exists($statEntry[
'BannerID'], $bannerList))
334 'CAMPAIGN_ID' => $campaignId,
335 'BANNER_ID' => $bannerList[$statEntry[
'BannerID']],
336 'DATE_DAY' =>
new Date($statEntry[
'StatDate'],
'Y-m-d'),
337 'CURRENCY' => $result[
'Currency'],
338 'SUM' => $statEntry[
'Sum'],
339 'SUM_SEARCH' => $statEntry[
'SumSearch'],
340 'SUM_CONTEXT' => $statEntry[
'SumContext'],
341 'CLICKS' => $statEntry[
'Clicks'],
342 'CLICKS_SEARCH' => $statEntry[
'ClicksSearch'],
343 'CLICKS_CONTEXT' => $statEntry[
'ClicksContext'],
344 'SHOWS' => $statEntry[
'Shows'],
345 'SHOWS_SEARCH' => $statEntry[
'ShowsSearch'],
346 'SHOWS_CONTEXT' => $statEntry[
'ShowsContext'],
349 $statCheckRes = static::getList(array(
351 'BANNER_ID' => $statFields[
'BANNER_ID'],
352 'DATE_DAY' => $statFields[
'DATE_DAY'],
354 'select' => array(
'ID')
357 $statCheck = $statCheckRes->fetch();
360 static::add($statFields);
371 $missedPeriods = array();
373 $datePrevoius =
false;
375 $checkDate =
new Date($dateStart);
376 $dateCurrent =
new Date($dateStart);
377 $dateFinish =
new Date($dateFinish);
379 while($dateCurrent->getTimestamp() <= $dateFinish->getTimestamp())
381 if(!array_key_exists($dateCurrent->toString(), $stats))
385 || $dateCurrent->getTimestamp() >= $checkDate->getTimestamp()
388 $missedPeriods[] = array(
389 $dateCurrent->toString(),
390 $dateCurrent->toString()
393 $checkDate =
new Date($dateCurrent->toString());
394 $checkDate->add(
"+".YandexDirect::MAX_STAT_DAYS_DELTA.
" days");
396 $datePrevoius =
true;
400 $missedPeriods[count($missedPeriods)-1][1] = $dateCurrent->toString();
405 $datePrevoius =
false;
408 $dateCurrent->add(
"+1 days");
411 return $missedPeriods;
static loadCampaignStat($campaignId, $dateStart, $dateFinish)
static getMissedPeriods(array $stats, $dateStart, $dateFinish)
static loadStat(YandexDirect $directEngine, $campaignXmlId, $dateStart, $dateFinish, $skipCurrency=false)
static getCampaignStat($campaignId, $dateStart, $dateFinish)
static getBannerStat($bannerId, $dateStart, $dateFinish)
static processStatsResult($campaignId, array $result, YandexDirect $directEngine)
static loadBannerStat($bannerId, $dateStart, $dateFinish)
getBannerStats(array $params)