-
Notifications
You must be signed in to change notification settings - Fork 13
/
AbstractETSubscriberList.class.php
190 lines (162 loc) · 6.68 KB
/
AbstractETSubscriberList.class.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
<?php
abstract class AbstractETSubscriberList
{
protected $soapClient;
protected $subscriberClassName;
public function __construct()
{
$this->soapClient = ETCore::getClient();
$className = get_class($this);
$this->subscriberClassName = substr($className, 0 , -4);
}
/**
*
* @param mixed $filter An ExactTarget_SimpleFilterPart object or
* an ExactTarget_ComplexFilterPart object.
* @param integer $hydrationMode
*/
public function find($filter, $hydrationMode = ETCore::HYDRATE_ARRAY)
{
return $this->_find($filter, $hydrationMode, false);
}
/**
* Return Subscriber records that match the search criteria.
*
* @param string $property The name of the property to match
* @param string $value The value of the property to match
* @param int $hydrationMode The hydration mode
*
* @return mixed Either an array or an ETCollection object
*/
public function findByProperty($property, $value, $hydrationMode = ETCore::HYDRATE_ARRAY)
{
$sfp = $this->newSimpleFilterPart($property, $value);
return $this->_find($sfp, $hydrationMode, false, false);
}
public function findOneByProperty($property, $value, $hydrationMode = ETCore::HYDRATE_ARRAY)
{
$sfp = $this->newSimpleFilterPart($property, $value);
return $this->_find($sfp, $hydrationMode, false, true);
}
protected function _find($filter, $hydrationMode = ETCore::HYDRATE_ARRAY, $one = false)
{
$typeName = null;
if ($filter instanceof ExactTarget_SimpleFilterPart)
{
$typeName = 'SimpleFilterPart';
}
else if ($filter instanceof ExactTarget_ComplexFilterPart)
{
$typeName = 'ComplexFilterPart';
}
else
{
throw new ETException('First parameter must be of type ExactTarget_SimpleFilterPart or ExactTarget_ComplexFilterPart.');
}
$rr = new ExactTarget_RetrieveRequest();
$rr->ObjectType = "Subscriber";
$rr->Properties = $this->retrievableProperties();
$rr->Filter = ETCore::toSoapVar($filter, $typeName);
$rr->Options = null;
$rrm = new ExactTarget_RetrieveRequestMsg();
$rrm->RetrieveRequest = $rr;
$result = $this->soapClient->Retrieve($rrm);
ETCore::evaluateSoapResult($result);
return $this->hydrate($result, $hydrationMode, $one);
}
/**
* Subset of properties that are retrievable with a Retrieve() request.
* This was determined by trial and error.
*
* @return array
*/
protected function retrievableProperties()
{
$properties = array(
// 'Addresses', // SubscriberAddress[] Indicates addresses belonging to a subscriber.
// 'Attributes', // Attribute[] Specifies attributes associated with an object.
// 'Client', // ClientID Specifies the account ownership and context of an object.
// 'CorrelationID', // xsd:string Identifies correlation of objects across several requests.
'CreatedDate', // xsd:dateTime Read-only date and time of the object's creation.
// 'CustomerKey', // xsd:string User-supplied unique identifier for an object within an object type.
'EmailAddress', // xsd:string Contains the email address for a subscriber. Indicates the data extension field contains email address data.
'EmailTypePreference', // EmailType The format in which email should be sent
// 'GlobalUnsubscribeCategory', // GlobalUnsubscribeCategory Indicates how the application handles a globally unsubscribed subscriber.
'ID', // xsd:int Read-only legacy identifier for an object. Not supported on all objects.
// 'Lists', // SubscriberList[] Defines lists a subscriber resides on.
// 'Locale', // Locale Contains the locale information for an Account.
// 'ModifiedDate', // Nullable`1 Last time object information was modified.
// 'ObjectID', // xsd:string System-controlled, read-only text string identifier for object.
// 'ObjectState', // xsd:string Reserved for future use.
// 'Owner', // Owner Describes account ownership of subscriber in an on-your-behalf account.
'PartnerKey', // xsd:string Unique identifier provided by partner for an object, accessible only via API.
// 'PartnerProperties', // APIProperty[] A collection of metadata supplied by client and stored by system - only accessible via API.
// 'PartnerType', // xsd:string Defines partner associated with a subscriber.
// 'PrimaryEmailAddress', // EmailAddress Indicates primary email address for a subscriber.
// 'PrimarySMSAddress', // SMSAddress Indicates primary SMS address for a subscriber.
// 'PrimarySMSPublicationStatus', // SubscriberAddressStatus Indicates the subscriber's modality status.
'Status', // SubscriberStatus Defines status of object. Status of an address.
'SubscriberKey', // xsd:string Identification of a specific subscriber.
// 'SubscriberTypeDefinition', // SubscriberTypeDefinition Specifies if a subscriber resides in an integration, such as Salesforce or Microsoft Dynamics CRM
'UnsubscribedDate'
);
return $properties;
}
/**
* Hydrate the result set.
*
* @param mixed $soapResult The soap result object
* @param int $hydrationMode The hydration mode
*
* @return mixed Either an array or an ETCollection object
*/
protected function hydrate($soapResult, $hydrationMode, $one = false)
{
$final = null;
$result = $soapResult->Results;
if (!is_array($result))
{
$result = array($result);
}
if ($hydrationMode === ETCore::HYDRATE_ARRAY)
{
$final = array();
}
else if ($hydrationMode === ETCore::HYDRATE_RECORD)
{
$final = new ETCollection();
}
foreach ($result as $soapSub)
{
$sub = new $this->subscriberClassName();
$sub->fromSoapResult($soapSub);
if ($hydrationMode === ETCore::HYDRATE_ARRAY)
{
$final[] = $sub->toArray();
if ($one)
{
$final = $sub->toArray();
break;
}
}
else if ($hydrationMode === ETCore::HYDRATE_RECORD)
{
$final->add($sub);
if ($one)
{
$final = $sub;
break;
}
}
}
return $final;
}
protected function newSimpleFilterPart($property, $value, $operator = ExactTarget_SimpleOperators::equals)
{
$sfp = new ExactTarget_SimpleFilterPart();
$sfp->Value = array($value);
$sfp->SimpleOperator = $operator;
$sfp->Property = $property;
return $sfp;
}
}