Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
audiencefacebook.php
1<?php
5
7{
8 const TYPE_CODE = 'facebook';
9
10 const ENUM_CONTACT_TYPE_EMAIL = 'email'; // email
11 const ENUM_CONTACT_TYPE_PHONE = 'phone'; // phone
12 const ENUM_CONTACT_TYPE_IDFA_GAID = 'idfa_gaid'; // IDFA (Identifier For Advertising) or device ID (Android ID and UDID on iOS)
13 const ENUM_CONTACT_TYPE_INTERNAL_ID = 'int'; // int
14
17
18 protected static $listRowMap = array(
19 'ID' => 'ID',
20 'NAME' => 'NAME',
21 'COUNT_VALID' => 'APPROXIMATE_COUNT',
22 'COUNT_MATCHED' => 'APPROXIMATE_COUNT',
23 'SUPPORTED_CONTACT_TYPES' => array(
24 self::ENUM_CONTACT_TYPE_EMAIL,
25 self::ENUM_CONTACT_TYPE_PHONE,
26 self::ENUM_CONTACT_TYPE_IDFA_GAID,
27 self::ENUM_CONTACT_TYPE_INTERNAL_ID
28 ),
29 );
30
31 public function getList()
32 {
33 $response = $this->getRequest()->send(array(
34 'methodName' => 'marketing.audience.list',
35 'parameters' => array(
36 'accountId' => $this->accountId
37 )
38 ));
39 if ($response->isSuccess())
40 {
41 $result = [];
42 while($data = $response->fetch())
43 {
44 $result[] = $data;
45 }
46 return $result;
47 }
48
49 return null;
50 }
51
52 public function add(array $data)
53 {
54 $response = $this->getRequest()->send(array(
55 'methodName' => 'marketing.audience.create',
56 'parameters' => $data
57 ));
58
59 if ($response->isSuccess())
60 {
61 return $response->getData();
62 }
63
64 return null;
65 }
66
67 protected function importContacts($audienceId, array $contacts, array $options)
68 {
69 return $this->getRequest()->send(array(
70 'methodName' => 'marketing.audience.contacts.add',
71 'parameters' => array(
72 'accountId' => $this->accountId,
73 'audience_id' => $this->accountId,
74 'contacts' => Json::encode(
75 $this->prepareContacts($contacts)
76 ),
77 )
78 ));
79 }
80
81 protected function removeContacts($audienceId, array $contacts, array $options)
82 {
83 return $this->getRequest()->send(array(
84 'methodName' => 'marketing.audience.contacts.remove',
85 'parameters' => array(
86 'accountId' => $this->accountId,
87 'audienceId' => $audienceId,
88 'contacts' => Json::encode(
89 $this->prepareContacts($contacts)
90 )
91 )
92 ));
93 }
94
95 protected function prepareContacts(array $contacts = array())
96 {
97 $data = array();
98
99 foreach (static::$listRowMap['SUPPORTED_CONTACT_TYPES'] as $contactType)
100 {
101 if (!isset($contacts[$contactType]))
102 {
103 continue;
104 }
105
106 $contactsCount = count($contacts[$contactType]);
107 for ($i = 0; $i < $contactsCount; $i++)
108 {
109 $contact = $contacts[$contactType][$i];
110 $contact = hash('sha256', $contact);
111
112 switch ($contactType)
113 {
115 $data[$contactType.'_SHA256'][] = $contact;
116 break;
117
119 $data[$contactType.'_SHA256'][] = $contact;
120 break;
121 }
122 }
123 }
124
125 return $data;
126 }
127}
removeContacts($audienceId, array $contacts, array $options)
importContacts($audienceId, array $contacts, array $options)