Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
accountvkads.php
1<?
2
4
10
12{
13 const TYPE_CODE = 'vkads';
14
15 const MAX_ADS_EDIT = 20;
16 const CURRENCY_CODE = 'RUB';
17
18 protected static $listRowMap = array(
19 'ID' => 'ACCOUNT_ID',
20 'NAME' => 'NAME',
21 );
22
23 public function getList()
24 {
25 $result = $this->getRequest()->send([
26 'methodName' => 'analytics.account.list.full',
27 ]);
28 if ($result->isSuccess())
29 {
30 $list = [];
31 while ($item = $result->fetch())
32 {
33 if (
34 (
35 isset($item['CLIENT_NAME'])
36 || isset($item['NAME'])
37 )
38 && isset($item['ID'])
39 )
40 {
41 $list[] = [
42 'NAME' => !empty(trim($item['CLIENT_NAME'])) ? $item['CLIENT_NAME'] : $item['NAME'],
43 'ACCOUNT_ID' => $item['ID'],
44 ];
45 }
46 }
47 $result->setData($list);
48 }
49
50 return $result;
51 }
52
53 public function getProfile()
54 {
55 $response = $this->getRequest()->send([
56 'methodName' => 'analytics.profile',
57 'parameters' => []
58 ]);
59
60 if ($response->isSuccess() && $data = $response->fetch())
61 {
62 $result = [
63 'ID' => $data['ID'],
64 'NAME' => $data['FIRST_NAME'] . ' ' . $data['LAST_NAME'],
65 'LINK' => 'https://ads.vk.com/hq/budget/transactions/',
66 ];
67
68 $result['PICTURE'] = (Context::getCurrent()->getRequest()->isHttps() ? 'https' : 'http')
69 . '://'
70 . Context::getCurrent()->getServer()->getHttpHost() . '/bitrix/images/seo/integration/vklogo.svg';
71
72 return $result;
73 }
74
75 return null;
76 }
77
78 public function getExpenses($accountId, Date $dateFrom = null, Date $dateTo = null)
79 {
80 $result = new ResponseVkads();
81 $params = [
82 'id' => $accountId,
83 ];
84
85 if($dateFrom && $dateTo)
86 {
87 $params['period'] = 'day';
88 $params['date_from'] = $dateFrom->format('Y-m-d');
89 $params['date_to'] = $dateTo->format('Y-m-d');
90 }
91 else
92 {
93 $params['period'] = 'summary';
94 $params['date_from'] = '0';
95 $params['date_to'] = '0';
96 }
97 $response = $this->getRequest()->send([
98 'methodName' => 'analytics.expenses.get',
99 'parameters' => $params,
100 ]);
101 if($response->isSuccess())
102 {
103 $data = $response->getData();
104 $expenses = new Expenses();
105 $expenses->add([
106 'impressions' => $data['shows'],
107 'clicks' => $data['clicks'],
108 'actions' => $data['clicks'],
109 'spend' => $data['spent'],
110 'currency' => static::CURRENCY_CODE,
111 ]);
112 $result->setData(['expenses' => $expenses]);
113 }
114 else
115 {
116 $result->addErrors($response->getErrors());
117 }
118
119 return $result;
120 }
121
129 public function updateAnalyticParams($accountId, array $params, array $publicPageIds = [])
130 {
131 return new ResponseVkads();
132 }
133}
static getCurrent()
Definition context.php:241
updateAnalyticParams($accountId, array $params, array $publicPageIds=[])
getExpenses($accountId, Date $dateFrom=null, Date $dateTo=null)