Maileon PHP client  1.2.5
Easily integrate your PHP application with Maileon.
ContactEvent.php
1 <?php
2 
9 {
10  public $email;
11  public $external_id;
12  public $properties;
13 
17  function __construct()
18  {
19  $this->properties = array();
20  }
21 
32  function setProperty($key, $value)
33  {
34  if ($value === true) $this->properties[$key] = 1;
35  else if ($value === false) $this->properties[$key] = 0;
36  else $this->properties[$key] = $value;
37  }
38 
44  function fromXML($xmlElement)
45  {
46  }
47 
52  function toXML()
53  {
54  $xml = new SimpleXMLElement("<?xml version=\"1.0\"?><event></event>");
55 
56  // Some fields are mandatory, especially when setting data to the API
57  if (isset($this->email)) $xml->addChild("email", $this->email);
58  if (isset($this->external_id)) $xml->addChild("external_id", $this->external_id);
59 
60  if (count($this->properties) > 0) {
61  foreach ($this->properties as $index => $value) {
62 
63  // If value exists, add it, else add nul="true"
64  if (isset($value)) {
65  $property = $xml->addChild("property", $value);
66  } else {
67  $property = $xml->addChild("property");
68  $property->addAttribute("nil", true);
69  }
70 
71  $property->addAttribute("key", $index);
72  }
73  }
74 
75  return $xml;
76  }
77 
82  function toXMLString()
83  {
84  $xml = $this->toXML();
85  return $xml->asXML();
86  }
87 
92  function toString()
93  {
94 
95  // Generate standard field string
96  $properties = "";
97  if (count($this->properties) > 0) {
98  foreach ($this->properties as $index => $value) {
99  $properties .= $index . "=" . $value . ",";
100  }
101  $properties = rtrim($properties, ',');
102  }
103 
104  return "ContactEvent [email=" . $this->email . ", external_id=" . $this->external_id . ", properties={" . $properties . "}]";
105  }
106 }