Пример #1
0
 /**
  * @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);
 }
Пример #2
0
 /**
  * @param BudgetForm $budgetForm
  *
  * @return int
  */
 public function save(BudgetForm $budgetForm)
 {
     $budgetId = 0;
     if ($budgetForm->getBudgetId()) {
         $update = (bool) $this->update()->where(['budget_id', '=', $budgetForm->getBudgetId()])->execute(['name' => $budgetForm->getName(), 'description' => $budgetForm->getDescription(), 'start_date' => $budgetForm->getStartDate(), 'end_date' => $budgetForm->getEndDate(), 'is_closed' => $budgetForm->isClosed()]);
         if ($update) {
             $budgetId = $budgetForm->getBudgetId();
         }
     } else {
         $insert = $this->insert(['create_user_id', 'family_id', 'name', 'description', 'start_date', 'end_date', 'is_closed'])->values([$budgetForm->getCreateUserId(), $budgetForm->getFamilyId(), $budgetForm->getName(), $budgetForm->getDescription(), $budgetForm->getStartDate(), $budgetForm->getEndDate(), $budgetForm->isClosed()]);
         if ($insert) {
             $budgetId = $this->getConnection()->lastInsertId('budget_id');
         }
     }
     return $budgetId;
 }