Maileon PHP client  1.2.5
Easily integrate your PHP application with Maileon.
Transaction.php
1 <?php
2 
16  public $type;
17 
23  public $contact;
24 
31  public $import;
32 
38  public $content;
39 
44  public $attachments;
45 
49  function __construct() {
50  $this->content = array();
51  $this->attachments = array();
52  $this->contact = new com_maileon_api_transactions_ContactReference();
54  $this->import->permission = com_maileon_api_contacts_Permission::$NONE;
55  }
56 
64  function addAttachmentFromFile($filename, $mimetype, $attachmentFileName = null) {
65  $handle = fopen($filename, "rb");
66  if (FALSE === $filename) {
67  throw new com_maileon_api_MaileonAPIException("Cannot read file " . $filename . ".");
68  }
69  $contents = '';
70  while (!feof($handle)) {
71  $contents .= fread($handle, 8192);
72  }
73  fclose($handle);
74  if ($attachmentFileName === null) {
75  $attachmentFileName = basename($filename);
76  }
77  $attachment = new com_maileon_api_transactions_Attachment($attachmentFileName, $mimetype, base64_encode($contents));
78  $this->attachments[] = $attachment;
79  }
80 
87  function addAttachmentFromBinaryData($filename, $mimetype, $contents) {
88  $attachment = new com_maileon_api_transactions_Attachment($filename, $mimetype, base64_encode($contents));
89  $this->attachments[] = $attachment;
90  }
91 
98  function addAttachmentFromBase64Data($filename, $mimetype, $contents) {
99  $attachment = new com_maileon_api_transactions_Attachment($filename, $mimetype, $contents);
100  $this->attachments[] = $attachment;
101  }
102 
107  function toString() {
108  return "Transaction [type=" . $this->type . ", contact=(" . (empty( $this->contact))?"":$this->contact->toString() . "), import=(" . (empty( $this->import))?"":$this->import->toString() . "), content=(" . json_encode($this->content) . ")]";
109  }
110 
111  function toArray() {
112  $array = parent::toArray();
113 
114  if(isset($array['import'])) {
115  unset($array['contact']);
116  $array['import'] = array( "contact" => $array['import'] );
117  }
118 
119  return $array;
120  }
121 }
addAttachmentFromBase64Data($filename, $mimetype, $contents)
Definition: Transaction.php:98
addAttachmentFromFile($filename, $mimetype, $attachmentFileName=null)
Definition: Transaction.php:64
addAttachmentFromBinaryData($filename, $mimetype, $contents)
Definition: Transaction.php:87