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

class Item_groups_model extends App_Model
{
    private $table = 'items_groups';

    public function __construct()
    {
        parent::__construct();
    }

    public function get($id = false)
    {
        if (is_numeric($id)) {
            $this->db->where('id', $id);
            return $this->db->get(db_prefix() . $this->table)->row();
        }
        return $this->db->get(db_prefix() . $this->table)->result_array();
    }

    public function add($data)
    {
        unset($data['groupid']);
        $this->db->insert(db_prefix() . $this->table, $data);
        $insert_id = $this->db->insert_id();
        if ($insert_id) {
            log_activity('New Item Group Added [ID: ' . $insert_id . ']');
            return $insert_id;
        }
        return false;
    }

    public function edit($id, $data)
    {
        unset($data['groupid']);
        $this->db->where('id', $id);
        $this->db->update(db_prefix() . $this->table, $data);
        if ($this->db->affected_rows() > 0) {
            log_activity('Item Group Updated [ID: ' . $id . ']');
            return true;
        }
        return false;
    }

    public function delete($id)
    {
        $this->db->where('id', $id);
        $this->db->delete(db_prefix() . $this->table);
        if ($this->db->affected_rows() > 0) {
            log_activity('Item Group Deleted [ID: ' . $id . ']');
            return true;
        }
        return false;
    }
}