cuentaRepository->fetchAll()); return array_values(array_filter($cuentas, function(Model\Inmobiliaria\Cuenta $cuenta) { return $cuenta->currentEstado()->active; })); } catch (Implement\Exception\EmptyResult $exception) { throw new Read(__CLASS__, $exception); } } /** * @param int $inmobiliaria_rut * @return array * @throws Read */ public function getAllActiveByInmobiliaria(int $inmobiliaria_rut): array { try { $cuentas = array_map([$this, 'process'], $this->cuentaRepository->fetchByInmobiliaria($inmobiliaria_rut)); return array_values(array_filter($cuentas, function(Model\Inmobiliaria\Cuenta $cuenta) { return $cuenta->currentEstado()->active; })); } catch (Implement\Exception\EmptyResult $exception) { throw new Read(__CLASS__, $exception); } } public function add(array $data): Model\Inmobiliaria\Cuenta { $cuenta = $this->cuentaRepository->create($data); $cuenta = $this->cuentaRepository->save($cuenta); $dataEstado = [ 'cuenta_id' => $cuenta->id, 'fecha' => new DateTimeImmutable(), 'active' => true ]; $estado = $this->estadoRepository->create($dataEstado); $this->estadoRepository->save($estado); return $this->process($cuenta); } protected function process(Model\Inmobiliaria\Cuenta $cuenta): Model\Inmobiliaria\Cuenta { $cuenta->addFactory('estados', (new Implement\Repository\Factory()) ->setCallable(function($cuenta_id) { return $this->estadoRepository->fetchByCuenta($cuenta_id); }) ->setArgs(['cuenta_id' => $cuenta->id])); return $cuenta; } }