@@ -24,6 +24,7 @@ class Contact extends AbstractXMLWrapper
2424 public $ updated ;
2525 public $ standard_fields ;
2626 public $ custom_fields ;
27+ public $ preferences ;
2728
2829 /**
2930 * Constructor initializing default values.
@@ -51,7 +52,8 @@ public function __construct(
5152 $ standard_fields = array (),
5253 $ custom_fields = array (),
5354 $ created = null ,
54- $ updated = null
55+ $ updated = null ,
56+ $ preferences = array ()
5557 ) {
5658 $ this ->id = $ id ;
5759 $ this ->email = $ email ;
@@ -62,6 +64,7 @@ public function __construct(
6264 $ this ->custom_fields = $ custom_fields ;
6365 $ this ->created = $ created ;
6466 $ this ->updated = $ updated ;
67+ $ this ->preferences = $ preferences ;
6568 }
6669
6770 /**
@@ -110,6 +113,15 @@ public function fromXML($xmlElement)
110113 // The trim is required to make a safer string from the object
111114 }
112115 }
116+
117+ if (isset ($ xmlElement ->preferences )) {
118+ $ this ->preferences = array ();
119+ foreach ($ xmlElement ->preferences ->children () as $ preference ) {
120+ $ preference_obj = new Preference ();
121+ $ preference_obj ->fromXML ($ preference );
122+ array_push ($ this ->preferences , $ preference_obj );
123+ }
124+ }
113125 }
114126
115127 /**
@@ -146,7 +158,6 @@ public function toXML($addXMLDeclaration = true)
146158 if (isset ($ this ->anonymous )) {
147159 $ xml ->addChild ("anonymous " , $ this ->anonymous );
148160 }
149-
150161 if (isset ($ this ->created )) {
151162 $ xml ->addChild ("created " , $ this ->created );
152163 }
@@ -176,6 +187,19 @@ public function toXML($addXMLDeclaration = true)
176187 }
177188 }
178189
190+ if (isset ($ this ->preferences )) {
191+ $ preferences_field = $ xml ->addChild ("preferences " );
192+ foreach ($ this ->preferences as $ preference ) {
193+ $ preference_field = $ preferences_field ->addChild ("preference " );
194+ $ preference_field ->addChild ("name " , $ preference ->name );
195+ $ preference_field ->addChild ("category " , $ preference ->category );
196+
197+ XMLUtils::addChildAsCDATA ($ preference_field , "value " , $ preference ->value );
198+
199+ $ preference_field ->addChild ("source " , $ preference ->source );
200+ }
201+ }
202+
179203 return $ xml ;
180204 }
181205
@@ -218,6 +242,14 @@ public function toString()
218242 $ customfields = rtrim ($ customfields , ', ' );
219243 }
220244
245+ $ preferences = "" ;
246+ if (isset ($ this ->preferences )) {
247+ foreach ($ this ->preferences as $ preference ) {
248+ $ preferences .= $ preference ->toString () . ", " ;
249+ }
250+ $ preferences = rtrim ($ preferences , ', ' );
251+ }
252+
221253 $ permission = "" ;
222254 if (isset ($ this ->permission )) {
223255 $ permission = $ this ->permission ->getCode ();
@@ -227,7 +259,8 @@ public function toString()
227259 . $ this ->email . ", permission= " . $ permission . ", external_id= " . $ this ->external_id
228260 . ", anonymous= " . (($ this ->anonymous == true ) ? "true " : "false " ) .
229261 ", created= " . $ this ->created . ", updated= " . $ this ->updated
230- . ", standard_fields={ " . $ standard_fields . "}, customfields={ " . $ customfields . "}] " ;
262+ . ", standard_fields={ " . $ standard_fields . "}, customfields={ " . $ customfields .
263+ "}, preferences={ " . $ preferences . "}] " ;
231264 }
232265
233266 /**
@@ -259,6 +292,16 @@ public function toCsvString()
259292 }
260293 $ customfields .= "} " ;
261294
295+ // Generate preferences string
296+ $ preferences = "{ " ;
297+ if (isset ($ this ->preferences )) {
298+ foreach ($ this ->preferences as $ preference ) {
299+ $ preferences .= "{ " . $ preference ->toCsvString () . "}, " ;
300+ }
301+ $ preferences = rtrim ($ preferences , ', ' );
302+ }
303+ $ preferences .= "} " ;
304+
262305 $ permission = "" ;
263306 if (isset ($ this ->permission )) {
264307 $ permission = $ this ->permission ->getCode ();
@@ -272,6 +315,7 @@ public function toCsvString()
272315 . "; " . $ this ->created
273316 . "; " . $ this ->updated
274317 . "; \"" . $ standard_fields . "\""
275- . "; \"" . $ customfields . "\"" ;
318+ . "; \"" . $ customfields . "\""
319+ . "; \"" . $ preferences . "\"" ;
276320 }
277321}
0 commit comments