src/Controller/DashboardController.php line 15

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace PPAdmin\Controller;
  3. use PlnaPenezenka\PPSDKBundle\Doctrine\Repository\WebsRepository;
  4. use PPAdmin\Security\ManagedWebsResolver;
  5. use PPAdmin\UI\DashboardTilesControllersCollection;
  6. use Symfony\Component\HttpFoundation\RedirectResponse;
  7. use Symfony\Component\HttpFoundation\Request;
  8. use Symfony\Component\HttpFoundation\Response;
  9. use Symfony\Component\Routing\Annotation\Route;
  10. class DashboardController extends AbstractAdminController
  11. {
  12.     #[Route("/"name"dashboard")]
  13.     function dashboard(DashboardTilesControllersCollection $controllers): Response
  14.     {
  15.         $tiles_methods = [];
  16.         foreach ($controllers as $controller) {
  17.             $controller_name get_class($controller);
  18.             $method $controller->getDashboardTileMethodName();
  19.             if($method === null){
  20.                 continue;
  21.             }
  22.             if(!method_exists($controller$method)){
  23.                 throw new \RuntimeException("Controller {$controller_name} does not have method '{$method}' implemented for rendering dashboard tile");
  24.             }
  25.             $tiles_methods[$controller_name] = $method;
  26.         }
  27.         return $this->render('dashboard.html.twig', [
  28.             'tiles_methods' => $tiles_methods
  29.         ]);
  30.     }
  31.     #[Route("/manage-web/{identifier}"name"manage-web")]
  32.     function manageWeb(string $identifierManagedWebsResolver $resolverWebsRepository $webs_repoRequest $request): RedirectResponse
  33.     {
  34.         $web $webs_repo->findByIdentifier($identifier);
  35.         if(!$web){
  36.             throw $this->createNotFoundException("Web not found");
  37.         }
  38.         if(!in_array($web$resolver->getWebsManagedByCurrentAdmin())){
  39.             throw $this->createAccessDeniedException("Cannot manage given web");
  40.         }
  41.         $resolver->setCurrentManagedWeb($web);
  42.         $referer $request->headers->get('referer');
  43.         return $referer ?
  44.             $this->redirect($referer) :
  45.             $this->redirectToRoute('dashboard');
  46.     }
  47. }