Maileon PHP client  1.5.0
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 
61  function __construct(
62  $id = null,
63  $name = null,
64  $attributes = array(),
65  $archivingDuration = null,
66  $storeOnly = false,
67  $description = null)
68  {
69  $this->id = $id;
70  $this->name = $name;
71  $this->attributes = $attributes;
72  $this->archivingDuration = $archivingDuration;
73  $this->storeOnly = $storeOnly;
74  $this->description = $description;
75  }
76 
83  function fromXML($xmlElement)
84  {
85  if (isset($xmlElement->id)) $this->id = $xmlElement->id;
86  if (isset($xmlElement->name)) $this->name = $xmlElement->name;
87  if (isset($xmlElement->description)) $this->description = $xmlElement->description;
88 
89  if (isset($xmlElement->attributes)) {
90  $this->attributes = array();
91  foreach ($xmlElement->attributes->children() as $xmlAttribute) {
92  $attribute = array();
93  if (isset($xmlAttribute->id)) $attribute['id'] = trim($xmlAttribute->id);
94  if (isset($xmlAttribute->name)) $attribute['name'] = trim($xmlAttribute->name);
95  if (isset($xmlAttribute->description)) $attribute['description'] = trim($xmlAttribute->description);
96  if (isset($xmlAttribute->type)) $attribute['type'] = com_maileon_api_transactions_DataType::getDataType($xmlAttribute->type);
97  if (isset($xmlAttribute->required)) $attribute['required'] = $xmlAttribute->required;
98  if (isset($xmlAttribute->archivingDuration)) $attribute['archivingDuration'] = $xmlAttribute->archivingDuration;
99  if (isset($xmlAttribute->storeOnly)) $attribute['storeOnly'] = $xmlAttribute->storeOnly;
100  array_push($this->attributes, $attribute);
101  }
102  }
103  }
104 
109  function toString()
110  {
111  // Generate attributes string
112  $attributes = "[";
113  if (isset($this->attributes)) {
114  foreach ($this->attributes as $index => $value) {
115  echo $value['name']."<br />";
116  $attributes .= "attribute (id=" . $value['id'] . ", name=" . $value['name'] . ", description=" . ((!empty($value['description']))?$value['description']:"") . ", type=" . $value['type']->getValue() . ", required=" . (($value['required'] == true) ? "true" : "false") . "), ";
117  }
118  $attributes = rtrim($attributes, ' ');
119  $attributes = rtrim($attributes, ',');
120  }
121  $attributes .= "]";
122 
123  return "TransactionType [id=" . $this->id . ", name=" . $this->name . ", description=" . $this->description . ", archivingDuration=" . $this->archivingDuration . ", storeOnly=" . $this->storeOnly . ", attributes=" . $attributes . "]";
124  }
125 
130  function toXML()
131  {
132  $xml = new SimpleXMLElement("<?xml version=\"1.0\"?><transaction_type></transaction_type>");
133 
134  // Some fields are mandatory, especially when setting data to the API
135  if (isset($this->id)) $xml->addChild("id", $this->id);
136  if (isset($this->name)) $xml->addChild("name", $this->name);
137  if (isset($this->name)) $xml->addChild("description", $this->description);
138  if (isset($this->archivingDuration)) $xml->addChild("archivingDuration", $this->archivingDuration);
139  if (isset($this->storeOnly)) $xml->addChild("storeOnly", ($this->storeOnly==true)?"true":"false");
140 
141  if (isset($this->attributes) && sizeof($this->attributes) > 0) {
142 
143  $attributes = $xml->addChild("attributes");
144  foreach ($this->attributes as $index => $value) {
145  $field = $attributes->addChild("attribute");
146  $field->addChild("id", $value->id);
147  $field->addChild("name", $value->name);
148  $field->addChild("description", $value->description);
149  $field->addChild("type", $value->type->getValue());
150  $field->addChild("required", ($value->required == true) ? "true" : "false");
151  }
152  }
153 
154  return $xml;
155  }
156 
161  function toXMLString()
162  {
163  $xml = $this->toXML();
164  return $xml->asXML();
165  }
166 }
__construct($id=null, $name=null, $attributes=array(), $archivingDuration=null, $storeOnly=false, $description=null)