register('price_id', (new Implement\Repository\Mapper()) ->setProperty('price') ->setFunction(function($data) { return $this->precioRepository->create($data); })) ->register('start_date', new Implement\Repository\Mapper\DateTime('start_date', 'startDate')) ->register('end_date', new Implement\Repository\Mapper\DateTime('end_date', 'endDate')) ->register('valid_until', new Implement\Repository\Mapper\DateTime('valid_until', 'validUntil')); return $this->parseData(new Model\Venta\Promotion(), $data, $map); } public function save(Common\Define\Model $model): Model\Venta\Promotion { $model->id = $this->saveNew( ['amount', 'type', 'start_date', 'end_date', 'valid_until', 'price_id'], [$model->amount, $model->type, $model->startDate->format('Y-m-d'), $model->endDate->format('Y-m-d'), $model->validUntil->format('Y-m-d'), $model->price->id] ); return $model; } public function edit(Common\Define\Model $model, array $new_data): Model\Venta\Promotion { return $this->update($model, ['amount', 'type', 'start_date', 'end_date', 'valid_until', 'price_id'], $new_data); } public function fetchByPrice(int $price_id): array { $query = $this->connection->getQueryBuilder() ->select() ->from($this->getTable()) ->where('price_id = :price_id'); return $this->fetchMany($query, ['price_id' => $price_id]); } public function fetchActiveByPrice(int $price_id): array { $query = $this->connection->getQueryBuilder() ->select() ->from($this->getTable()) ->where('price_id = :price_id AND state = :state'); return $this->fetchMany($query, ['price_id' => $price_id, 'state' => Model\Venta\Promotion\State::ACTIVE]); } }