MIF_E31211958/app/Models/ModelKriteria.php

59 lines
1.4 KiB
PHP

<?php
namespace App\Models;
use CodeIgniter\Model;
use Codeigniter\HTTP\RequestInterface;
class ModelKriteria extends Model
{
protected $db;
protected $request;
public function __construct()
{
$this->db = \Config\Database::connect();
$this->request = \Config\Services::request();
}
protected $table = 'kriteria';
protected $primaryKey = 'id_kriteria';
protected $returnType = 'object';
protected $allowedFields = ['id_kriteria', 'kode_kriteria', 'nama_kriteria', 'tipe', 'bobot'];
public function getKriteria()
{
return $this->get()->getResult();
}
public function insert_kriteria($data)
{
return $this->db->table($this->table)->insert($data);
}
public function getById($id)
{
return $this->where(['id_kriteria' => $id])->get();
}
public function getTipeByKode($kode)
{
$kriteria = $this->where('kode_kriteria', $kode)->get()->getRow();
if ($kriteria) {
return $kriteria->tipe;
} else {
return null; // Atau Anda bisa menangani kesalahan sesuai kebutuhan aplikasi Anda
}
}
public function getBobotByKode($kode)
{
$kriteria = $this->where('kode_kriteria', $kode)->get()->getRow();
if ($kriteria) {
return $kriteria->bobot;
} else {
return null; // Atau Anda bisa menangani kesalahan sesuai kebutuhan aplikasi Anda
}
}
}