Maileon PHP client  1.3.2
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 
53  function __construct(
54  $id = null,
55  $name = null,
56  $attributes = array(),
57  $archivingDuration = null,
58  $storeOnly = false)
59  {
60  $this->id = $id;
61  $this->name = $name;
62  $this->attributes = $attributes;
63  $this->archivingDuration = $archivingDuration;
64  $this->storeOnly = $storeOnly;
65  }
66 
73  function fromXML($xmlElement)
74  {
75  if (isset($xmlElement->id)) $this->id = $xmlElement->id;
76  if (isset($xmlElement->name)) $this->name = $xmlElement->name;
77 
78  if (isset($xmlElement->attributes)) {
79  $this->attributes = array();
80  foreach ($xmlElement->attributes->children() as $xmlAttribute) {
81  $attribute = array();
82  if (isset($xmlAttribute->id)) $attribute['id'] = trim($xmlAttribute->id);
83  if (isset($xmlAttribute->name)) $attribute['name'] = trim($xmlAttribute->name);
84  if (isset($xmlAttribute->type)) $attribute['type'] = com_maileon_api_transactions_DataType::getDataType($xmlAttribute->type);
85  if (isset($xmlAttribute->required)) $attribute['required'] = $xmlAttribute->required;
86  if (isset($xmlAttribute->archivingDuration)) $attribute['archivingDuration'] = $xmlAttribute->archivingDuration;
87  if (isset($xmlAttribute->storeOnly)) $attribute['storeOnly'] = $xmlAttribute->storeOnly;
88  array_push($this->attributes, $attribute);
89  }
90  }
91  }
92 
97  function toString()
98  {
99  // Generate attributes string
100  $attributes = "[";
101  if (isset($this->attributes)) {
102  foreach ($this->attributes as $index => $value) {
103  $attributes .= "attribute (id=" . $value['id'] . ", name=" . $value['name'] . ", type=" . $value['type']->getValue() . ", required=" . (($value['required'] == true) ? "true" : "false") . "), ";
104  }
105  $attributes = rtrim($attributes, ' ');
106  $attributes = rtrim($attributes, ',');
107  }
108  $attributes .= "]";
109 
110  return "TransactionType [id=" . $this->id . ", name=" . $this->name . ", archivingDuration=" . $this->archivingDuration . ", storeOnly=" . $this->storeOnly . ", attributes=" . $attributes . "]";
111  }
112 
117  function toXML()
118  {
119  $xml = new SimpleXMLElement("<?xml version=\"1.0\"?><transaction_type></transaction_type>");
120 
121  // Some fields are mandatory, especially when setting data to the API
122  if (isset($this->id)) $xml->addChild("id", $this->id);
123  if (isset($this->name)) $xml->addChild("name", $this->name);
124  if (isset($this->archivingDuration)) $xml->addChild("archivingDuration", $this->archivingDuration);
125  if (isset($this->storeOnly)) $xml->addChild("storeOnly", ($this->storeOnly==true)?"true":"false");
126 
127  if (isset($this->attributes) && sizeof($this->attributes) > 0) {
128 
129  $attributes = $xml->addChild("attributes");
130  foreach ($this->attributes as $index => $value) {
131  $field = $attributes->addChild("attribute");
132  $field->addChild("id", $value->id);
133  $field->addChild("name", $value->name);
134  $field->addChild("type", $value->type->getValue());
135  $field->addChild("required", ($value->required == true) ? "true" : "false");
136  }
137  }
138 
139  return $xml;
140  }
141 
146  function toXMLString()
147  {
148  $xml = $this->toXML();
149  return $xml->asXML();
150  }
151 }
__construct($id=null, $name=null, $attributes=array(), $archivingDuration=null, $storeOnly=false)