Maileon PHP client  1.5.5
Easily integrate your PHP application with Maileon.
ContactEventType.php
1 <?php
2 
9 {
10  public $id;
11  public $name;
12  public $active;
13  public $anonymizable;
14  public $description;
15  public $created;
16  public $updated;
17 
18  public $attributes;
19 
20  // TODO verify meaning and types of arguments
35  function __construct(
36  $id = null,
37  $name = null,
38  $active = null,
39  $anonymizable = null,
40  $description = null,
41  $created = null,
42  $updated = null,
43  $attributes = array())
44  {
45  $this->id = $id;
46  $this->name = $name;
47  $this->active = $active;
48  $this->anonymizable = $anonymizable;
49  $this->description = $description;
50  $this->created = $created;
51  $this->updated = $updated;
52  $this->attributes = $attributes;
53  }
54 
61  function fromXML($xmlElement)
62  {
63  if (isset($xmlElement->id)) $this->id = $xmlElement->id;
64  if (isset($xmlElement->name)) $this->name = $xmlElement->name;
65  if (isset($xmlElement->active)) $this->active = $xmlElement->active;
66  if (isset($xmlElement->anonymizable)) $this->anonymizable = $xmlElement->anonymizable;
67  if (isset($xmlElement->description)) $this->description = $xmlElement->description;
68  if (isset($xmlElement->created)) $this->created = $xmlElement->created;
69  if (isset($xmlElement->updated)) $this->updated = $xmlElement->updated;
70 
71  if (isset($xmlElement->attributes)) {
72  $this->attributes = array();
73  foreach ($xmlElement->attributes->children() as $xmlAttribute) {
74  $attribute = array();
75  if (isset($xmlAttribute->name)) $attribute['name'] = trim($xmlAttribute->name);
76  if (isset($xmlAttribute->datatype)) $attribute['datatype'] = com_maileon_api_contactevents_DataType::getDataType($xmlAttribute->datatype);
77  if (isset($xmlAttribute->description)) $attribute['description'] = trim($xmlAttribute->description);
78  if (isset($xmlAttribute->required)) $attribute['required'] = $xmlAttribute->required;
79  array_push($this->attributes, $attribute);
80  }
81  }
82  }
83 
88  function toString()
89  {
90  // Generate attributes string
91  $attributes = "[";
92  if (isset($this->attributes)) {
93  foreach ($this->attributes as $index => $value) {
94  $attributes .= "attribute (name=" . $value['name'] . ", datatype=" . $value['datatype']->getValue() . ", description=" . $value['description'] . ", required=" . (($value['required'] == true) ? "true" : "false") . "), ";
95  }
96  $attributes = rtrim($attributes, ' ');
97  $attributes = rtrim($attributes, ',');
98  }
99  $attributes .= "]";
100 
101  return "ContactEventType [id=" . $this->id . ", name=" . $this->name . ", active=" . $this->active . ", anonymizable="
102  . $this->anonymizable . ", description=" . $this->description . ", created=" . $this->created . ", updated=" . $this->updated . ", attributes=" . $attributes . "]";
103  }
104 
109  function toXML()
110  {
111  $xml = new SimpleXMLElement("<?xml version=\"1.0\"?><contacteventtype></contacteventtype>");
112 
113  // Some fields are mandatory, especially when setting data to the API
114  if (isset($this->id)) $xml->addChild("id", $this->id);
115  if (isset($this->active)) $xml->addChild("active", $this->active);
116  if (isset($this->anonymizable)) $xml->addChild("anonymizable", ($this->anonymizable == true) ? "true" : "false");
117  if (isset($this->description)) $xml->addChild("description", $this->description);
118  if (isset($this->created)) $xml->addChild("created", $this->created);
119  if (isset($this->updated)) $xml->addChild("updated", $this->updated);
120  if (isset($this->updated)) $xml->addChild("name", $this->name);
121 
122  if (isset($this->attributes) && sizeof($this->attributes) > 0) {
123 
124  $attributes = $xml->addChild("attributes");
125  foreach ($this->attributes as $index => $value) {
126  $field = $attributes->addChild("attribute");
127  $field->addChild("name", $value->name);
128  $field->addChild("datatype", $value->datatype->getValue());
129  $field->addChild("description", $value->description);
130  $field->addChild("required", ($value->required == true) ? "true" : "false");
131  }
132  }
133 
134  return $xml;
135  }
136 
141  function toXMLString()
142  {
143  $xml = $this->toXML();
144  return $xml->asXML();
145  }
146 }
__construct($id=null, $name=null, $active=null, $anonymizable=null, $description=null, $created=null, $updated=null, $attributes=array())