|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Yandex\Direct\Service; |
|
4
|
|
|
|
|
5
|
|
|
use Yandex\Direct\Exception\Exception; |
|
6
|
|
|
use Yandex\Direct\Service; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* Class Reports |
|
10
|
|
|
* |
|
11
|
|
|
* @author Dmitry Gladyshev <[email protected]> |
|
12
|
|
|
*/ |
|
13
|
|
|
final class Reports extends Service |
|
14
|
|
|
{ |
|
15
|
|
|
/** |
|
16
|
|
|
* Спецификация отчета. |
|
17
|
|
|
* |
|
18
|
|
|
* @param $SelectionCriteria |
|
19
|
|
|
* @param $Goals |
|
20
|
|
|
* @param $FieldNames |
|
21
|
|
|
* @param $ReportName |
|
22
|
|
|
* @param $ReportType |
|
23
|
|
|
* @param $DateRangeType |
|
24
|
|
|
* @param $Format |
|
25
|
|
|
* @param $IncludeVAT |
|
26
|
|
|
* @param $IncludeDiscount |
|
27
|
|
|
* @param $Page |
|
28
|
|
|
* @param $OrderBy |
|
29
|
|
|
* @return string |
|
30
|
|
|
* @throws Exception |
|
31
|
|
|
* |
|
32
|
|
|
* @see https://tech.yandex.ru/direct/doc/reports/spec-docpage/ |
|
33
|
|
|
*/ |
|
34
|
|
|
public function get( |
|
35
|
|
|
$SelectionCriteria, |
|
36
|
|
|
$FieldNames, |
|
37
|
|
|
$ReportName, |
|
38
|
|
|
$ReportType, |
|
39
|
|
|
$DateRangeType, |
|
40
|
|
|
$Page = null, |
|
41
|
|
|
$OrderBy = null, |
|
42
|
|
|
$IncludeVAT = 'YES', |
|
43
|
|
|
$IncludeDiscount = 'YES', |
|
44
|
|
|
$Format = 'TSV', |
|
45
|
|
|
$Goals = [] |
|
46
|
|
|
) { |
|
47
|
|
|
|
|
48
|
|
|
$params = [ |
|
49
|
|
|
'SelectionCriteria' => $SelectionCriteria, |
|
50
|
|
|
'FieldNames' => $FieldNames, |
|
51
|
|
|
'Page' => $Page, |
|
52
|
|
|
'OrderBy' => $OrderBy, |
|
53
|
|
|
'ReportName' => $ReportName, |
|
54
|
|
|
'ReportType' => $ReportType, |
|
55
|
|
|
'DateRangeType' => $DateRangeType, |
|
56
|
|
|
'Format' => $Format, |
|
57
|
|
|
'IncludeVAT' => $IncludeVAT, |
|
58
|
|
|
'IncludeDiscount' => $IncludeDiscount, |
|
59
|
|
|
]; |
|
60
|
|
|
|
|
61
|
|
|
if (!empty($Goals)) { |
|
62
|
|
|
$params['Goals'] = $Goals; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
if ($Page) { |
|
66
|
|
|
$params['Page'] = $Page; |
|
67
|
|
|
} else { |
|
68
|
|
|
unset($params['Page']); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
if ($OrderBy) { |
|
72
|
|
|
$params['OrderBy'] = $OrderBy; |
|
73
|
|
|
} else { |
|
74
|
|
|
unset($params['OrderBy']); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
return $this->request([ |
|
78
|
|
|
'params' => $params |
|
79
|
|
|
]); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* Режим формирования отчета: online, offline или auto. |
|
84
|
|
|
* Отсутствие заголовка эквивалентно значению auto. |
|
85
|
|
|
* |
|
86
|
|
|
* @param $processingMode |
|
87
|
|
|
* @return $this |
|
88
|
|
|
* @see https://tech.yandex.ru/direct/doc/reports/headers-docpage/ |
|
89
|
|
|
*/ |
|
90
|
|
|
public function setProcessingMode($processingMode) |
|
91
|
|
|
{ |
|
92
|
|
|
$this->headers['processingMode'] = $processingMode; |
|
93
|
|
|
return $this; |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
/** |
|
97
|
|
|
* Если заголовок указан, денежные значения в отчете возвращаются в валюте с точностью до двух знаков после |
|
98
|
|
|
* запятой. Если не указан, денежные значения возвращаются в виде целых чисел — сумм в валюте, |
|
99
|
|
|
* умноженных на 1 000 000. |
|
100
|
|
|
* |
|
101
|
|
|
* @param $returnMoneyInMicros |
|
102
|
|
|
* @return $this |
|
103
|
|
|
* @see https://tech.yandex.ru/direct/doc/reports/headers-docpage/ |
|
104
|
|
|
*/ |
|
105
|
|
|
public function setReturnMoneyInMicros($returnMoneyInMicros) |
|
106
|
|
|
{ |
|
107
|
|
|
if (is_numeric($returnMoneyInMicros) || is_bool($returnMoneyInMicros)) { |
|
108
|
|
|
$returnMoneyInMicros = $returnMoneyInMicros ? 'true' : 'false'; |
|
109
|
|
|
} |
|
110
|
|
|
$this->headers['returnMoneyInMicros'] = $returnMoneyInMicros; |
|
111
|
|
|
return $this; |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
/** |
|
115
|
|
|
* Не выводить в отчете строку с названием отчета и диапазоном дат. |
|
116
|
|
|
* @return $this |
|
117
|
|
|
* @see https://tech.yandex.ru/direct/doc/reports/headers-docpage/ |
|
118
|
|
|
*/ |
|
119
|
|
|
public function setSkipReportHeader() |
|
120
|
|
|
{ |
|
121
|
|
|
$this->headers['skipReportHeader'] = 'true'; |
|
122
|
|
|
return $this; |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
/** |
|
126
|
|
|
* Не выводить в отчете строку с названиями полей. |
|
127
|
|
|
* |
|
128
|
|
|
* @return $this |
|
129
|
|
|
* @see https://tech.yandex.ru/direct/doc/reports/headers-docpage/ |
|
130
|
|
|
*/ |
|
131
|
|
|
public function setSkipColumnHeader() |
|
132
|
|
|
{ |
|
133
|
|
|
$this->headers['skipColumnHeader'] = 'true'; |
|
134
|
|
|
return $this; |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
|
/** |
|
138
|
|
|
* Не выводить в отчете строку с количеством строк статистики. |
|
139
|
|
|
* |
|
140
|
|
|
* @see https://tech.yandex.ru/direct/doc/reports/headers-docpage/ |
|
141
|
|
|
*/ |
|
142
|
|
|
public function setSkipReportSummary() |
|
143
|
|
|
{ |
|
144
|
|
|
$this->headers['skipReportSummary'] = 'true'; |
|
145
|
|
|
return $this; |
|
146
|
|
|
} |
|
147
|
|
|
} |
|
148
|
|
|
|