<?php

if (!defined('BASEPATH')) {
    exit('No direct script access allowed');
}

class template_tmodel extends RT_Model
{

    protected $data = [];

    public function fetch_by_code($code = '')
    {
        if (empty($this->data[$code])) {
            $this->data[$code] = $this->db->select('copy_to'
                                    . ', hidden_copy_to'
                                    . ', subject'
                                    . ', message'
                                    . ', mailtype'
                            )
                            ->where('code', $code)
                            ->get('emailmng')->row_array();
        }

        return $this->data[$code];
    }

    public function add($code = '', $subject = '', $message = '')
    {
        $data = array(
            'code'    => $code,
            'subject' => $subject,
            'message' => $message
        );

        return $this->db->insert('emailmng', $data);
    }

    public function delete_by_code($code)
    {
        return $this->db->delete('emailmng', array('code' => $code));
    }

}
