56 lines
1.3 KiB
PHP
56 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use CodeIgniter\Model;
|
|
|
|
class DropdownModel extends Model
|
|
{
|
|
protected $table = 'm_dropdown';
|
|
// protected $primaryKey = 'dropdown_key';
|
|
|
|
protected $allowedFields = [
|
|
'dropdown',
|
|
'dropdown_key',
|
|
'dropdown_value',
|
|
'created_on',
|
|
'updated_on',
|
|
'is_active'
|
|
];
|
|
|
|
protected $useTimestamps = false; // No automatic timestamp handling by CI4
|
|
|
|
protected $createdField = 'created_on';
|
|
protected $updatedField = 'updated_on';
|
|
|
|
// Fetch dropdown values by group name
|
|
public function getDropdownValuesByGroup($group)
|
|
{
|
|
return $this->where('dropdown', $group)->where('is_active', 1)->findAll();
|
|
}
|
|
|
|
// Fetch a specific dropdown entry
|
|
public function getDropdownByKey($key)
|
|
{
|
|
return $this->where('dropdown_key', $key)->first();
|
|
}
|
|
|
|
// Insert a new dropdown value
|
|
public function insertDropdown($data)
|
|
{
|
|
return $this->insert($data);
|
|
}
|
|
|
|
// Update a dropdown value
|
|
public function updateDropdown($key, $data)
|
|
{
|
|
return $this->where('dropdown_key', $key)->set($data)->update();
|
|
}
|
|
|
|
// Soft delete (deactivate) a dropdown entry
|
|
public function deactivateDropdown($key)
|
|
{
|
|
return $this->where('dropdown_key', $key)->set(['is_active' => 0])->update();
|
|
}
|
|
}
|