1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
expensesadapter.php
См. документацию.
1<?php
2
4
8
9final class ExpensesAdapter
10{
12 {
13 $campaigns = $data['CAMPAIGNS'] ?? [];
14 if (is_array($campaigns))
15 {
16 $campaigns = array_column($campaigns, 'NAME', 'ID');
17 }
18
19 $adGroups = $data['AD_GROUPS'] ?? [];
20 if (is_array($adGroups))
21 {
22 $adGroups = array_column($adGroups, 'NAME', 'ID');
23 }
24
25 $ads = $data['ADS'] ?? [];
26 if (is_array($ads))
27 {
28 $ads = array_column($ads, 'NAME', 'ID');
29 }
30
31 $rows = $data['ROWS'] ?? [];
32 $currency = $data['CURRENCY'] ?? '';
33
34 $resultCollection = new ExpensesCollection();
35 foreach ($rows as $row)
36 {
37 $clicks = (int)($row['CLICKS'] ?? 0);
38 $cost = (float)($row['COST'] ?? 0);
39 $impressions = (int)($row['IMPRESSIONS'] ?? 0);
40
41 $costPerMill =
42 $impressions > 0
43 ? round(($cost / $impressions) * 1000, 2)
44 : 0
45 ;
46
47 $costPerClick =
48 $clicks > 0
49 ? round($cost / $clicks, 2)
50 : 0
51 ;
52
53 $date = !empty($row['DATE']) ? new Date($row['DATE'], 'Y-m-d') : null;
54
55 $formattedRow = [
56 'impressions' => $row['IMPRESSIONS'],
57 'campaignName' => $campaigns[$row['CID']] ?? '',
58 'campaignId' => $row['CID'],
59 'clicks' => $clicks,
60 'actions' => $clicks,
61 'spend' => $cost,
62 'cpc' => $costPerClick,
63 'date' => $date,
64 'cpm' => $costPerMill,
65 'currency' => $currency,
66 'adId' => $row['ADID'],
67 'adName' => $ads[$row['ADID']] ?? '',
68 'groupId' => $row['GID'],
69 'groupName' => $adGroups[$row['GID']] ?? '',
70 'utmSource' => $data['CLICKS'][$row['CLICKID']]['UTM_TAGS']['UTM_SOURCE'] ?? '',
71 'utmMedium' => $data['CLICKS'][$row['CLICKID']]['UTM_TAGS']['UTM_MEDIUM'] ?? '',
72 'utmCampaign' => $data['CLICKS'][$row['CLICKID']]['UTM_TAGS']['UTM_CAMPAIGN'] ?? '',
73 'utmContent' => $data['CLICKS'][$row['CLICKID']]['UTM_TAGS']['UTM_CONTENT'] ?? '',
74 ];
75
76 $resultCollection->addItem(new Expenses($formattedRow));
77 }
78
79 return $resultCollection;
80 }
81}
Определения date.php:9
static translateExpensesReportToDailyExpenses(array $data)
Определения expensesadapter.php:11
$data['IS_AVAILABLE']
Определения .description.php:13
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$currency
Определения template.php:266
$rows
Определения options.php:264