src/Controller/ActivityLogController.php line 30

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Repository\ActivityLogRepository;
  4. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  5. use Symfony\Component\HttpFoundation\{RequestResponse};
  6. use Symfony\Component\Routing\Annotation\Route;
  7. use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
  8. use Nzo\UrlEncryptorBundle\Annotations\ParamDecryptor;
  9. #[Route(path'/activity/log')]
  10. class ActivityLogController extends AbstractController
  11. {
  12.     #[Route('/'name'activity_log'methods: ['GET'])]
  13.     public function index(ActivityLogRepository $activityLogRepository): Response
  14.     {
  15.         $activityLog $activityLogRepository->GetRecordList($this->getUser()->getHospital()->getId(), $this->getUser()->getId());
  16.         return $this->render('activity_log/index.html.twig', [
  17.             'activityLog' => $activityLog,
  18.         ]);
  19.     }
  20.     #[Route('/download/{id}'name'download'methods: ['GET'])]
  21.     #[ParamDecryptor(["id"])]
  22.     public function export(Request $requestActivityLogRepository $activityLogRepository): Response
  23.     {
  24.         $activityLog $activityLogRepository->GetRecordById($request->attributes->get('id'));
  25.         $path $this->getParameter('upload_dir') . "/activity_log/" $this->getUser()->getId() . '/';
  26.         $content file_get_contents($path $activityLog);
  27.         $response = new Response();
  28.         $response->headers->set('Content-Type''mime/type');
  29.         $response->headers->set('Content-Disposition''attachment;filename="' $activityLog);
  30.         $response->setContent($content);
  31.         return $response;
  32.     }
  33. }