/** * @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); }
/** * @param int $budgetId * @return BudgetReport|null */ public function generate($budgetId) { $budget = $this->budgetRepository->getBudgetById($budgetId); if (!$budget) { // @todo need throw exception return null; } $user = $this->userRepository->getUserById($budget->getCreateUserId()); if (!$user) { // @todo need throw exception return null; } $estimates = $this->estimateRepository->getEstimatesByBudgetId($budget->getBudgetId()); $categoryIds = []; foreach ($estimates as $estimate) { $categoryIds[] = $estimate->getCategoryId(); } $budgetEstimates = []; if (!empty($categoryIds)) { $categories = $this->categoryRepository->getListOfCategoriesByIds($categoryIds); foreach ($estimates as $estimate) { if (empty($categories[$estimate->getCategoryId()])) { // @todo need throw exception continue; } $category = $categories[$estimate->getCategoryId()]; $filterCriteria = new FilterCriteria(); $filterCriteria->setFamilyId($budget->getFamilyId()); $filterCriteria->setCategoryId($category->getCategoryId()); $filterCriteria->setOperationType(Operation::OPERATION_TYPE_EXPENSE); $filterCriteria->setStartDate($budget->getStartDate()); $filterCriteria->setEndDate($budget->getEndDate()); $budgetEstimates[] = new BudgetEstimate($estimate, $category, $this->operationFilter->filter($filterCriteria)); } } return new BudgetReport($budget, $user, $budgetEstimates); }
/** * @param UserRegisterForm $userRegisterForm * * @return bool */ private function checkUserExists(UserRegisterForm $userRegisterForm) { return !empty($this->userRepository->getUserByEmail($userRegisterForm->getEmail())); }