src/StartPlatz/Bundle/MetaBundle/Controller/DefaultController.php line 38

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace App\StartPlatz\Bundle\MetaBundle\Controller;
  3. use App\StartPlatz\Bundle\AlphaBundle\Entity\Feed;
  4. use App\StartPlatz\Bundle\FibuBundle\Entity\Position;
  5. use App\StartPlatz\Bundle\SettingBundle\Entity\Transponder;
  6. use App\StartPlatz\Bundle\StartupBundle\Entity\Startup;
  7. use App\StartPlatz\Bundle\UserBundle\Entity\User;
  8. use Doctrine\ORM\EntityManagerInterface;
  9. use Symfony\Component\Routing\Annotation\Route;
  10. use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
  11. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  12. use Symfony\Component\HttpFoundation\Request;
  13. class DefaultController extends AbstractController
  14. {
  15.     public function __construct(
  16.         private readonly EntityManagerInterface $entityManager
  17.     ) {
  18.     }
  19.     #[Route('/redirect/page'name'meta_redirect_page')]
  20.     public function redirectAction(Request $request)
  21.     {
  22.         $redirect json_decode(base64_decode((string) $request->get('redirect')));
  23.         if (!$redirect) {
  24.             return $this->redirect($this->generateUrl('x_home'));
  25.         }
  26.         return $this->redirect($this->generateUrl($redirect->path, (array) $redirect->parameters));
  27.     }
  28.     #[Route('/x/feed/link/{url}'name'meta_feed_link'requirements: ['url' => '.+'])]
  29.     /**
  30.      * @IsGranted("ROLE_USER")
  31.      */
  32.     public function feedLinkAction(Request $request$url)
  33.     {
  34.         $em $this->entityManager;
  35.         /** @var User $user */
  36.         if ($user $this->getUser()) {
  37.             $em->getRepository(User::class)->writeActivity($user);
  38.         }
  39.         if ($feedId $request->get('feedId')) {
  40.             $em->getRepository(Feed::class)->updateScoreByUrlLink($feedId);
  41.         }
  42.         $url urldecode((string) $url);
  43.         return $this->redirect($url);
  44.     }
  45.     #[Route('/show-more/{id}/{field}/{entity}'name'allmeda_meta_show_more')]
  46.     /**
  47.      * @IsGranted("ROLE_ADMIN")
  48.      */
  49.     public function showMoreAction(Request $request$id$field$entity)
  50.     {
  51.         $allowedEntities = ['transponder''easybillPosition'];
  52.         if (!in_array($entity$allowedEntitiestrue)) {
  53.             throw $this->createNotFoundException('Invalid entity type');
  54.         }
  55.         $allowedFields = ['description''notes''comment''content''text'];
  56.         if (!in_array($field$allowedFieldstrue)) {
  57.             throw $this->createNotFoundException('Invalid field');
  58.         }
  59.         $em $this->entityManager;
  60.         switch ($entity) {
  61.             case "transponder":
  62.                 $entity $em->getRepository(Transponder::class)->findOneBy(['id' => $id]);
  63.                 break;
  64.             case "easybillPosition":
  65.                 $entity $em->getRepository(Position::class)->findOneBy(['id' => $id]);
  66.                 break;
  67.         }
  68.         if (!$entity) {
  69.             throw $this->createNotFoundException('Entity not found');
  70.         }
  71.         $method 'get' ucfirst((string) $field);
  72.         $more   $entity->$method();
  73.         return $this->render('@StartPlatzSettingBundle/showMore.html.twig', ['id' => $id'more'    => $more]);
  74.     }
  75. }