src/Controller/DefaultController.php line 14

  1. <?php
  2. namespace App\Controller;
  3. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  4. use Symfony\Component\Finder\Finder;
  5. use Symfony\Component\HttpFoundation\Request;
  6. use Symfony\Component\HttpFoundation\Response;
  7. use Symfony\Component\Routing\Annotation\Route;
  8. class DefaultController extends AbstractController
  9. {
  10.     #[Route('/'name'app_home'methods: ['GET'])]
  11.     public function index(Request $request): Response
  12.     {
  13.         return $this->render('default/tagung-april.html.twig', [
  14.             'images' => $this->get_files('public/media/tagung-april-imgs'),
  15.             'opengallery' => $request->getSession()->getFlashBag()->get('opengallery')
  16.         ]);
  17.     }
  18.     #[Route('/tagung-september-2023'name'tagung_september'methods: ['GET'])]
  19.     public function tagung_september(Request $request): Response
  20.     {
  21.         return $this->render('default/tagung-september.html.twig', [
  22.             'images' => $this->get_files('public/media/tagung-september-imgs'),
  23.             'opengallery' => $request->getSession()->getFlashBag()->get('opengallery')
  24.         ]);
  25.     }
  26.     #[Route('/welcome'name'app_welcome')]
  27.     public function welcome(): Response
  28.     {
  29.         return $this->render('default/welcome.html.twig');
  30.     }
  31.     #[Route('/imprint'name'app_imprint')]
  32.     public function imprint(): Response
  33.     {
  34.         return $this->render('default/imprint.html.twig');
  35.     }
  36.     #[Route('/logout'name'app_logout'methods: ['GET'])]
  37.     public function logout()
  38.     {
  39.         // controller can be blank: it will never be called!
  40.         throw new \Exception('Don\'t forget to activate logout in security.yaml');
  41.     }
  42.     private function get_files($folder){
  43.         $finder = new Finder();
  44.         $finder->files()->in($folder)->sortByName();
  45.         $files = array();
  46.         $i 0;
  47.         $tempFiles = [];
  48.         foreach ($finder as $file) {
  49.             $i++;
  50.             $fileNameWithExtension $file->getRelativePathname();
  51.             $tempFiles[] = $fileNameWithExtension;
  52.             if($i === 20) {
  53.                 $files[] = $tempFiles;
  54.                 $tempFiles = [];
  55.                 $i 0;
  56.             }
  57.         }
  58.         $files[] = $tempFiles;
  59.         return $files;
  60.     }
  61. }