<?php

namespace MGModule\DNSManager2\models\whmcs\emailtemplate;
use MGModule\DNSManager2 as main;


/**
 * email model
 * @Table(name=tblemailtemplates,preventUpdate,prefixed=false)
 * @author Nieznany
 */
class emailtemplate extends main\mgLibs\models\orm {    
    /**
     * @Column()
     * @var int 
     */
    public $id;
    
    /**
     * @Column()
     * @var string 
     */
    public $type;
    
    /**
     * @Column()
     * @var string 
     */
    public $name;
    
    /**
     * 
     * @Column()
     * @var string 
     */
    public $subject;
    
    /**
     * 
     * @Column()
     * @var string 
     */
    public $message;
    
    /**
     * 
     * @Column()
     * @var string 
     */
    public $attachments;
    
    /**
     * @Column()
     * @var string 
     */
    public $fromname;
    
    /**
     * @Column()
     * @var string 
     */
    public $fromemail;
    
    /**
     * @Column()
     * @var int 
     */
    public $disabled;
    
    /**
     * @Column()
     * @var int 
     */
    public $custom;
    
    /**
     * @Column()
     * @var string 
     */
    public $language;
    
    /**
     * @Column()
     * @var string 
     */
    public $copyto;
    
    /**
     * @Column()
     * @var int 
     */
    public $plaintext;
    
    /**
     * @Column()
     * @var string 
     */
//    public $created_at; WHMCS6
    
    /**
     * @Column()
     * @var string 
     */
//    public $updated_at; WHMCS6
    
    public function save($data = array()) {
        $data['message'] = nl2br($this->message);
        parent::save($data);
    }
    
    public function byTypeAndName($type, $name) {
        $rep = new repository();
        $rep->setFilter('type', $type);
        $rep->setFilter('name', $name);
        $arr = $rep->get();
        
        return array_pop($arr);
    }

}
