18 public $standard_fields;
19 public $custom_fields;
44 $standard_fields = array(),
45 $custom_fields = array(),
50 $this->email = $email;
51 $this->permission = $permission;
52 $this->external_id = $external_id;
53 $this->anonymous = $anonymous;
54 $this->standard_fields = $standard_fields;
55 $this->custom_fields = $custom_fields;
56 $this->created = $created;
57 $this->updated = $updated;
69 if (isset($xmlElement->id)) $this->
id = $xmlElement->id;
70 $this->email = $xmlElement->email;
72 if (isset($xmlElement->external_id)) $this->external_id = $xmlElement->external_id;
73 if (isset($xmlElement->anonymous)) $this->anonymous = $xmlElement->anonymous;
74 if (isset($xmlElement[
'anonymous'])) $this->anonymous = $xmlElement[
'anonymous'];
76 if (isset($xmlElement->created)) $this->created = $xmlElement->created;
77 if (isset($xmlElement->updated)) $this->updated = $xmlElement->updated;
79 if (isset($xmlElement->standard_fields)) {
80 $this->standard_fields = array();
81 foreach ($xmlElement->standard_fields->children() as $field) {
82 $this->standard_fields[trim($field->name)] = (string)$field->value;
86 if (isset($xmlElement->custom_fields)) {
87 foreach ($xmlElement->custom_fields->children() as $field) {
88 $this->custom_fields[trim($field->name)] = (string)$field->value;
101 function toXML($addXMLDeclaration =
true)
103 $xmlString = $addXMLDeclaration ?
"<?xml version=\"1.0\"?><contact></contact>" :
"<contact></contact>";
104 $xml =
new SimpleXMLElement($xmlString);
107 if (isset($this->
id)) $xml->addChild(
"id", $this->
id);
111 if (isset($this->email)) {
112 $emailChild = $xml->addChild(
"email");
113 $xml->email = $this->email;
115 if (isset($this->permission)) $xml->addChild(
"permission", $this->permission->getCode());
116 if (isset($this->external_id) && $this->external_id != -1) $xml->addChild(
"external_id", $this->external_id);
117 if (isset($this->anonymous)) $xml->addChild(
"anonymous", $this->anonymous);
119 if (isset($this->created)) $xml->addChild(
"created", $this->created);
120 if (isset($this->updated)) $xml->addChild(
"updated", $this->updated);
122 if (isset($this->standard_fields)) {
123 $standard_fields = $xml->addChild(
"standard_fields");
124 foreach ($this->standard_fields as $index => $value) {
125 $field = $standard_fields->addChild(
"field");
126 $field->addChild(
"name", $index);
133 if (isset($this->custom_fields)) {
134 $customfields = $xml->addChild(
"custom_fields");
135 foreach ($this->custom_fields as $index => $value) {
136 $field = $customfields->addChild(
"field");
137 $field->addChild(
"name", $index);
155 $xml = $this->
toXML();
156 return $xml->asXML();
169 $standard_fields =
"";
170 if (isset($this->standard_fields)) {
171 foreach ($this->standard_fields as $index => $value) {
172 $standard_fields .= $index .
"=" . $value .
",";
174 $standard_fields = rtrim($standard_fields,
',');
179 if (isset($this->custom_fields)) {
180 foreach ($this->custom_fields as $index => $value) {
181 $customfields .= $index .
"=" . $value .
",";
183 $customfields = rtrim($customfields,
',');
187 if (isset($this->permission)) {
188 $permission = $this->permission->getCode();
191 return "Contact [id=" . $this->
id .
", email="
192 . $this->email .
", permission=" . $permission .
", external_id=" . $this->external_id
193 .
", anonymous=" . (($this->anonymous ==
true) ?
"true" :
"false") .
", created=" . $this->created .
", updated=" . $this->updated
194 .
", standard_fields={" . $standard_fields .
"}, customfields={" . $customfields .
"}]";
207 $standard_fields =
"{";
208 if (isset($this->standard_fields)) {
209 foreach ($this->standard_fields as $index => $value) {
210 $standard_fields .= $index .
"=" . $value .
",";
212 $standard_fields = rtrim($standard_fields,
',');
214 $standard_fields .=
"}";
218 if (isset($this->custom_fields)) {
219 foreach ($this->custom_fields as $index => $value) {
220 $customfields .= $index .
"=" . $value .
",";
222 $customfields = rtrim($customfields,
',');
224 $customfields .=
"}";
227 if (isset($this->permission)) {
228 $permission = $this->permission->getCode();
234 .
";" . $this->external_id
235 .
";" . (($this->anonymous ==
true) ?
"true" :
"false")
236 .
";" . $this->created
237 .
";" . $this->updated
238 .
";\"" . $standard_fields .
"\""
239 .
";\"" . $customfields .
"\"";
static addChildAsCDATA($parent, $name, $value=NULL)