<?php

namespace App\Models;

use CodeIgniter\Model;

class User_model extends Model
{

    var $table = 'user';

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

    public function get_all_users()
    {
        //       $query = $this->db->table('users');
        $query = $this->db->query('select * from user');
        //      print_r($query->getResult());
        // $query = $this->db->get();
        return $query->getResult();
    }

    public function get_by_id($id)
    {
        $query = $this->db->table('user')
            ->where('id', $id)
            ->get();
        return $query->getRow();
    }

    public function user_add($data)
    {

        $query = $this->db->table($this->table)->insert($data);

        return $this->db->insertID();
    }

    public function user_update($where, $data)
    {
        $this->db->table($this->table)->update($data, $where);
        return $this->db->affectedRows();
    }

    public function delete_by_id($id)
    {
        $this->db->table($this->table)->delete(array('id' => $id));
    }

    public function cek_by_nip($nip)
    {
        return $this->db->table($this->table)->where(['nip' => $nip, 'role' => 'guru'])->get()->getNumRows();
    }
}
