"t1.nombre", 1 => "t1.precio", 2 => "t1.precio_unidad" ]; protected $allowedFields = ["presupuesto_id", "tarifa_acabado_id", "nombre", "precio", "precio_unidad"]; protected $returnType = "App\Entities\Presupuestos\PresupuestoAcabadosEntity"; protected $useTimestamps = true; protected $useSoftDeletes = false; protected $createdField = "created_at"; protected $updatedField = "updated_at"; public static $labelField = "nombre"; protected $validationRules = [ "precio" => [ "label" => "ClienteContactos.precio", "rules" => "trim|max_length[100]", ], ]; protected $validationMessages = [ "precio" => [ "max_length" => "ClienteContactos.validation.apellidos.max_length", ], ]; public function findAllWithClientes(string $selcols = "*", int $limit = null, int $offset = 0) { $sql = "SELECT t1." . $selcols . ", t2.nombre AS cliente_id FROM " . $this->table . " t1 LEFT JOIN clientes t2 ON t1.cliente_id = t2.id"; if (!is_null($limit) && intval($limit) > 0) { $sql .= " LIMIT " . $limit; } if (!is_null($offset) && intval($offset) > 0) { $sql .= " OFFSET " . $offset; } $query = $this->db->query($sql); $result = $query->getResultObject(); return $result; } /** * Get resource data. * * @param string $search * * @return \CodeIgniter\Database\BaseBuilder */ public function getResource(string $search = "", $presupuesto_id = -1) { $builder = $this->db ->table($this->table . " t1") ->select( "t1.id AS id, t1.cargo AS cargo, t1.nombre AS nombre, t1.apellidos AS apellidos, t1.telefono AS telefono, t1.email AS email, t1.cliente_id AS cliente_id" ); $builder->where('t1.presupuesto_id', $presupuesto_id); $builder->join("presupuestos t2", "t1.presupuesto_id = t2.id", "left"); return empty($search) ? $builder : $builder ->groupStart() ->like("t1.nombre", $search) ->orLike("t1.nombre", $search) ->orLike("t1.apellidos", $search) ->orLike("t1.telefono", $search) ->orLike("t1.email", $search) ->groupEnd(); } }