src/Controller/TargetsController.php line 29

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Model\Target\Report as TargetReport;
  4. use App\Entity\Scan;
  5. use App\Model\Tag;
  6. use DateTime;
  7. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  8. use Symfony\Component\HttpFoundation\Response;
  9. use Symfony\Component\HttpFoundation\Request;
  10. use Symfony\Component\HttpFoundation\JsonResponse;
  11. use Symfony\Component\Routing\Annotation\Route;
  12. /**
  13.  * Projects controller.
  14.  */
  15. class TargetsController extends AbstractController
  16. {
  17.     const DATETIME_FORMAT 'Y-m-d';
  18.     /**
  19.      * Show all projects.
  20.      *
  21.      * @Route(path="", name="targets_index", methods={"GET"})
  22.      *
  23.      * @return Response
  24.      */
  25.     public function indexAction(): Response
  26.     {
  27.         return $this->render('targets/list.html.twig', [
  28.             'trafficType'  => Scan::FLAG_TRAFFIC_LABELS,
  29.             'statusLabels' => Scan::STATUS_LABELS,
  30.             'tagTypes'     => Tag::TYPE_LABELS,
  31.         ]);
  32.     }
  33.     /**
  34.      * Gets targets list
  35.      *
  36.      * @Route(path="/targets/list", name="targets_list", methods={"GET"})
  37.      *
  38.      * @param Request      $request
  39.      * @param TargetReport $targetReport
  40.      * @return JsonResponse
  41.      */
  42.     public function listAction(Request $requestTargetReport $targetReport): JsonResponse
  43.     {
  44.         $from           $request->query->get('from'date("Y-m-d"));
  45.         $to             $request->query->get('to'date("Y-m-d"));
  46.         $trafficType    $request->query->get('trafficType''');
  47.         $lastScanStatus $request->query->get('lastScanStatus''');
  48.         $tags           $request->query->get('tags''');
  49.         $from           DateTime::createFromFormat(self::DATETIME_FORMAT$from);
  50.         $to             DateTime::createFromFormat(self::DATETIME_FORMAT$to);
  51.         $trafficType    = !empty($trafficType) ? explode(','$trafficType) : [];
  52.         $lastScanStatus = !empty($lastScanStatus) ? explode(','$lastScanStatus) : [];
  53.         $tags           = !empty($tags) ? explode(','$tags) : [];
  54.         $targetDTOs $targetReport->getTargetsWithLastScanResult($from$to$trafficType$lastScanStatus$tags);
  55.         return $this->json($targetDTOs);
  56.     }
  57. }