promotionRepository->fetchAll($order)); } catch (Implement\Exception\EmptyResult) { return []; } } /** * @param int $promotion_id * @return Model\Venta\Promotion * @throws Exception\ServiceAction\Read */ public function getById(int $promotion_id): Model\Venta\Promotion { try { return $this->process($this->promotionRepository->fetchById($promotion_id)); } catch (Implement\Exception\EmptyResult $exception) { throw new Exception\ServiceAction\Read(__CLASS__, $exception); } } /** * @param int $contract_id * @return array */ public function getByContract(int $contract_id): array { try { return array_map([$this, 'process'], $this->promotionRepository->fetchByContract($contract_id)); } catch (Implement\Exception\EmptyResult) { try { $contract = $this->contractRepository->fetchById($contract_id); return array_map([$this, 'process'], $this->promotionRepository->fetchByProject($contract->project->id)); } catch (Implement\Exception\EmptyResult) { return []; } } } /** * @param int $contract_id * @return array */ public function getActiveByContract(int $contract_id): array { try { return array_map([$this, 'process'], $this->promotionRepository->fetchActiveByContract($contract_id)); } catch (Implement\Exception\EmptyResult) { try { $contract = $this->contractRepository->fetchById($contract_id); return array_map([$this, 'process'], $this->promotionRepository->fetchActiveByProject($contract->project->id)); } catch (Implement\Exception\EmptyResult) { return []; } } } protected function process(Model\Venta\Promotion $model): Model\Venta\Promotion { return $model; } }