vendor/mandrill/mandrill/src/Mandrill/Templates.php line 5

Open in your IDE?
  1. <?php
  2. class Mandrill_Templates {
  3. public function __construct(Mandrill $master) {
  4. $this->master = $master;
  5. }
  6. /**
  7. * Add a new template
  8. * @param string $name the name for the new template - must be unique
  9. * @param string $from_email a default sending address for emails sent using this template
  10. * @param string $from_name a default from name to be used
  11. * @param string $subject a default subject line to be used
  12. * @param string $code the HTML code for the template with mc:edit attributes for the editable elements
  13. * @param string $text a default text part to be used when sending with this template
  14. * @param boolean $publish set to false to add a draft template without publishing
  15. * @param array $labels an optional array of up to 10 labels to use for filtering templates
  16. * - labels[] string a single label
  17. * @return struct the information saved about the new template
  18. * - slug string the immutable unique code name of the template
  19. * - name string the name of the template
  20. * - labels array the list of labels applied to the template
  21. * - labels[] string a single label
  22. * - code string the full HTML code of the template, with mc:edit attributes marking the editable elements - draft version
  23. * - subject string the subject line of the template, if provided - draft version
  24. * - from_email string the default sender address for the template, if provided - draft version
  25. * - from_name string the default sender from name for the template, if provided - draft version
  26. * - text string the default text part of messages sent with the template, if provided - draft version
  27. * - publish_name string the same as the template name - kept as a separate field for backwards compatibility
  28. * - publish_code string the full HTML code of the template, with mc:edit attributes marking the editable elements that are available as published, if it has been published
  29. * - publish_subject string the subject line of the template, if provided
  30. * - publish_from_email string the default sender address for the template, if provided
  31. * - publish_from_name string the default sender from name for the template, if provided
  32. * - publish_text string the default text part of messages sent with the template, if provided
  33. * - published_at string the date and time the template was last published as a UTC string in YYYY-MM-DD HH:MM:SS format, or null if it has not been published
  34. * - created_at string the date and time the template was first created as a UTC string in YYYY-MM-DD HH:MM:SS format
  35. * - updated_at string the date and time the template was last modified as a UTC string in YYYY-MM-DD HH:MM:SS format
  36. */
  37. public function add($name, $from_email=null, $from_name=null, $subject=null, $code=null, $text=null, $publish=true, $labels=array()) {
  38. $_params = array("name" => $name, "from_email" => $from_email, "from_name" => $from_name, "subject" => $subject, "code" => $code, "text" => $text, "publish" => $publish, "labels" => $labels);
  39. return $this->master->call('templates/add', $_params);
  40. }
  41. /**
  42. * Get the information for an existing template
  43. * @param string $name the immutable name of an existing template
  44. * @return struct the requested template information
  45. * - slug string the immutable unique code name of the template
  46. * - name string the name of the template
  47. * - labels array the list of labels applied to the template
  48. * - labels[] string a single label
  49. * - code string the full HTML code of the template, with mc:edit attributes marking the editable elements - draft version
  50. * - subject string the subject line of the template, if provided - draft version
  51. * - from_email string the default sender address for the template, if provided - draft version
  52. * - from_name string the default sender from name for the template, if provided - draft version
  53. * - text string the default text part of messages sent with the template, if provided - draft version
  54. * - publish_name string the same as the template name - kept as a separate field for backwards compatibility
  55. * - publish_code string the full HTML code of the template, with mc:edit attributes marking the editable elements that are available as published, if it has been published
  56. * - publish_subject string the subject line of the template, if provided
  57. * - publish_from_email string the default sender address for the template, if provided
  58. * - publish_from_name string the default sender from name for the template, if provided
  59. * - publish_text string the default text part of messages sent with the template, if provided
  60. * - published_at string the date and time the template was last published as a UTC string in YYYY-MM-DD HH:MM:SS format, or null if it has not been published
  61. * - created_at string the date and time the template was first created as a UTC string in YYYY-MM-DD HH:MM:SS format
  62. * - updated_at string the date and time the template was last modified as a UTC string in YYYY-MM-DD HH:MM:SS format
  63. */
  64. public function info($name) {
  65. $_params = array("name" => $name);
  66. return $this->master->call('templates/info', $_params);
  67. }
  68. /**
  69. * Update the code for an existing template. If null is provided for any fields, the values will remain unchanged.
  70. * @param string $name the immutable name of an existing template
  71. * @param string $from_email the new default sending address
  72. * @param string $from_name the new default from name
  73. * @param string $subject the new default subject line
  74. * @param string $code the new code for the template
  75. * @param string $text the new default text part to be used
  76. * @param boolean $publish set to false to update the draft version of the template without publishing
  77. * @param array $labels an optional array of up to 10 labels to use for filtering templates
  78. * - labels[] string a single label
  79. * @return struct the template that was updated
  80. * - slug string the immutable unique code name of the template
  81. * - name string the name of the template
  82. * - labels array the list of labels applied to the template
  83. * - labels[] string a single label
  84. * - code string the full HTML code of the template, with mc:edit attributes marking the editable elements - draft version
  85. * - subject string the subject line of the template, if provided - draft version
  86. * - from_email string the default sender address for the template, if provided - draft version
  87. * - from_name string the default sender from name for the template, if provided - draft version
  88. * - text string the default text part of messages sent with the template, if provided - draft version
  89. * - publish_name string the same as the template name - kept as a separate field for backwards compatibility
  90. * - publish_code string the full HTML code of the template, with mc:edit attributes marking the editable elements that are available as published, if it has been published
  91. * - publish_subject string the subject line of the template, if provided
  92. * - publish_from_email string the default sender address for the template, if provided
  93. * - publish_from_name string the default sender from name for the template, if provided
  94. * - publish_text string the default text part of messages sent with the template, if provided
  95. * - published_at string the date and time the template was last published as a UTC string in YYYY-MM-DD HH:MM:SS format, or null if it has not been published
  96. * - created_at string the date and time the template was first created as a UTC string in YYYY-MM-DD HH:MM:SS format
  97. * - updated_at string the date and time the template was last modified as a UTC string in YYYY-MM-DD HH:MM:SS format
  98. */
  99. public function update($name, $from_email=null, $from_name=null, $subject=null, $code=null, $text=null, $publish=true, $labels=null) {
  100. $_params = array("name" => $name, "from_email" => $from_email, "from_name" => $from_name, "subject" => $subject, "code" => $code, "text" => $text, "publish" => $publish, "labels" => $labels);
  101. return $this->master->call('templates/update', $_params);
  102. }
  103. /**
  104. * Publish the content for the template. Any new messages sent using this template will start using the content that was previously in draft.
  105. * @param string $name the immutable name of an existing template
  106. * @return struct the template that was published
  107. * - slug string the immutable unique code name of the template
  108. * - name string the name of the template
  109. * - labels array the list of labels applied to the template
  110. * - labels[] string a single label
  111. * - code string the full HTML code of the template, with mc:edit attributes marking the editable elements - draft version
  112. * - subject string the subject line of the template, if provided - draft version
  113. * - from_email string the default sender address for the template, if provided - draft version
  114. * - from_name string the default sender from name for the template, if provided - draft version
  115. * - text string the default text part of messages sent with the template, if provided - draft version
  116. * - publish_name string the same as the template name - kept as a separate field for backwards compatibility
  117. * - publish_code string the full HTML code of the template, with mc:edit attributes marking the editable elements that are available as published, if it has been published
  118. * - publish_subject string the subject line of the template, if provided
  119. * - publish_from_email string the default sender address for the template, if provided
  120. * - publish_from_name string the default sender from name for the template, if provided
  121. * - publish_text string the default text part of messages sent with the template, if provided
  122. * - published_at string the date and time the template was last published as a UTC string in YYYY-MM-DD HH:MM:SS format, or null if it has not been published
  123. * - created_at string the date and time the template was first created as a UTC string in YYYY-MM-DD HH:MM:SS format
  124. * - updated_at string the date and time the template was last modified as a UTC string in YYYY-MM-DD HH:MM:SS format
  125. */
  126. public function publish($name) {
  127. $_params = array("name" => $name);
  128. return $this->master->call('templates/publish', $_params);
  129. }
  130. /**
  131. * Delete a template
  132. * @param string $name the immutable name of an existing template
  133. * @return struct the template that was deleted
  134. * - slug string the immutable unique code name of the template
  135. * - name string the name of the template
  136. * - labels array the list of labels applied to the template
  137. * - labels[] string a single label
  138. * - code string the full HTML code of the template, with mc:edit attributes marking the editable elements - draft version
  139. * - subject string the subject line of the template, if provided - draft version
  140. * - from_email string the default sender address for the template, if provided - draft version
  141. * - from_name string the default sender from name for the template, if provided - draft version
  142. * - text string the default text part of messages sent with the template, if provided - draft version
  143. * - publish_name string the same as the template name - kept as a separate field for backwards compatibility
  144. * - publish_code string the full HTML code of the template, with mc:edit attributes marking the editable elements that are available as published, if it has been published
  145. * - publish_subject string the subject line of the template, if provided
  146. * - publish_from_email string the default sender address for the template, if provided
  147. * - publish_from_name string the default sender from name for the template, if provided
  148. * - publish_text string the default text part of messages sent with the template, if provided
  149. * - published_at string the date and time the template was last published as a UTC string in YYYY-MM-DD HH:MM:SS format, or null if it has not been published
  150. * - created_at string the date and time the template was first created as a UTC string in YYYY-MM-DD HH:MM:SS format
  151. * - updated_at string the date and time the template was last modified as a UTC string in YYYY-MM-DD HH:MM:SS format
  152. */
  153. public function delete($name) {
  154. $_params = array("name" => $name);
  155. return $this->master->call('templates/delete', $_params);
  156. }
  157. /**
  158. * Return a list of all the templates available to this user
  159. * @param string $label an optional label to filter the templates
  160. * @return array an array of structs with information about each template
  161. * - return[] struct the information on each template in the account
  162. * - slug string the immutable unique code name of the template
  163. * - name string the name of the template
  164. * - labels array the list of labels applied to the template
  165. * - labels[] string a single label
  166. * - code string the full HTML code of the template, with mc:edit attributes marking the editable elements - draft version
  167. * - subject string the subject line of the template, if provided - draft version
  168. * - from_email string the default sender address for the template, if provided - draft version
  169. * - from_name string the default sender from name for the template, if provided - draft version
  170. * - text string the default text part of messages sent with the template, if provided - draft version
  171. * - publish_name string the same as the template name - kept as a separate field for backwards compatibility
  172. * - publish_code string the full HTML code of the template, with mc:edit attributes marking the editable elements that are available as published, if it has been published
  173. * - publish_subject string the subject line of the template, if provided
  174. * - publish_from_email string the default sender address for the template, if provided
  175. * - publish_from_name string the default sender from name for the template, if provided
  176. * - publish_text string the default text part of messages sent with the template, if provided
  177. * - published_at string the date and time the template was last published as a UTC string in YYYY-MM-DD HH:MM:SS format, or null if it has not been published
  178. * - created_at string the date and time the template was first created as a UTC string in YYYY-MM-DD HH:MM:SS format
  179. * - updated_at string the date and time the template was last modified as a UTC string in YYYY-MM-DD HH:MM:SS format
  180. */
  181. public function getList($label=null) {
  182. $_params = array("label" => $label);
  183. return $this->master->call('templates/list', $_params);
  184. }
  185. /**
  186. * Return the recent history (hourly stats for the last 30 days) for a template
  187. * @param string $name the name of an existing template
  188. * @return array the array of history information
  189. * - return[] struct the stats for a single hour
  190. * - time string the hour as a UTC date string in YYYY-MM-DD HH:MM:SS format
  191. * - sent integer the number of emails that were sent during the hour
  192. * - hard_bounces integer the number of emails that hard bounced during the hour
  193. * - soft_bounces integer the number of emails that soft bounced during the hour
  194. * - rejects integer the number of emails that were rejected during the hour
  195. * - complaints integer the number of spam complaints received during the hour
  196. * - opens integer the number of emails opened during the hour
  197. * - unique_opens integer the number of unique opens generated by messages sent during the hour
  198. * - clicks integer the number of tracked URLs clicked during the hour
  199. * - unique_clicks integer the number of unique clicks generated by messages sent during the hour
  200. */
  201. public function timeSeries($name) {
  202. $_params = array("name" => $name);
  203. return $this->master->call('templates/time-series', $_params);
  204. }
  205. /**
  206. * Inject content and optionally merge fields into a template, returning the HTML that results
  207. * @param string $template_name the immutable name of a template that exists in the user's account
  208. * @param array $template_content an array of template content to render. Each item in the array should be a struct with two keys - name: the name of the content block to set the content for, and content: the actual content to put into the block
  209. * - template_content[] struct the injection of a single piece of content into a single editable region
  210. * - name string the name of the mc:edit editable region to inject into
  211. * - content string the content to inject
  212. * @param array $merge_vars optional merge variables to use for injecting merge field content. If this is not provided, no merge fields will be replaced.
  213. * - merge_vars[] struct a single merge variable
  214. * - name string the merge variable's name. Merge variable names are case-insensitive and may not start with _
  215. * - content string the merge variable's content
  216. * @return struct the result of rendering the given template with the content and merge field values injected
  217. * - html string the rendered HTML as a string
  218. */
  219. public function render($template_name, $template_content, $merge_vars=null) {
  220. $_params = array("template_name" => $template_name, "template_content" => $template_content, "merge_vars" => $merge_vars);
  221. return $this->master->call('templates/render', $_params);
  222. }
  223. }