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

class Globalcompanysettings_model extends CI_Model
{

    public function add($formsdirectory)
    {

        if (!isset($formsdirectory['id'])) {
            $formsdirectory['id'] = $this->_insert($formsdirectory);

        } else {
            $this->_update($formsdirectory);
        }

        return (int)$formsdirectory['id'];
    }

    protected function _insert($formsdirectory)
    {

        if (!$this->db->insert('companyglobalsetting', $formsdirectory)) {
            throw new Exception('Could not insert forms directory record.');
        }
        return (int)$this->db->insert_id();
    }

    protected function _update($formsdirectory)
    {
        $this->db->where('id', $formsdirectory['id']);
        if (!$this->db->update('companyglobalsetting', $formsdirectory)) {
            throw new Exception('Could not update forms directory record');
        }
    }

    public function delete($forms_id)
    {
        if (!is_numeric($forms_id)) {
            throw new Exception('Invalid argument type $forms_id (value:"' . $forms_id . '"');
        }

        $num_rows = $this->db->get_where('companyglobalsetting', ['id' => $forms_id])->num_rows();
        if ($num_rows == 0) {
            return FALSE; // Record does not exist
        }

        return $this->db->delete('companyglobalsetting', ['id' => $forms_id]);
    }


    public function get_batch($where_clause = NULL)
    {
        if ($where_clause != NULL) {
            $this->db->where($where_clause);
        }

        return $this->db->get('companyglobalsetting')->result_array();
    }

    public function get_globalsetting($global_id)
    {
        if (!is_numeric($global_id)) {
            throw new Exception('$service_id argument is not an numeric (value: "' . $global_id . '")');
        }
        return $this->db->get_where('companyglobalsetting', ['id' => $global_id])->row_array();
    }


}