      1: <?php
      2:
      3: class Mailchimp_Templates {
      4:     public function __construct(Mailchimp $master) {
      5:         $this->master = $master;
      6:     }
      7:
      8:     /**
      9:      * Create a new user template, <strong>NOT</strong> campaign content. These templates can then be applied while creating campaigns.
     10:      * @param string $name
     11:      * @param string $html
     12:      * @param int $folder_id
     13:      * @return associative_array with a single element:
     14:      *     - template_id int the new template id, otherwise an error is thrown.
     15:      */
     16:     public function add($name, $html, $folder_id=null) {
     17:         $_params = array("name" => $name, "html" => $html, "folder_id" => $folder_id);
     18:         return $this->master->call('templates/add', $_params);
     19:     }
     20:
     21:     /**
     22:      * Delete (deactivate) a user template
     23:      * @param int $template_id
     24:      * @return associative_array with a single entry:
     25:      *     - complete bool whether the call worked. reallistically this will always be true as errors will be thrown otherwise.
     26:      */
     27:     public function del($template_id) {
     28:         $_params = array("template_id" => $template_id);
     29:         return $this->master->call('templates/del', $_params);
     30:     }
     31:
     32:     /**
     33:      * Pull details for a specific template to help support editing
     34:      * @param int $template_id
     35:      * @param string $type
     36:      * @return associative_array info to be used when editing
     37:      *     - default_content associative_array the default content broken down into the named editable sections for the template - dependant upon template, so not documented
     38:      *     - sections associative_array the valid editable section names - dependant upon template, so not documented
     39:      *     - source string the full source of the template as if you exported it via our template editor
     40:      *     - preview string similar to the source, but the rendered version of the source from our popup preview
     41:      */
     42:     public function info($template_id, $type='user') {
     43:         $_params = array("template_id" => $template_id, "type" => $type);
     44:         return $this->master->call('templates/info', $_params);
     45:     }
     46:
     47:     /**
     48:      * Retrieve various templates available in the system, allowing some thing similar to our template gallery to be created.
     49:      * @param associative_array $types
     50:      *     - user boolean Custom templates for this user account. Defaults to true.
     51:      *     - gallery boolean Templates from our Gallery. Note that some templates that require extra configuration are withheld. (eg, the Etsy template). Defaults to false.
     52:      *     - base boolean Our "start from scratch" extremely basic templates. Defaults to false.
     53:      * @param associative_array $filters
     54:      *     - category string optional for Gallery templates only, limit to a specific template category
     55:      *     - folder_id string user templates, limit to this folder_id
     56:      *     - include_inactive boolean user templates are not deleted, only set inactive. defaults to false.
     57:      *     - inactive_only boolean only include inactive user templates. defaults to false.
     58:      * @return associative_array for each type
     59:      *     - user array matching user templates, if requested.
     60:      *         - id int Id of the template
     61:      *         - name string Name of the template
     62:      *         - layout string General description of the layout of the template
     63:      *         - category string The category for the template, if there is one.
     64:      *         - preview_image string If we've generated it, the url of the preview image for the template. We do out best to keep these up to date, but Preview image urls are not guaranteed to be available
     65:      *         - date_created string The date/time the template was created
     66:      *         - active boolean whether or not the template is active and available for use.
     67:      *         - edit_source boolean Whether or not you are able to edit the source of a template.
     68:      *         - folder_id boolean if it's in one, the folder id
     69:      *     - gallery array matching gallery templates, if requested.
     70:      *         - id int Id of the template
     71:      *         - name string Name of the template
     72:      *         - layout string General description of the layout of the template
     73:      *         - category string The category for the template, if there is one.
     74:      *         - preview_image string If we've generated it, the url of the preview image for the template. We do out best to keep these up to date, but Preview image urls are not guaranteed to be available
     75:      *         - date_created string The date/time the template was created
     76:      *         - active boolean whether or not the template is active and available for use.
     77:      *         - edit_source boolean Whether or not you are able to edit the source of a template.
     78:      *     - base array matching base templates, if requested.
     79:      *         - id int Id of the template
     80:      *         - name string Name of the template
     81:      *         - layout string General description of the layout of the template
     82:      *         - category string The category for the template, if there is one.
     83:      *         - preview_image string If we've generated it, the url of the preview image for the template. We do out best to keep these up to date, but Preview image urls are not guaranteed to be available
     84:      *         - active boolean whether or not the template is active and available for use.
     85:      *         - date_created string The date/time the template was created
     86:      *         - edit_source boolean Whether or not you are able to edit the source of a template.
     87:      */
     88:     public function getList($types=array(), $filters=array()) {
     89:         $_params = array("types" => $types, "filters" => $filters);
     90:         return $this->master->call('templates/list', $_params);
     91:     }
     92:
     93:     /**
     94:      * Undelete (reactivate) a user template
     95:      * @param int $template_id
     96:      * @return associative_array with a single entry:
     97:      *     - complete bool whether the call worked. reallistically this will always be true as errors will be thrown otherwise.
     98:      */
     99:     public function undel($template_id) {
    100:         $_params = array("template_id" => $template_id);
    101:         return $this->master->call('templates/undel', $_params);
    102:     }
    103:
    104:     /**
    105:      * Replace the content of a user template, <strong>NOT</strong> campaign content.
    106:      * @param int $template_id
    107:      * @param associative_array $values
    108:      *     - name string the name for the template - names must be unique and a max of 50 bytes
    109:      *     - html string a string specifying the entire template to be created. This is <strong>NOT</strong> campaign content. They are intended to utilize our <a href="http://www.mailchimp.com/resources/email-template-language/" target="_blank">template language</a>.
    110:      *     - folder_id int the folder to put this template in - 0 or a blank values will remove it from a folder.
    111:      * @return associative_array with a single entry:
    112:      *     - complete bool whether the call worked. reallistically this will always be true as errors will be thrown otherwise.
    113:      */
    114:     public function update($template_id, $values) {
    115:         $_params = array("template_id" => $template_id, "values" => $values);
    116:         return $this->master->call('templates/update', $_params);
    117:     }
    118:
    119: }
    120:
    121:
    122: