<?php

class Improvement_model extends Atapp_Model
{

    private $lang;

    public function __construct()
    {
        parent::__construct();
        $this->lang = get_contact_language();
    }

    function insert($arr)
    {
        $data = [
            'title' => $arr['title'],
            'lang' => $this->config->item('system_default_language'),
        ];
        $this->db->insert('_improvement', $data);
        return $this->db->insert_id();

    }

    function update($id, $arr)
    {
		$data = [
			'title' => $arr['title'],
		];
		$this->db->where('id', $id);
		$this->db->update('_improvement', $data);
    }

    function get($include_hidden = false)
    {
        $this->db->select('*');
        $this->db->order_by("displayorder", "asc");
        $this->db->from('_improvement');
        $result = $this->db->get()->result_array();
		return $result;
    }

    function get_id($id)
    {
        $this->db->where('id', $id);
        $result = $this->db->get('_improvement')->row_array();
        return $result;
    }

    function delete($id)
    {
        $this->db->delete('_improvement', ['id' => $id]);
    }

    function update_rank($id, $rank)
    {
        $data = array(
            'displayorder' => $rank
        );

        $this->db->where('id', $id);
        $this->db->update('_improvement', $data);
    }

}
