1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
expenses.php
См. документацию.
1<?php
2
4
6
8{
9 protected array $data = [];
10
15 public function __construct(array $data = [])
16 {
17 $this->prepareData($data);
18 }
19
24 public function add(array $data): static
25 {
26 foreach ($this->getNumericFieldNames() as $name)
27 {
28 if (isset($data[$name]))
29 {
30 $value = $data[$name];
31 if (is_array($value))
32 {
33 $value = array_sum(array_map(
34 function ($value)
35 {
36 return is_numeric($value) ? $value : 0;
37 },
38 array_column($value, 'value')
39 ));
40 }
41 if (is_numeric($value))
42 {
43 $this->data[$name] += $value;
44 }
45 }
46 }
47
48 if (isset($data['currency']) && empty($this->data['currency']))
49 {
50 $this->data['currency'] = (string)$data['currency'];
51 }
52
53 if (isset($data['campaignId']))
54 {
55 $this->data['campaignId'] = (string)$data['campaignId'];
56 }
57
58 if (isset($data['campaignName']))
59 {
60 $this->data['campaignName'] = (string)$data['campaignName'];
61 }
62
63 if (isset($data['groupId']))
64 {
65 $this->data['groupId'] = (string)$data['groupId'];
66 }
67
68 if (isset($data['groupName']))
69 {
70 $this->data['groupName'] = (string)$data['groupName'];
71 }
72
73 if (isset($data['adId']))
74 {
75 $this->data['adId'] = (string)$data['adId'];
76 }
77
78 if (isset($data['adName']))
79 {
80 $this->data['adName'] = (string)$data['adName'];
81 }
82
83 if (isset($data['utmMedium']))
84 {
85 $this->data['utmMedium'] = (string)$data['utmMedium'];
86 }
87
88 if (isset($data['utmSource']))
89 {
90 $this->data['utmSource'] = (string)$data['utmSource'];
91 }
92
93 if (isset($data['utmCampaign']))
94 {
95 $this->data['utmCampaign'] = (string)$data['utmCampaign'];
96 }
97
98 if (isset($data['utmContent']))
99 {
100 $this->data['utmContent'] = (string)$data['utmContent'];
101 }
102
103 if (isset($data['date']) && $data['date'] instanceof Date)
104 {
105 $this->data['date'] = $data['date'];
106 }
107
108 return $this;
109 }
110
114 public function toArray(): array
115 {
116 return $this->data;
117 }
118
122 public function getImpressions(): int
123 {
124 return (int)($this->data['impressions'] ?? 0);
125 }
126
130 public function getClicks(): int
131 {
132 return (int)($this->data['clicks'] ?? 0);
133 }
134
138 public function getActions(): int
139 {
140 return (int)($this->data['actions'] ?? 0);
141 }
142
146 public function getCpc(): float
147 {
148 return (float)($this->data['cpc'] ?? 0);
149 }
150
156 public function getCpm(): float
157 {
158 return (float)($this->data['cpm'] ?? 0);
159 }
160
164 public function getSpend(): float
165 {
166 return $this->data['spend'];
167 }
168
172 public function getCurrency(): string
173 {
174 return $this->data['currency'];
175 }
176
180 public function getCampaignId(): string
181 {
182 return $this->data['campaignId'] ?? '';
183 }
184
188 public function getCampaignName(): string
189 {
190 return $this->data['campaignName'];
191 }
192
196 public function getGroupId(): string
197 {
198 return $this->data['groupId'] ?? '';
199 }
200
204 public function getGroupName(): string
205 {
206 return $this->data['groupName'] ?? '';
207 }
208
212 public function getAdId(): string
213 {
214 return $this->data['adId'] ?? '';
215 }
216
220 public function getAdName(): string
221 {
222 return $this->data['adName'] ?? '';
223 }
224
230 public function getUtmMedium(): string
231 {
232 return $this->data['utmMedium'] ?? '';
233 }
234
240 public function getUtmSource(): string
241 {
242 return $this->data['utmSource'] ?? '';
243 }
244
250 public function getUtmCampaign(): string
251 {
252 return $this->data['utmCampaign'] ?? '';
253 }
254
260 public function getUtmContent(): string
261 {
262 return $this->data['utmContent'] ?? '';
263 }
264
267 public function getDate(): ?Date
268 {
269 return $this->data['date'];
270 }
271
275 protected function prepareData(array $data)
276 {
277 $this->data = [
278 'impressions' => 0,
279 'clicks' => 0,
280 'actions' => 0,
281 'cpc' => 0,
282 'cpm' => 0,
283 'spend' => 0,
284 'currency' => '',
285 'campaignId' => '',
286 'campaignName' => '',
287 'date' => null,
288 ];
289
290 $this->add($data);
291 }
292
296 protected function getNumericFieldNames(): array
297 {
298 return ['impressions', 'clicks', 'actions', 'cpc', 'cpm', 'spend'];
299 }
300}
Определения date.php:9
__construct(array $data=[])
Определения expenses.php:15
prepareData(array $data)
Определения expenses.php:275
add(array $data)
Определения expenses.php:24
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$name
Определения menu_edit.php:35