<?php

namespace App\Models;

use CodeIgniter\Model;

class Pengumuman_model extends Model
{

    var $table = 'pengumuman';

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

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

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

    public function pengumuman_add($data)
    {

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

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

    public function pengumuman_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();
    }
}
