src/Monitor/Controller/DashboardController.php line 22

Open in your IDE?
  1. <?php
  2. namespace App\Monitor\Controller;
  3. use App\Monitor\Entity\Environment;
  4. use App\Monitor\Entity\Project;
  5. use App\Monitor\Entity\Result;
  6. use App\Monitor\Service\LicenseManager;
  7. use App\UI\Controller\AbstractUIController;
  8. use DateTime;
  9. use Doctrine\Common\Collections\Criteria;
  10. use Symfony\Component\Form\Extension\Core\Type\DateType;
  11. use Symfony\Component\Form\Extension\Core\Type\SubmitType;
  12. use Symfony\Component\HttpFoundation\Request;
  13. use Symfony\Component\HttpFoundation\Response;
  14. use Symfony\Component\Routing\Annotation\Route;
  15. class DashboardController extends AbstractUIController
  16. {
  17.     /**
  18.      * @Route("/")
  19.      */
  20.     public function list(Request $requestLicenseManager $licenseManager):Response
  21.     {
  22.         $projectRep $this->entityManager->getRepository(Project::class);
  23.         $environmentRep $this->entityManager->getRepository(Environment::class);
  24.         $resultRep $this->entityManager->getRepository(Result::class);
  25.         $licenseForm $this->createFormBuilder()
  26.             ->add('appSecret')
  27.             ->add('licensedTill'DateType::class, ['data' => (new DateTime())->modify('+ 365 days')])
  28.             ->add('save'SubmitType::class, ['label' => 'Generate license key'])
  29.             ->getForm();
  30.         $licenseForm->handleRequest($request);
  31.         if ($licenseForm->isSubmitted()) {
  32.             $data $licenseForm->getData();
  33.             $customKey $licenseManager->generateKey($data['appSecret'], $data['licensedTill']);
  34.             $this->addFlash('success''Generated key <b>' $customKey '</b>');
  35.             return $this->redirectToRoute('app_monitor_dashboard_list');
  36.         }
  37.         return $this->render(
  38.             'monitor/dashboard.html.twig', [
  39.             'totalProjects' => $projectRep->count([]),
  40.             'totalEnvironments' => $environmentRep->count([]),
  41.             'totalMonitorActiveEnvironments' => $environmentRep->count(['monitorActive' => true]),
  42.             'totalResults' => $resultRep->count([]),
  43.             'projects' => $projectRep->findBy([], ['clientName' => Criteria::ASC]),
  44.             'licenseForm' => $licenseForm->createView()
  45.         ]);
  46.     }
  47. }