Files
safekat/ci4/app/Models/Configuracion/FormaPagoModel.php
2024-07-17 14:51:47 +02:00

81 lines
2.1 KiB
PHP
Executable File

<?php
namespace App\Models\Configuracion;
class FormaPagoModel extends \App\Models\BaseModel
{
protected $table = "formas_pago";
/**
* Whether primary key uses auto increment.
*
* @var bool
*/
protected $useAutoIncrement = true;
const SORTABLE = [
1 => "t1.id",
2 => "t1.nombre",
3 => "t1.created_at",
4 => "t1.updated_at",
];
protected $allowedFields = ["nombre"];
protected $returnType = "App\Entities\Configuracion\FormaPagoEntity";
public static $labelField = "nombre";
protected $validationRules = [
"nombre" => [
"label" => "FormasPagoes.nombre",
"rules" => "trim|required|max_length[255]",
],
];
protected $validationMessages = [
"nombre" => [
"max_length" => "FormasPagoes.validation.nombre.max_length",
"required" => "FormasPagoes.validation.nombre.required",
],
];
public function getMenuItems(){
$items = $this->findAll();
$menuItems = [];
foreach ($items as $item) {
$menuItems[] = [
"value" => $item->id,
"label" => $item->nombre,
];
}
return $menuItems;
}
/**
* Get resource data.
*
* @param string $search
*
* @return \CodeIgniter\Database\BaseBuilder
*/
public function getResource(string $search = "")
{
$builder = $this->db
->table($this->table . " t1")
->select("t1.id AS id, t1.nombre AS nombre, t1.created_at AS created_at, t1.updated_at AS updated_at");
return empty($search)
? $builder
: $builder
->groupStart()
->like("t1.id", $search)
->orLike("t1.nombre", $search)
->orLike("t1.created_at", $search)
->orLike("t1.updated_at", $search)
->orLike("t1.id", $search)
->orLike("t1.nombre", $search)
->orLike("t1.created_at", $search)
->orLike("t1.updated_at", $search)
->groupEnd();
}
}