MIF_E31211958/app/Models/ModelSurat.php

82 lines
2.1 KiB
PHP

<?php
namespace App\Models;
use CodeIgniter\Model;
use Codeigniter\HTTP\RequestInterface;
class ModelSurat extends Model
{
protected $db;
protected $request;
public function __construct()
{
$this->db = \Config\Database::connect();
$this->request = \Config\Services::request();
}
protected $table = 'surat';
protected $primaryKey = 'id_surat';
protected $returnType = 'object';
protected $allowedFields = ['id_surat', 'nip', 'jenis_surat', 'jabatan', 'tanggal', 'keterangan_surat', 'lampiran'];
public function getSurat($nip)
{
return $this->db->table('surat')
->join('guru', 'surat.nip = guru.nip')
->where([
'surat.nip' => $nip,
])
->get()
->getResult();
}
public function getSuratAll()
{
return $this->db->table('surat')
->join('guru', 'surat.nip = guru.nip')->get()->getResult();
}
public function insert_surat($data)
{
return $this->db->table($this->table)->insert($data);
}
public function getById($id)
{
return $this->where(['id_surat' => $id])->get();
}
public function getRekapTugas($nip)
{
$builder = $this->db->table($this->table);
$currentDate = date('Y-m-d');
$threeMonthsAgo = date('Y-m-d', strtotime('-3 months'));
return $this->db->table('surat')
->join('guru', 'surat.nip = guru.nip')
->where('jenis_surat', 1)
->where('surat.nip', $nip)
->where('tanggal >=', $threeMonthsAgo)
->where('tanggal <=', $currentDate)
->get()
->getResult();
}
public function getRekapPanitia($nip)
{
$currentDate = date('Y-m-d');
$threeMonthsAgo = date('Y-m-d', strtotime('-3 months'));
return $this->db->table('surat')
->join('guru', 'surat.nip = guru.nip')
->where('jenis_surat', 2)
->where('surat.nip', $nip)
->where('tanggal >=', $threeMonthsAgo)
->where('tanggal <=', $currentDate)
->get()
->getResult();
}
}