Exemple #1
0
 /**
  * Вывод главной страницы.
  *
  * @return string Представление главной страницы
  */
 public function indexAction()
 {
     if (!$this->getUser()->isAuth()) {
         $this->redirect('user/login');
     }
     /** @var UserRepository $userRepository */
     $userRepository = $this->getDbFacade()->getEntityRepository(UserRepository::class);
     /** @var FamilyRepository $familyRepository */
     $familyRepository = $this->getDbFacade()->getEntityRepository(FamilyRepository::class);
     $familyManager = new FamilyManager($familyRepository, $userRepository);
     $users = $familyManager->getUsersOfFamilyByUserId($this->getUser()->getUserId());
     /** @var CategoryRepository $categoryRepository */
     $categoryRepository = $this->getDbFacade()->getEntityRepository(CategoryRepository::class);
     $family = $familyRepository->getFamilyByUserId($this->getUser()->getUserId());
     $categories = $categoryRepository->getListOfCategoriesByFamilyId($family->getFamilyId());
     /** @var OperationRepository $operationRepository */
     $operationRepository = $this->getDbFacade()->getEntityRepository(OperationRepository::class);
     $operations = $operationRepository->getOperationsByFamilyId($family->getFamilyId(), new RangeStruct(self::SHOW_NUMBER_OF_OPERATIONS_ON_PER_PAGE, 0));
     $statisticService = new StatisticService($operationRepository);
     $expenseAmount = $statisticService->getExpenseAmount($family->getFamilyId());
     $incomeAmount = $statisticService->getIncomeAmount($family->getFamilyId());
     $expenseAmountInMonth = $statisticService->getExpenseAmountInMonth($family->getFamilyId());
     $incomeAmountInMonth = $statisticService->getIncomeAmountInMonth($family->getFamilyId());
     return $this->view->render('index/index', ['users' => $users, 'categories' => $categories, 'operations' => $operations, 'expenseAmount' => $expenseAmount, 'incomeAmount' => $incomeAmount, 'expenseAmountInMonth' => $expenseAmountInMonth, 'incomeAmountInMonth' => $incomeAmountInMonth]);
 }
 /**
  * Выводит список расходов/доходов для управления.
  *
  * @param Request $request
  *
  * @return string Список расходов/доходов.
  */
 public function listAction(Request $request)
 {
     if (!$this->getUser()->isAuth()) {
         $this->redirect('user/login');
     }
     $filterCriteria = new FilterCriteria();
     $filterCriteria->setOrderBy('operation_id', OrderByExpressionInterface::ORDER_DESC);
     /** @var FamilyRepository $familyRepository */
     $familyRepository = $this->getDbFacade()->getEntityRepository(FamilyRepository::class);
     $family = $familyRepository->getFamilyByUserId($this->getUser()->getUserId());
     $filterCriteria->setFamilyId($family->getFamilyId());
     if ($request->hasRequest('operationFilter')) {
         $filterCriteria->setApplyFilter(true);
         $operationFilter = $request->getRequest('operationFilter');
         if (isset($operationFilter['categoryId'])) {
             $filterCriteria->setCategoryId($operationFilter['categoryId']);
         }
         if (isset($operationFilter['period'])) {
             $filterCriteria->setPeriod($operationFilter['period']);
         }
         if (isset($operationFilter['operationType'])) {
             $filterCriteria->setOperationType($operationFilter['operationType']);
         }
         if (isset($operationFilter['startDate'])) {
             $filterCriteria->setStartDate($operationFilter['startDate']);
         }
         if (isset($operationFilter['endDate'])) {
             $filterCriteria->setEndDate($operationFilter['endDate']);
         }
     }
     /** @var OperationRepository $operationRepository */
     $operationRepository = $this->getDbFacade()->getEntityRepository(OperationRepository::class);
     $paginator = new Paginator(new PaginationFactory(), new PaginationViewer($this->view));
     $pagination = null;
     try {
         $pagination = $paginator->build(self::SHOW_OPERATIONS_ON_PER_PAGE, $operationRepository->getOperationsCountByFamilyId($family->getFamilyId()), (int) $request->getQuery('page'));
         $filterCriteria->setRange(new RangeStruct($pagination->getPerPage(), $pagination->getOffset()));
     } catch (\InvalidArgumentException $exc) {
         // @todo Need add logging
     }
     $operationFilterService = new OperationFilter($operationRepository);
     $operations = $operationFilterService->filter($filterCriteria);
     /** @var UserRepository $userRepository */
     $userRepository = $this->getDbFacade()->getEntityRepository(UserRepository::class);
     $familyManager = new FamilyManager($familyRepository, $userRepository);
     $users = $familyManager->getUsersOfFamilyByUserId($this->getUser()->getUserId());
     /** @var CategoryRepository $categoryRepository */
     $categoryRepository = $this->getDbFacade()->getEntityRepository(CategoryRepository::class);
     $categories = $categoryRepository->getListOfCategoriesByFamilyId($family->getFamilyId());
     return $this->view->render('operation/list', ['users' => $users, 'filterCriteria' => $filterCriteria, 'categories' => $categories, 'operations' => $operations, 'pagination' => $pagination]);
 }