<?php

namespace App\Models;

use CodeIgniter\Model;

class Tahunpelajaran_model extends Model
{
    var $table = 'tahunpelajaran';
    public function __construct()
    {
        parent::__construct();
    }

    public function get_all_tahunpelajaran()
    {
        $query = $this->db->table($this->table)
            ->get();
        return $query->getResult();
    }

    public function get_wali()
    {
        $query = $this->db->table('users')
            ->where('role', 'guru')
            ->get();
        return $query->getResult();
    }

    public function get_by_id($id)
    {
        $query =  $this->db->table($this->table)
            ->where('id', $id)
            ->get();
        return $query->getRow();
    }
    public function tahunpelajaran_add($data)
    {
        $query = $this->db->table($this->table)->insert($data);
        return $this->db->insertID();
    }
    public function update_status($where)
    {

        $cekdata = $this->db->table($this->table)
            ->update(['status' => 'tidak'], $where);
        return $cekdata;
    }
    public function update_setting($data)
    {
        $update = $this->db->table('settings')
            ->update(['tahunpelajaran' => $data], ['id' => 1]);
        return $update;
    }

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