Maileon PHP client  1.2.5
Easily integrate your PHP application with Maileon.
TransactionType.php
1 <?php
2 
10 {
15  public $id;
16 
21  public $name;
22 
27  public $attributes;
28 
33  public $archivingDuration;
34 
47  function __construct(
48  $id = null,
49  $name = null,
50  $attributes = array(),
51  $archivingDuration = null)
52  {
53  $this->id = $id;
54  $this->name = $name;
55  $this->attributes = $attributes;
56  $this->archivingDuration = $archivingDuration;
57  }
58 
65  function fromXML($xmlElement)
66  {
67  if (isset($xmlElement->id)) $this->id = $xmlElement->id;
68  if (isset($xmlElement->name)) $this->name = $xmlElement->name;
69 
70  if (isset($xmlElement->attributes)) {
71  $this->attributes = array();
72  foreach ($xmlElement->attributes->children() as $xmlAttribute) {
73  $attribute = array();
74  if (isset($xmlAttribute->id)) $attribute['id'] = trim($xmlAttribute->id);
75  if (isset($xmlAttribute->name)) $attribute['name'] = trim($xmlAttribute->name);
76  if (isset($xmlAttribute->type)) $attribute['type'] = com_maileon_api_transactions_DataType::getDataType($xmlAttribute->type);
77  if (isset($xmlAttribute->required)) $attribute['required'] = $xmlAttribute->required;
78  if (isset($xmlAttribute->archivingDuration)) $attribute['archivingDuration'] = $xmlAttribute->archivingDuration;
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 (id=" . $value['id'] . ", name=" . $value['name'] . ", type=" . $value['type']->getValue() . ", required=" . (($value['required'] == true) ? "true" : "false") . "), ";
95  }
96  $attributes = rtrim($attributes, ' ');
97  $attributes = rtrim($attributes, ',');
98  }
99  $attributes .= "]";
100 
101  return "TransactionType [id=" . $this->id . ", name=" . $this->name . ", archivingDuration=" . $this->archivingDuration . ", attributes=" . $attributes . "]";
102  }
103 
108  function toXML()
109  {
110  $xml = new SimpleXMLElement("<?xml version=\"1.0\"?><transaction_type></transaction_type>");
111 
112  // Some fields are mandatory, especially when setting data to the API
113  if (isset($this->id)) $xml->addChild("id", $this->id);
114  if (isset($this->name)) $xml->addChild("name", $this->name);
115  if (isset($this->archivingDuration)) $xml->addChild("archivingDuration", $this->archivingDuration);
116 
117  if (isset($this->attributes) && sizeof($this->attributes) > 0) {
118 
119  $attributes = $xml->addChild("attributes");
120  foreach ($this->attributes as $index => $value) {
121  $field = $attributes->addChild("attribute");
122  $field->addChild("id", $value->id);
123  $field->addChild("name", $value->name);
124  $field->addChild("type", $value->type->getValue());
125  $field->addChild("required", ($value->required == true) ? "true" : "false");
126  }
127  }
128 
129  return $xml;
130  }
131 
136  function toXMLString()
137  {
138  $xml = $this->toXML();
139  return $xml->asXML();
140  }
141 }
__construct($id=null, $name=null, $attributes=array(), $archivingDuration=null)