<?php defined('BASEPATH') or exit('No direct script access allowed');

class config_model extends CI_Model
{

    public $table = 'cm_config';

    public function __construct()
    {
        parent::__construct();
        $this->load->database();
    }

    public function findById($configId)
    {
        return $this->db->where('Id', $configId)->get($this->table);
    }

    public function findByCategoryId($categoryId)
    {
        return $this->db->from($this->table . ' cnf')->where_in('CategoryId', $categoryId);
    }

    public function findByTypeAndName($configType, $name)
    {
        return $this->db->from($this->table . ' cnf')->where_in('Type', $configType)->where_in('Name', $name);
    }

    public function findByTypeAndPostId($configType, $postId)
    {
        return $this->db->from($this->table . ' cnf')->where_in('Type', $configType)->where_in('PostId', $postId);
    }

    public function findByTypeAndNameAndPage($configType, $name, $page)
    {
        return $this->db->from($this->table . ' cnf')->where_in('Type', $configType)
            ->where_in('Name', $name)->where_in('Page', $page)->order_by('OrderNum');
    }

    public function findByTypeAndPage($configType, $page)
    {
        return $this->db->from($this->table . ' cnf')->where_in('Type', $configType)
            ->where_in('Page', $page)->order_by('OrderNum');
    }

    public function findByTypeAndNameAndPageAndOrderNum($configType, $name, $page, $order)
    {
        return $this->db->from($this->table . ' cnf')->where_in('Type', $configType)->where_in('Name', $name)
            ->where_in('Page', $page)->where_in('OrderNum', $order);
    }

}
