<?php
namespace WAM\Bundle\WebContentBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Response;
/**
* @author Edgar Tébar <etebar@wearemarketing.com>
*/
class EditInlineController extends Controller
{
const NEW_MESSAGE_INPUT_NAME = 'new_message';
const TEMPLATE_EDIT_INLINE_FORM = 'WAMWebContentBundle:EditInline:edit_inline_translation.html.twig';
const TEMPLATE_TRANS_LINK_ADMIN = 'WAMWebContentBundle:EditInline:path_to_admin_translation.html.twig';
const TEMPLATE_EDIT_INLINE_FULL_PATH = 'WAMWebContentBundle:EditInline:full_edit_path_template.html.twig';
public function updateTranslationAction($id)
{
$request = $this->container->get('request_stack')->getCurrentRequest();
$locale = $request->get('_locale');
$transUnit = $this->getDoctrine()->getRepository('LexikTranslationBundle:TransUnit')->findOneById($id);
$transUnitManager = $this->container->get('lexik_translation.trans_unit.manager');
$newMessage = $request->get(self::NEW_MESSAGE_INPUT_NAME);
$transUnitManager->updateTranslation(
$transUnit,
$locale,
$newMessage,
true
);
$this->clearCache();
return new Response($newMessage);
}
public function fullAdminEditAction($route = '', $aditionalClass = '', $title = '', $faIconClass = '', $parentClass = '')
{
$response = $this->render(self::TEMPLATE_EDIT_INLINE_FULL_PATH, array(
'route' => $route,
'aditional_class' => $aditionalClass,
'title' => $title,
'fa_icon_class' => $faIconClass,
'parent_class' => $parentClass,
));
$response->setPrivate();
return $response;
}
public function adminBarAction($id, $class)
{
$object = $this->getEntityManager()->find($class, $id);
$response = $this->render('WAMWebContentBundle:EditInline:admin_bar.html.twig', array(
'object' => $object,
));
$response->setPrivate();
return $response;
}
public function renderFormAction($trans = '', $message = '')
{
$object = $this->getEntityManager()->getRepository('LexikTranslationBundle:TransUnit')
->findOneByKey($message);
$response = $this->render(self::TEMPLATE_EDIT_INLINE_FORM, array(
'trans' => $trans,
'message' => $message,
'object' => $object,
));
$response->setPrivate();
return $response;
}
public function clearCacheAction()
{
$this->clearCache();
return new Response('cache_clear');
}
protected function getManagedLocales()
{
return $this->container->getParameter('lexik_translation.managed_locales');
}
private function getEntityManager()
{
return $this->get('doctrine.orm.default_entity_manager');
}
private function clearCache()
{
$this->get('translator')->removeLocalesCacheFiles($this->getManagedLocales());
}
}