Пример #1
0
 /**
  * @param Request $request
  */
 public function saveAction(Request $request)
 {
     if ($request->isPost() && $request->hasRequest('estimate')) {
         /** @var EstimateRepository $estimateRepository */
         $estimateRepository = $this->getDbFacade()->getEntityRepository(EstimateRepository::class);
         /** @var FamilyRepository $familyRepository */
         $familyRepository = $this->getDbFacade()->getEntityRepository(FamilyRepository::class);
         $estimateManager = new EstimateManager($estimateRepository, $familyRepository);
         /** @var AuthUser $user */
         $user = $this->getUser();
         $estimate = new Estimate($request->getRequest('estimate'));
         $estimateManager->save($estimate, $user);
         $this->redirect('budget/view', ['id' => $estimate->getBudgetId()]);
     }
     $this->redirect('budget/view');
 }
Пример #2
0
 /**
  * Добавление категории.
  *
  * @param Request $request Объект запроса.
  *
  * @return string форма добавления категории
  */
 public function addAction(Request $request)
 {
     if (!$this->getUser()->isAuth()) {
         $this->redirect('user/login');
     }
     if (!empty($request->getRequest('category')['categoryName'])) {
         /** @var FamilyRepository $familyRepository */
         $familyRepository = $this->getDbFacade()->getEntityRepository(FamilyRepository::class);
         /** @var CategoryRepository $categoryRepository */
         $categoryRepository = $this->getDbFacade()->getEntityRepository(CategoryRepository::class);
         $categoryManager = new CategoryManager($familyRepository, $categoryRepository);
         /** @var AuthUser $user */
         $user = $this->getUser();
         $categoryManager->add($user, $request->getRequest('category')['categoryName']);
         $this->redirect('category/list');
     }
     return $this->view->render('category/add');
 }
Пример #3
0
 public function registerAction(Request $request)
 {
     if ($this->getUser()->isAuth()) {
         $this->redirect('index/index');
     }
     $isRegister = false;
     $userRegisterForm = new UserRegisterForm();
     if ($request->getRequest('register')) {
         $isRegister = true;
         /** @var UserRepository $userRepository */
         $userRepository = $this->getDbFacade()->getEntityRepository(UserRepository::class);
         /** @var FamilyRepository $familyRepository */
         $familyRepository = $this->getDbFacade()->getEntityRepository(FamilyRepository::class);
         $userRegister = new UserRegister($userRepository, $familyRepository);
         $userRegisterForm->loadData($request->getRequest('register'));
         if ($userRegister->run($userRegisterForm) == UserRegister::USER_REGISTER_OK) {
             $this->redirect('index/index');
         }
     }
     $this->view->setLayout('single');
     return $this->view->render('user/register', ['isRegister' => $isRegister, 'userRegisterForm' => $userRegisterForm]);
 }
Пример #4
0
 public function editAction(Request $request)
 {
     /** @var BudgetRepository $budgetRepository */
     $budgetRepository = $this->getDbFacade()->getEntityRepository(BudgetRepository::class);
     $budget = $budgetRepository->getBudgetById($request->getQuery('id'));
     if (!$budget) {
         $this->notFound();
     }
     return $this->view->render('budget/edit', ['budget' => $budget]);
 }
Пример #5
0
 /**
  * Выводит список расходов/доходов для управления.
  *
  * @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]);
 }