<?php


namespace AutoAdmin\Bundle\Admin\Controller\Admin;

use Symfony\Component\HttpFoundation\Request;

/**
 * Class EntityController
 * @package AutoAdmin\Bundle\Admin\Controller\Admin
 *
 */
class LogController extends EntityController
{
    public function adminLink(Request $request)
    {
        $entitySlug = $request->get('entitySlug');
        $id = $request->get('id');

        $entity = $this->resolveEntity($entitySlug, $id);

        if (!$url = $entity->getAdminLink()) {
            $this->addFlash('error', 'Pas de lien admin');

            return $this->redirectToRoute('aa_admin_entity', array_merge(
                $request->attributes->all(),
                ['action' => 'list']
            ));
        }

        return $this->redirect($url);
    }

    public function frontLink(Request $request)
    {
        $entitySlug = $request->get('entitySlug');
        $id = $request->get('id');

        $entity = $this->resolveEntity($entitySlug, $id);

        if (!$url = $entity->getFrontLink()) {
            $this->addFlash('error', 'Pas de lien front');

            return $this->redirectToRoute('aa_admin_entity', array_merge(
                $request->attributes->all(),
                ['action' => 'list']
            ));
        }

        return $this->redirect($url);
    }

}