src/Controller/SponsorsController.php line 16

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  4. use Symfony\Component\Routing\Annotation\Route;
  5. /**
  6.  * @Route("/sponsoren", name="sponsors_")
  7.  */
  8. class SponsorsController extends AbstractController
  9. {
  10.     /**
  11.      * @Route("/", name="index")
  12.      */
  13.     public function index()
  14.     {
  15.         /* Get sponsors from api */
  16.         $sponsorsJson = ['entries' => []];
  17.         try {
  18.             $sponsorsJsonPath = @file_get_contents('https://api.ctc-rheda.de/api/collections/get/sponsors?token=863f1ccdb97de3b924e07b600ce0f5');
  19.             if ($sponsorsJsonPath !== false) {
  20.                 $sponsorsJson json_decode($sponsorsJsonPathtrue) ?: ['entries' => []];
  21.             }
  22.         } catch (\Exception $e) {
  23.             error_log('API Error in SponsorsController (sponsors): ' $e->getMessage());
  24.         }
  25.         /* Get meta from api */
  26.         $metaJson null;
  27.         try {
  28.             $metaJsonPath = @file_get_contents('https://api.ctc-rheda.de/api/singletons/get/sponsors?token=863f1ccdb97de3b924e07b600ce0f5');
  29.             if ($metaJsonPath !== false) {
  30.                 $metaJson json_decode($metaJsonPathtrue);
  31.             }
  32.         } catch (\Exception $e) {
  33.             error_log('API Error in SponsorsController (meta): ' $e->getMessage());
  34.         }
  35.         
  36.         // Fallback if API is not available
  37.         if ($metaJson === null) {
  38.             $metaJson = [
  39.                 'title' => 'Sponsoren',
  40.                 'description' => 'Alle Sponsoren des Cor Tennisclub Rheda e.V.',
  41.                 'keywords' => 'Tennis, Sponsoren, CTC, Rheda'
  42.             ];
  43.         }
  44.         return $this->render('pages/sponsors.html.twig', [
  45.             // passed dates to template
  46.             'sponsors' => $sponsorsJson['entries'],
  47.             'page' => array(
  48.                 'title' => 'Sponsoren',
  49.                 'description' => 'Alle Sponsoren des Cor Tennisclub Rheda e.V.',
  50.                 'meta' => $metaJson
  51.             )
  52.         ]);
  53.     }
  54. }