Exemplo n.º 1
0
 /**
  * @param UserRegisterForm $userRegisterForm
  *
  * @return string
  */
 public function run(UserRegisterForm $userRegisterForm)
 {
     $valid = $userRegisterForm->valid();
     if ($valid != UserRegisterForm::VALID_OK) {
         return $valid;
     }
     if ($this->valid($userRegisterForm)) {
         $userRegisterForm->setError(UserRegisterForm::USER_EXISTS);
         return self::USER_REGISTER_FAIL;
     }
     try {
         $registerUser = $this->userRepository->registerUser($userRegisterForm);
         if (!$registerUser) {
             return self::USER_REGISTER_FAIL;
         }
         $user = $this->userRepository->getUserByEmail($userRegisterForm->getEmail());
         $registerFamily = $this->familyRepository->registerFamily($user->getUserId());
         if (!$registerFamily) {
             return self::USER_REGISTER_FAIL;
         }
         $family = $this->familyRepository->getFamilyByHeadUserId($user->getUserId());
         $attachUserToFamily = $this->familyRepository->attachUserToFamily($user->getUserId(), $family->getFamilyId());
         if (!$attachUserToFamily) {
             return self::USER_REGISTER_FAIL;
         }
     } catch (\Exception $exc) {
         // @todo Add logging.
         return self::USER_REGISTER_FAIL;
     }
     return self::USER_REGISTER_OK;
 }
Exemplo n.º 2
0
 /**
  * @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);
 }
Exemplo n.º 3
0
 /**
  * @param int $userId
  *
  * @return AuthUser[]
  */
 public function getUsersOfFamilyByUserId($userId)
 {
     $family = $this->familyRepository->getFamilyByUserId($userId);
     if (!$family) {
         return [];
     }
     $relationsOfFamily = $this->familyRepository->getRelationsOfFamily($family->getFamilyId());
     $userIds = [];
     foreach ($relationsOfFamily as $relation) {
         $userIds[] = $relation->getUserId();
     }
     if (empty($userIds)) {
         return [];
     }
     return $this->userRepository->getUsersByIds($userIds);
 }
Exemplo n.º 4
0
 /**
  * @param int $userId
  *
  * @return Category[]
  */
 public function getListOfCategoryByUserId($userId)
 {
     $family = $this->familyRepository->getFamilyByUserId($userId);
     return $this->categoryRepository->getListOfCategoriesByFamilyId($family->getFamilyId());
 }
Exemplo n.º 5
0
 /**
  * @param int $userId
  *
  * @return Budget[]
  */
 public function getListOfBudgetsByUserId($userId)
 {
     $family = $this->familyRepository->getFamilyByUserId($userId);
     return $this->budgetRepository->getBudgetsByFamilyId($family->getFamilyId());
 }