Maileon PHP client  1.2.5
Easily integrate your PHP application with Maileon.
Mailing.php
1 <?php
2 
9 {
10  public $id;
11  public $fields;
12 
21  function __construct(
22  $id = null,
23  $fields = array())
24  {
25  $this->id = $id;
26  $this->fields = $fields;
27  }
28 
35  function fromXML($xmlElement)
36  {
37  if (isset($xmlElement->id)) $this->id = $xmlElement->id;
38 
39  if (isset($xmlElement->fields)) {
40  $this->fields = array();
41  foreach ($xmlElement->fields->children() as $field) {
42  $this->fields[trim($field->name)] = (string)$field->value; // The trim is required to make a safer string from the object
43  }
44  }
45  }
46 
56  function getFieldValue($fieldName)
57  {
58  $name = trim($fieldName);
59  if (isset($this->fields)) {
60  return ($this->fields[$name]);
61  }
62  return;
63  }
64 
73  function toXML($addXMLDeclaration = true)
74  {
75  $xmlString = $addXMLDeclaration ? "<?xml version=\"1.0\"?><mailing></mailing>" : "<mailing></mailing>";
76  $xml = new SimpleXMLElement($xmlString);
77 
78  if (isset($this->id)) $xml->addChild("id", $this->id);
79 
80  if (isset($this->fields)) {
81  $standard_fields = $xml->addChild("fields");
82  foreach ($this->fields as $index => $value) {
83  $field = $standard_fields->addChild("field");
84  $field->addChild("name", $index);
85 
86  com_maileon_api_xml_XMLUtils::addChildAsCDATA($field, "value", $value);
87  }
88  }
89 
90  return $xml;
91  }
92 
99  function toXMLString()
100  {
101  $xml = $this->toXML();
102  return $xml->asXML();
103  }
104 
111  function toString()
112  {
113 
114  // Generate standard field string
115  $fields = "";
116  if (isset($this->fields)) {
117  foreach ($this->fields as $index => $value) {
118  $fields .= $index . "=" . $value . ",";
119  }
120  $fields = rtrim($fields, ',');
121  }
122 
123  return "Mailing [id=" . $this->id . ", fields={" . $fields . "}]";
124  }
125 }
__construct($id=null, $fields=array())
Definition: Mailing.php:21
static addChildAsCDATA($parent, $name, $value=NULL)
Definition: XMLUtils.php:30
toXML($addXMLDeclaration=true)
Definition: Mailing.php:73