Files
oficial/app/src/Model/Persona.php
Juan Pablo Vial e36281d924 Reservation Fixes
2025-09-09 16:24:48 -03:00

68 lines
1.8 KiB
PHP

<?php
namespace Incoviba\Model;
use Incoviba\Common\Implement\Exception\EmptyResult;
use InvalidArgumentException;
use Incoviba\Common\Ideal;
use Incoviba\Model\Persona\Datos;
class Persona extends Ideal\Model
{
public int $rut;
public string $digito;
public string $nombres;
public string $apellidoPaterno;
public string $apellidoMaterno;
public function nombreCompleto(): string
{
return $this->nombres . ' ' . $this->apellidoPaterno . ' ' . $this->apellidoMaterno;
}
public function rutCompleto(): string
{
return number_format($this->rut, 0, ',', '.') . '-' . $this->digito;
}
protected ?Datos $datos;
public function datos(): ?Datos
{
if (!isset($this->datos)) {
try {
$this->datos = $this->runFactory('datos');
} catch (EmptyResult) {
$this->datos = null;
}
}
return $this->datos;
}
public function __get(string $name): mixed
{
if ($name === 'datos') {
return $this->datos();
}
if ($name === 'dv') {
return $this->digito;
}
if (property_exists($this, $name)) {
return $this->{$name};
}
throw new InvalidArgumentException("Property {$name} is not found in " . __CLASS__);
}
public function jsonSerialize(): mixed
{
return [
'rut' => $this->rut,
'digito' => $this->digito,
'nombres' => $this->nombres,
'apellidoPaterno' => $this->apellidoPaterno,
'apellidoMaterno' => $this->apellidoMaterno,
'nombreCompleto' => $this->nombreCompleto(),
'rutCompleto' => $this->rutCompleto(),
'datos' => $this->datos() ?? null,
];
}
}