46 lines
1.4 KiB
PHP
46 lines
1.4 KiB
PHP
![]() |
<?php
|
||
|
namespace Incoviba\Repository\Venta;
|
||
|
|
||
|
use Incoviba\Common\Ideal;
|
||
|
use Incoviba\Common\Define;
|
||
|
use Incoviba\Model;
|
||
|
|
||
|
class Propiedad extends Ideal\Repository
|
||
|
{
|
||
|
public function __construct(Define\Connection $connection, protected Unidad $unidadRepository)
|
||
|
{
|
||
|
parent::__construct($connection);
|
||
|
$this->setTable('propiedad');
|
||
|
}
|
||
|
|
||
|
public function create(?array $data = null): Define\Model
|
||
|
{
|
||
|
$map = [
|
||
|
'unidad_principal' => [
|
||
|
'property' => 'unidades',
|
||
|
'function' => function($data) {
|
||
|
return $this->unidadRepository->fetchByPropiedad($data['id']);
|
||
|
}
|
||
|
],
|
||
|
'estado' => [
|
||
|
'function' => function($data) {
|
||
|
return true;
|
||
|
}
|
||
|
]
|
||
|
];
|
||
|
return $this->parseData(new Model\Venta\Propiedad(), $data, $map);
|
||
|
}
|
||
|
public function save(Define\Model $model): Define\Model
|
||
|
{
|
||
|
$model->id = $this->saveNew(
|
||
|
['unidad_principal', 'estacionamientos', 'bodegas', 'estado'],
|
||
|
[$model->departamentos()[0]->id, null, null, 1]
|
||
|
);
|
||
|
return $model;
|
||
|
}
|
||
|
public function edit(Define\Model $model, array $new_data): Define\Model
|
||
|
{
|
||
|
return $this->update($model, ['unidad_principal', 'estacionamientos', 'bodegas', 'estado'], $new_data);
|
||
|
}
|
||
|
}
|