MOON
Server: Apache
System: Linux nserver.cafsindia.com 4.18.0-553.104.1.lve.el8.x86_64 #1 SMP Tue Feb 10 20:07:30 UTC 2026 x86_64
User: cafsindia (1002)
PHP: 8.2.30
Disabled: NONE
Upload Files
File: /home/cafsindia/lms_cafsinfotech_in/application/models/BranchModel.php
<?php defined('BASEPATH') OR exit('No direct script access allowed');
class BranchModel extends CI_Model {
    var $table = 'branch';
    // set column field database for datatable orderable
    var $column_order = array(null, 'branch_title', 'branch_description', null, null, 'branch_status', 'branch_added', null);
    // set column field database for datatable searchable
    var $column_search = array('branch_title', 'branch_description', 'branch_status', 'branch_added');
    // default order
    var $order = array('branch_id' => 'DESC');
    public function __construct() {
        parent::__construct();
        $this->load->database();
    }
    function insert($insert) {
        $this->db->insert('branch', $insert);
    }
    function allbranch($id = NULL) {

        $query = $this->db->select('branch_id,branch_name');
        if ($id) {
            $query->where('branch_id !=', $id);
        }
        //echo "model"; die;
        $result = $query->get('branch')->result_array();
        return $result;
    }
    private function _get_datatables_query() {
        $this->db->from($this->table);
        $i = 0;
        // loop column
        foreach ($this->column_search as $item) {
            // if datatable send POST for search
            if ($_POST['search']['value']) {
                // first loop
                if ($i === 0) {
                    // open bracket. query Where with OR clause better with bracket. because maybe can combine with other WHERE with AND.
                    $this->db->group_start();
                    $this->db->like($item, $_POST['search']['value']);
                } else {
                    $this->db->or_like($item, $_POST['search']['value']);
                }
                // last loop
                if (count($this->column_search) - 1 == $i) {
                    // close bracket
                    $this->db->group_end();
                }
            }
            $i++;
        }
        // here order processing
        if (isset($_POST['order'])) {
            $this->db->order_by($this->column_order[$_POST['order']['0']['column']], $_POST['order']['0']['dir']);
        } else if (isset($this->order)) {
            $order = $this->order;
            $this->db->order_by(key($order), $order[key($order) ]);
        }
    }
    function get_branch() {
        $this->_get_datatables_query();
        if ($_POST['length'] != - 1) $this->db->limit($_POST['length'], $_POST['start']);
        $query = $this->db->get();
        return $query->result();
        // echo $this->db->last_query(); die;
    }
    function count_filtered() {
        $this->_get_datatables_query();
        $query = $this->db->get();
        return $query->num_rows();
    }
    public function count_all() {
        $this->db->from($this->table);
        return $this->db->count_all_results();
    }
    function updatestatus($id, $status) {
        $this->db->set('branch_status', $status)->where('branch_id', $id)->update('branch');
    }
    function getfetch($id){
        return $this->db->where('branch_id', $id)->get('branch')->row_array();
    }
    function getImage($id) {
        return $this->db->where('branch_id', $id)->get('branch')->row('branch_image');
    }
    function update($data, $id) {
        $this->db->where('branch_id', $id)->update('branch', $data);
    }
    function deleteimage($id) {
        return $this->db->where('branch_id', $id)->get('branch')->row('branch_image');
    }
    function delete($id) {
        $this->db->where('branch_id', $id)->delete('branch');
    }
    function customfield_id($id) {
        $result = $this->db->select('custom_field_id')->where('branch_id', $id)->get('branch_custom_field')->result_array();
        return $result;
    }
    function getLabel($customField_id) {
        $result = $this->db->select('id,custom_label')->where_not_in('branch_id', $customField_id)->get('custom_field')->result_array();
        return $result;
    }
    function fetchbranch($id) {
        $result = $this->db->select('branch_id,custom_field_id')->where('branch_id', $id)->get('branch_custom_field')->result_array();
        return $result;
    }
    function fetchbranch_name($id) {
        $result = $this->db->select('custom_label,id as custom_field_id')->where_in('id', $id)->get('custom_field')->result_array();
        return $result;
    }
    function delete_label($id) {
        $result = $this->db->where_in('branch_id', $id)->delete('branch_custom_field');
    }
    function branch_custom($data) {
        $this->db->insert('branch_custom_field', $data);
    }
    function branch_name_like_this($id, $title) {
        $this->db->like('branch_name', $title);
        if ($id) {
            $this->db->where('branch_id !=', $id);
            $this->db->where('branch_id <', $id);
        }
        return $this->db->count_all_results('branch');
    }
    function get_branch_custom_fields($branch_id)
    {
        $result = $this->db
        ->select("id, custom_label, CCF.branch_custom_order")
        ->join("branch_custom_field CCF", "CCF.custom_field_id = CF.id AND CCF.branch_id = $branch_id", "LEFT")
        ->order_by("CCF.branch_custom_order",  "DESC")
        ->get("custom_field CF")
        ->result_array();
        return $result;
    }
}