<?php

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

/**
 * Description of Rtform_tmodel
 *
 * @author CIEXT skeleton
 */
class Rtform_tmodel extends \Ciext\Model\AbstractTableModel
{

    protected $table = 'rtform';
    protected $pkey = 'id_rtform';
    protected $cache = [];

    public function fetch_by_code($code)
    {
        if (empty($this->cache[$code])) {
            $this->cache[$code] = $this->db
                ->select($this->select, $this->select_escape)
                ->where('t.code', $code)
                ->limit(1)
                ->get($this->table . ' t')
                ->row_array();
        }

        // Notify all observers
        $this->notify(__FUNCTION__, ['res' => $this->cache[$code], 'code' => $code]);

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