src/Controller/Frontend/HomeController.php line 41

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Frontend;
  3. use Symfony\Component\HttpFoundation\Response;
  4. use Symfony\Component\HttpFoundation\Request;
  5. use Symfony\Component\Routing\Annotation\Route;
  6. use Symfony\Bundle\FrameworkBundle\Controller\Controller;
  7. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  8. use Doctrine\ORM\EntityManagerInterface;
  9. use App\Service\TextHelper;
  10. use App\Service\UrlHelper;
  11. use App\Entity\News;
  12. use App\Entity\File;
  13. use App\Entity\Section;
  14. class HomeController extends AbstractController {
  15.     public function __construct() {
  16.         // echo 'We can use __contruct<br />';
  17.     }
  18. //    /**
  19. //     * @Route("{_locale}/", name="home", defaults={"_locale" = "ca"}, requirements={"_locale" = "en|ca|es"})
  20. //     * @Route("/", defaults={"_locale" = "ca"}, name="home", requirements={"_locale" = "en|ca|es"})
  21. //     */
  22.     /**
  23.      * @Route(
  24.      *   {
  25.      *       "es" : "/es",
  26.      *       "ca" : "/",
  27.      *       "en" : "/en",
  28.      *    }, name="home",
  29.      *       requirements={
  30.      *          "_locale": "es|ca|en",
  31.      *          "_format" : "html"
  32.      *      }
  33.      * )
  34.      */
  35.     public function index(Request $requestTextHelper $textHelperUrlHelper $urlHelper) {
  36.         $oneSection $this->getDoctrine()->getRepository(Section::Class)->findOneBy(['code' => 'home']);
  37.         $text = ($textHelper->getBySection($oneSection)) ? $textHelper->getBySection($oneSection) : [];
  38.         $eventAddFiles = [];
  39.         $records $this->getDoctrine()->getRepository(News::class)->findBy(['active' => 1], ['sort' => 'ASC'], 4);
  40.         if ($records) {
  41.             foreach ($records as $key => $record) {
  42.                 $image $this->getDoctrine()->getRepository(File::class)->findOneBy(array('itemId' => $record->getId(), 'section' => 'news''type' => 'mainImage'), ['sort' => 'ASC']);
  43.                 $eventAddFiles[$key]['mainImage'] = ($image) ? $urlHelper->createImageUrl('news'$record->getId(), 'resized'$image->getId(), 'backendGallery'$image->getExtension()) : null;
  44.                 $eventAddFiles[$key]['record'] = $record;
  45.             }
  46.         }
  47.         return $this->render('Frontend/home/home.html.twig', ['events' => $eventAddFiles'text' => $text'oneSection' => $oneSection]);
  48.     }
  49. }