Maileon PHP client  1.5.5
Easily integrate your PHP application with Maileon.
TransactionType.php
1 <?php
2 
10 {
15  public $id;
16 
21  public $name;
22 
27  public $description;
28 
33  public $attributes;
34 
39  public $archivingDuration;
40 
45  public $storeOnly;
46 
67  function __construct(
68  $id = null,
69  $name = null,
70  $attributes = array(),
71  $archivingDuration = null,
72  $storeOnly = false,
73  $description = null)
74  {
75  $this->id = $id;
76  $this->name = $name;
77  $this->attributes = $attributes;
78  $this->archivingDuration = $archivingDuration;
79  $this->storeOnly = $storeOnly;
80  $this->description = $description;
81  }
82 
89  function fromXML($xmlElement)
90  {
91  if (isset($xmlElement->id)) $this->id = (int)$xmlElement->id;
92  if (isset($xmlElement->name)) $this->name = (string)$xmlElement->name;
93  if (isset($xmlElement->description)) $this->description = (string)$xmlElement->description;
94  if (isset($xmlElement->archivingDuration)) $this->archivingDuration = (int)$xmlElement->archivingDuration;
95  if (isset($xmlElement->storeOnly))$this->storeOnly = (string)$xmlElement->storeOnly;
96 
97  if (isset($xmlElement->attributes)) {
98  $this->attributes = array();
99  foreach ($xmlElement->attributes->children() as $xmlAttribute) {
100  $attribute = new stdClass();
101  if (isset($xmlAttribute->id)) $attribute->id = (int)$xmlAttribute->id;
102  if (isset($xmlAttribute->name)) $attribute->name = trim((string)$xmlAttribute->name);
103  if (isset($xmlAttribute->description)) $attribute->description = trim((string)$xmlAttribute->description);
104  if (isset($xmlAttribute->type)) $attribute->type = com_maileon_api_transactions_DataType::getDataType($xmlAttribute->type);
105  if (isset($xmlAttribute->required)) $attribute->required = (string)$xmlAttribute->required;
106  array_push($this->attributes, $attribute);
107  }
108  }
109  }
110 
115  function toString()
116  {
117  // Generate attributes string
118  $attributes = "[";
119  if (isset($this->attributes)) {
120  foreach ($this->attributes as $index => $value) {
121  echo $value['name']."<br />";
122  $attributes .= "attribute (id=" . $value['id'] . ", name=" . $value['name'] . ", description=" . ((!empty($value['description']))?$value['description']:"") . ", type=" . $value['type']->getValue() . ", required=" . (($value['required'] == true) ? "true" : "false") . "), ";
123  }
124  $attributes = rtrim($attributes, ' ');
125  $attributes = rtrim($attributes, ',');
126  }
127  $attributes .= "]";
128 
129  return "TransactionType [id=" . $this->id . ", name=" . $this->name . ", description=" . $this->description . ", archivingDuration=" . $this->archivingDuration . ", storeOnly=" . $this->storeOnly . ", attributes=" . $attributes . "]";
130  }
131 
136  function toXML()
137  {
138  $xml = new SimpleXMLElement("<?xml version=\"1.0\"?><transaction_type></transaction_type>");
139 
140  // Some fields are mandatory, especially when setting data to the API
141  if (isset($this->id)) $xml->addChild("id", $this->id);
142  if (isset($this->name)) $xml->addChild("name", $this->name);
143  if (isset($this->name)) $xml->addChild("description", $this->description);
144  if (isset($this->archivingDuration)) $xml->addChild("archivingDuration", $this->archivingDuration);
145  if (isset($this->storeOnly)) $xml->addChild("storeOnly", ($this->storeOnly === true || $this->storeOnly === "true")?"true":"false");
146 
147  if (isset($this->attributes) && sizeof($this->attributes) > 0) {
148 
149  $attributes = $xml->addChild("attributes");
150  foreach ($this->attributes as $index => $value) {
151  $field = $attributes->addChild("attribute");
152  if (!empty($value->id)) $field->addChild("id", $value->id);
153  if (!empty($value->name)) $field->addChild("name", $value->name);
154  if (!empty($value->description)) $field->addChild("description", $value->description);
155  if (!empty($value->type)) $field->addChild("type", $value->type->getValue());
156  if (!empty($value->required)) $field->addChild("required", ($value->required === true || $value->required === "true") ? "true" : "false");
157  }
158  }
159 
160  return $xml;
161  }
162 
167  function toXMLString()
168  {
169  $xml = $this->toXML();
170  return $xml->asXML();
171  }
172 }
__construct($id=null, $name=null, $attributes=array(), $archivingDuration=null, $storeOnly=false, $description=null)