src/Controller/Admin/HomeController.php line 25

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Admin;
  3. use App\Domain\Entity\Folder;
  4. use App\Domain\Entity\FolderUser;
  5. use App\Domain\Entity\Project;
  6. use App\Domain\Entity\User;
  7. use App\Service\FolderService;
  8. use App\Service\FolderUserService;
  9. use App\Service\ProjectService;
  10. use App\Service\UserService;
  11. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  12. use Symfony\Component\HttpFoundation\Request;
  13. use Symfony\Component\HttpFoundation\Response;
  14. use Symfony\Component\Routing\Annotation\Route;
  15. class HomeController extends AbstractController
  16. {
  17.     /**
  18.      * @Route("/", methods={"GET"}, name="home")
  19.      */
  20.     public function home(): Response
  21.     {
  22.         return $this->redirectToRoute('investor_home');
  23.     }
  24.     /**
  25.      * @Route("/admin", methods={"GET"}, name="admin_home")
  26.      */
  27.     public function homeAdmin(
  28.         ProjectService $projectService,
  29.         UserService $userService,
  30.         FolderService $folderService): Response
  31.     {
  32.         $this->denyAccessUnlessGranted(User::ROLE_SIMPLE_ADMIN);
  33.         $projectsPending = [];
  34.         $allProjects $projectService->getProjects();
  35.         foreach ($allProjects as $p) {
  36.             /** @var Project $p */
  37.             //If status not in [Project::STATUS_REVOKED, Project::STATUS_APPROVED]
  38.             if (!in_array($p->getStatus(), [Project::STATUS_REVOKEDProject::STATUS_APPROVED])) {
  39.                 $projectsPending[] = $p;
  40.                 continue;
  41.             }
  42.             //if has users to be validated
  43.             if ($p->getPendingCount() > 0) {
  44.                 $projectsPending[] = $p;
  45.                 continue;
  46.             }
  47.         }
  48.         return $this->render('admin/home.html.twig',
  49.             [
  50.                 'generalTitle' => 'Squircle Capital Admin',
  51.                 'baseTitle' => 'Dashboard',
  52.                 'projectCount' => $projectService->getProjectsCount(),
  53.                 'pendingProjects' => $projectsPending,
  54.                 'pendingFolders' => $folderService->getFoldersPending(),
  55.                 'userCount' => $userService->getUsersCount(),
  56.                 'projectCount' => $projectService->getProjectsCount(),
  57.                 'folderCount' => $folderService->getFolderCount()
  58.             ]);
  59.     }
  60.     /**
  61.      * @Route("/admin/folder-manage/{action}", name="admin_home_folder_manage_investors_grant_revoke", methods={"POST"})
  62.      * @param Request $request
  63.      * @param string $action
  64.      * @param ProjectService $projectService
  65.      * @return Response
  66.      */
  67.     public function manageHomeFoldersStatus(
  68.         Request $request,
  69.         string $action,
  70.         ProjectService $projectService): Response
  71.     {
  72.         $this->denyAccessUnlessGranted(User::ROLE_SIMPLE_ADMIN);
  73.         /** @var User $user */
  74.         $user $this->getUser();
  75.         //we are receiving folders but in this case, they are projects ids.
  76.         $projects $request->get('folders');
  77.         foreach ($projects as $projectId) {
  78.             $project $projectService->getOneById($projectId);
  79.             if ($project) {
  80.                 $projectService->updateStatus($project$action$user);
  81.             }
  82.         }
  83.         $this->addFlash('success','Projects updated!');
  84.         $response = new Response();
  85.         $response->setContent(json_encode([
  86.             'message' => 'Folders status edited ok',
  87.         ]));
  88.         $response->headers->set('Content-Type''application/json');
  89.         return $response;
  90.     }
  91. }