<?php

namespace KupShop\ContentBundle\Controller;

use KupShop\ContentBundle\View\RedirectView;
use KupShop\KupShopBundle\Routing\SimpleTranslatedRoute;
use KupShop\KupShopBundle\Routing\TranslatedRoute;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;

class RedirectController extends AbstractController
{
    /**
     * @TranslatedRoute(path="/#redir#/{type}/{id}/")
     *
     * @SimpleTranslatedRoute(path="/redir/")
     *
     * @return \Symfony\Component\HttpFoundation\Response
     */
    public function redirectAction(Request $request, RedirectView $view)
    {
        $view->setRequest($request);

        if ($request->get('type')) {
            $view->setType($request->get('type'));
        }
        if ($request->get('lang')) {
            $view->setLang($request->get('lang'));
        }
        if ($request->get('id')) {
            $view->setId($request->get('id'));
        }
        if ($request->get('inlineEdit')) {
            $view->setEnableInlineEdit(true);
        }

        $view->setPermanent($request->get('permanent', false));

        return $view->getResponse();
    }
}
