<?php
class Merchant_Optional_Info_model extends CI_Model
{
    public function __construct()
    {
        parent::__construct();
    }

    function saveOptionalInfo($data)
    {
        if($this->optionalInfoExists($data['merchant_row_id']))
        {
            $this->db->where('merchant_row_id', $data['merchant_row_id']);
            $this->db->update('tbl_merchant_optional_setup', $data);
        }
        else
        {
            $this->db->insert('tbl_merchant_optional_setup', $data);
        }
    }

    function optionalInfoExists($merchantRowId)
    {
        if($merchantRowId)
        {
            $sql = 'SELECT merchant_row_id
                    FROM tbl_merchant_optional_setup
                    WHERE merchant_row_id = ' . $this->db->escape($merchantRowId);
            $q = $this->db->query($sql);
            $row = $q->row();

            if($row && $row->merchant_row_id)
            {
                return true;
            }
        }

        return false;
    }

    function getOptionalInfo($merchantRowId)
    {
        settype($merchantRowId, 'integer');

        if($merchantRowId)
        {
            $this->db->where('merchant_row_id', $merchantRowId);
            $q = $this->db->get('tbl_merchant_optional_setup');
            return $q->row();
        }

        return false;
    }
}
?>
