/** * @param Estimate $estimate * @param AuthUser $user * * @return Estimate|null */ public function save(Estimate $estimate, AuthUser $user) { if (empty($estimate->getEstimateId())) { $estimate->setCreateUserId($user->getUserId()); $family = $this->familyRepository->getFamilyByUserId($user->getUserId()); $estimate->setFamilyId($family->getFamilyId()); } $estimate->setIsClosed(false); $estimateId = $this->estimateRepository->save($estimate); if (!$estimateId) { return null; } return $this->estimateRepository->getEstimateById($estimateId); }
/** * @param BudgetForm $budgetForm * @param AuthUser $user * * @return Budget|null */ public function save(BudgetForm $budgetForm, AuthUser $user) { if (empty($budgetForm->getBudgetId())) { $budgetForm->setCreateUserId($user->getUserId()); $family = $this->familyRepository->getFamilyByUserId($user->getUserId()); $budgetForm->setFamilyId($family->getFamilyId()); } $budgetForm->setIsClosed(false); $budgetId = $this->budgetRepository->save($budgetForm); if (!$budgetId) { return null; } return $this->budgetRepository->getBudgetById($budgetId); }
/** * @param AuthUser $user * @param string $categoryName * * @return bool */ public function add(AuthUser $user, $categoryName) { $family = $this->familyRepository->getFamilyByUserId($user->getUserId()); return $this->categoryRepository->insert(['family_id', 'category_name'])->values([$family->getFamilyId(), $categoryName]); }