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 4.8.6 4.8.7 4.8.8 4.8.9 4.9.0 4.9.1 4.9.10 4.9.11 4.9.12 4.9.13 4.9.14 4.9.15 4.9.16 4.9.17 4.9.18 4.9.19 4.9.2 4.9.20 4.9.21 4.9.3 4.9.4 4.9.5 4.9.6 4.9.7 4.9.8 4.9.9 trunk 1.1.5 1.2.1 1.2.3 1.2.4 1.2.5 1.3 1.3.1 1.4 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8
mailchimp-for-wp / includes / class-list-data-mapper.php
mailchimp-for-wp / includes Last commit date
admin 8 years ago api 8 years ago forms 8 years ago integrations 8 years ago mailchimp 8 years ago views 8 years ago class-array-bag.php 8 years ago class-container.php 10 years ago class-debug-log-reader.php 9 years ago class-debug-log.php 9 years ago class-dynamic-content-tags.php 9 years ago class-field-formatter.php 9 years ago class-field-guesser.php 8 years ago class-list-data-mapper.php 8 years ago class-mailchimp.php 8 years ago class-plugin.php 10 years ago class-queue-job.php 10 years ago class-queue.php 9 years ago class-request.php 10 years ago class-tools.php 9 years ago default-actions.php 9 years ago default-filters.php 9 years ago deprecated-functions.php 8 years ago functions.php 8 years ago
class-list-data-mapper.php
161 lines
1 <?php
2
3 /**
4 * Class MC4WP_Field_Map
5 *
6 * @access private
7 * @since 4.0
8 * @ignore
9 */
10 class MC4WP_List_Data_Mapper {
11
12 /**
13 * @var array
14 */
15 private $data = array();
16
17 /**
18 * @var array
19 */
20 private $list_ids = array();
21
22 /**
23 * @var MC4WP_Field_Formatter
24 */
25 private $formatter;
26
27 /**
28 * @param array $data
29 * @param array $list_ids
30 */
31 public function __construct( array $data, array $list_ids ) {
32 $this->data = array_change_key_case( $data, CASE_UPPER );
33 $this->list_ids = $list_ids;
34 $this->formatter = new MC4WP_Field_Formatter();
35
36 if( ! isset( $this->data['EMAIL'] ) ) {
37 throw new InvalidArgumentException( 'Data needs at least an EMAIL key.' );
38 }
39 }
40
41 /**
42 * @return MC4WP_MailChimp_Subscriber[]
43 */
44 public function map() {
45 $mailchimp = new MC4WP_MailChimp();
46 $map = array();
47
48 foreach( $this->list_ids as $list_id ) {
49 $list = $mailchimp->get_list( $list_id, true );
50
51 if( $list instanceof MC4WP_MailChimp_List ) {
52 $map[ $list_id ] = $this->map_list( $list );
53 }
54 }
55
56 return $map;
57 }
58
59 /**
60 * @param MC4WP_MailChimp_List $list
61 *
62 * @return MC4WP_MailChimp_Subscriber
63 */
64 protected function map_list( MC4WP_MailChimp_List $list ) {
65
66 $subscriber = new MC4WP_MailChimp_Subscriber();
67 $subscriber->email_address = $this->data['EMAIL'];
68
69 // find merge fields
70 foreach( $list->merge_fields as $merge_field ) {
71
72 // skip EMAIL field as that is handled separately (see above)
73 if( $merge_field->tag === 'EMAIL' ) {
74 continue;
75 }
76
77 if( ! isset( $this->data[ $merge_field->tag ] ) ) {
78 continue;
79 }
80
81 // format field value
82 $value = $this->data[ $merge_field->tag ];
83 $value = $this->format_merge_field_value( $value, $merge_field->field_type );
84
85 // add to map
86 $subscriber->merge_fields[ $merge_field->tag ] = $value;
87 }
88
89 // find interest categories
90 if( ! empty( $this->data['INTERESTS'] ) ) {
91 foreach( $list->interest_categories as $interest_category ) {
92 foreach( $interest_category->interests as $interest_id => $interest_name ) {
93
94 // straight lookup by ID as key with value copy.
95 if( isset( $this->data['INTERESTS'][ $interest_id ] ) ) {
96 $subscriber->interests[ $interest_id ] = $this->formatter->boolean( $this->data['INTERESTS'][ $interest_id ] );
97 }
98
99 // straight lookup by ID as top-level value
100 if( in_array( $interest_id, $this->data['INTERESTS'], false ) ) {
101 $subscriber->interests[ $interest_id ] = true;
102 }
103
104 // look in array with category ID as key.
105 if( isset( $this->data['INTERESTS'][ $interest_category->id ] ) ) {
106 $value = $this->data['INTERESTS'][ $interest_category->id ];
107 $values = is_array( $value ) ? $value : array_map( 'trim', explode( '|', $value ) );
108
109 // find by category ID + interest ID
110 if( in_array( $interest_id, $values, false ) ) {
111 $subscriber->interests[ $interest_id ] = true;
112 }
113
114 // find by category ID + interest name
115 if( in_array( $interest_name, $values ) ) {
116 $subscriber->interests[ $interest_id ] = true;
117 }
118 }
119 }
120 }
121 }
122
123 // find language
124 /* @see http://kb.mailchimp.com/lists/managing-subscribers/view-and-edit-subscriber-languages?utm_source=mc-api&utm_medium=docs&utm_campaign=apidocs&_ga=1.211519638.2083589671.1469697070 */
125 if( ! empty( $this->data['MC_LANGUAGE'] ) ) {
126 $subscriber->language = $this->formatter->language( $this->data['MC_LANGUAGE'] );
127 }
128
129 return $subscriber;
130 }
131
132
133 /**
134 * @param mixed $field_value
135 * @param string $field_type
136 *
137 * @return mixed
138 */
139 private function format_merge_field_value( $field_value, $field_type ) {
140 $field_type = strtolower( $field_type );
141
142 if( method_exists( $this->formatter, $field_type ) ) {
143 $field_value = call_user_func( array( $this->formatter, $field_type ), $field_value );
144 }
145
146 /**
147 * Filters the value of a field after it is formatted.
148 *
149 * Use this to format a field value according to the field type (in MailChimp).
150 *
151 * @since 3.0
152 * @param string $field_value The value
153 * @param string $field_type The type of the field (in MailChimp)
154 */
155 $field_value = apply_filters( 'mc4wp_format_field_value', $field_value, $field_type );
156
157 return $field_value;
158 }
159
160 }
161