<?php

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

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

    protected $table = 'product_group';
    protected $pkey = 'id_product_group';

    /**
     * Fetch one record
     * @param integer $id
     * @return array
     */
    public function fetch($id = 0)
    {
        $res = $this->where()
                ->select('t.*')
                ->where('t.' . $this->pkey, (int) $id)
                ->get($this->table . ' t')
                ->row_array();

        return $res;
    }

    /**
     * Fetch all records
     * @return array
     */
    public function fetch_all()
    {
        $res = $this->where()
                ->select('t.*')
                ->get($this->table . ' t')
                ->result_array();

        return $res;
    }
    
    public function fetch_current()
    {
        $this->load->model('ciext/core_model');
        
        $res = $this->where()
                ->select('t.*')
                ->where('t.id_resource_type_page', $this->core_model->get_current_page_id())
                ->get($this->table . ' t')
                ->row_array();
        
        return $res;
    }

    protected function where()
    {
        return $this->db
                        ->join('resource_type_page p', 'p.id_resource_type_page=t.id_resource_type_page', 'left')
                        ->where('p.active', TRUE);
    }

}
