55 lines
1.9 KiB
PHP
55 lines
1.9 KiB
PHP
![]() |
<?php
|
||
|
namespace Incoviba\Repository\MediosPago\Toku;
|
||
|
|
||
|
use DateTimeImmutable;
|
||
|
use Incoviba\Common\Ideal;
|
||
|
use Incoviba\Common\Define;
|
||
|
use Incoviba\Common\Implement;
|
||
|
use Incoviba\Model;
|
||
|
use Incoviba\Repository;
|
||
|
|
||
|
class Subscription extends Ideal\Repository
|
||
|
{
|
||
|
public function __construct(Define\Connection $connection, protected Repository\Venta $ventaRepository)
|
||
|
{
|
||
|
parent::__construct($connection);
|
||
|
}
|
||
|
|
||
|
public function getTable(): string
|
||
|
{
|
||
|
return 'toku_subscriptions';
|
||
|
}
|
||
|
|
||
|
public function create(?array $data = null): Model\MediosPago\Toku\Subscription
|
||
|
{
|
||
|
$map = (new Implement\Repository\MapperParser(['toku_id']))
|
||
|
->register('venta_id', (new Implement\Repository\Mapper())
|
||
|
->setProperty('venta')
|
||
|
->setFunction(function($data) {
|
||
|
return $this->ventaRepository->fetchById($data['venta_id']);
|
||
|
}));
|
||
|
return $this->parseData(new Model\MediosPago\Toku\Subscription(), $data, $map);
|
||
|
}
|
||
|
public function save(Define\Model $model): Model\MediosPago\Toku\Subscription
|
||
|
{
|
||
|
$model->id = $this->saveNew(
|
||
|
['venta_id', 'toku_id', 'created_at'],
|
||
|
[$model->venta->id, $model->toku_id, (new DateTimeImmutable())->format('Y-m-d H:i:s.u')]
|
||
|
);
|
||
|
return $model;
|
||
|
}
|
||
|
public function edit(Define\Model $model, array $new_data): Model\MediosPago\Toku\Subscription
|
||
|
{
|
||
|
return $this->update($model, ['venta_id', 'toku_id', 'updated_at'], array_merge($new_data, ['updated_at' => (new DateTimeImmutable())->format('Y-m-d H:i:s.u')]));
|
||
|
}
|
||
|
|
||
|
public function fetchByVenta(int $venta_id): Model\MediosPago\Toku\Subscription
|
||
|
{
|
||
|
$query = $this->connection->getQueryBuilder()
|
||
|
->select()
|
||
|
->from($this->getTable())
|
||
|
->where('venta_id = :venta_id');
|
||
|
return $this->fetchOne($query, compact('venta_id'));
|
||
|
}
|
||
|
}
|