<?php declare(strict_types=1);
namespace App\StartPlatz\Bundle\MetaBundle\Controller;
use App\StartPlatz\Bundle\AlphaBundle\Entity\Feed;
use App\StartPlatz\Bundle\FibuBundle\Entity\Position;
use App\StartPlatz\Bundle\SettingBundle\Entity\Transponder;
use App\StartPlatz\Bundle\StartupBundle\Entity\Startup;
use App\StartPlatz\Bundle\UserBundle\Entity\User;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\Routing\Annotation\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
class DefaultController extends AbstractController
{
public function __construct(
private readonly EntityManagerInterface $entityManager
) {
}
#[Route('/redirect/page', name: 'meta_redirect_page')]
public function redirectAction(Request $request)
{
$redirect = json_decode(base64_decode((string) $request->get('redirect')));
if (!$redirect) {
return $this->redirect($this->generateUrl('x_home'));
}
return $this->redirect($this->generateUrl($redirect->path, (array) $redirect->parameters));
}
#[Route('/x/feed/link/{url}', name: 'meta_feed_link', requirements: ['url' => '.+'])]
/**
* @IsGranted("ROLE_USER")
*/
public function feedLinkAction(Request $request, $url)
{
$em = $this->entityManager;
/** @var User $user */
if ($user = $this->getUser()) {
$em->getRepository(User::class)->writeActivity($user);
}
if ($feedId = $request->get('feedId')) {
$em->getRepository(Feed::class)->updateScoreByUrlLink($feedId);
}
$url = urldecode((string) $url);
return $this->redirect($url);
}
#[Route('/show-more/{id}/{field}/{entity}', name: 'allmeda_meta_show_more')]
/**
* @IsGranted("ROLE_ADMIN")
*/
public function showMoreAction(Request $request, $id, $field, $entity)
{
$allowedEntities = ['transponder', 'easybillPosition'];
if (!in_array($entity, $allowedEntities, true)) {
throw $this->createNotFoundException('Invalid entity type');
}
$allowedFields = ['description', 'notes', 'comment', 'content', 'text'];
if (!in_array($field, $allowedFields, true)) {
throw $this->createNotFoundException('Invalid field');
}
$em = $this->entityManager;
switch ($entity) {
case "transponder":
$entity = $em->getRepository(Transponder::class)->findOneBy(['id' => $id]);
break;
case "easybillPosition":
$entity = $em->getRepository(Position::class)->findOneBy(['id' => $id]);
break;
}
if (!$entity) {
throw $this->createNotFoundException('Entity not found');
}
$method = 'get' . ucfirst((string) $field);
$more = $entity->$method();
return $this->render('@StartPlatzSettingBundle/showMore.html.twig', ['id' => $id, 'more' => $more]);
}
}