<?php
namespace Cms\TenantBundle\Controller\Dashboard;
use Cms\ContentBundle\Entity\ContentVariables;
use Cms\ContentBundle\Service\ContentVariablesManager;
use Cms\CoreBundle\Form\Type\LocaleSettingsType;
use Cms\CoreBundle\Model\Scenes\DashboardScenes\DocumentScene;
use Cms\CoreBundle\Util\Controller;
use Cms\CoreBundle\Entity\LocaleSettings;
use Cms\TenantBundle\Form\Type\ContentVariablesType;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\HttpFoundation\RedirectResponse;
/**
* Class SettingsController
* @package Cms\TenantBundle\Controller\Dashboard
*/
final class SettingsController extends Controller
{
const ROUTES__MAIN = 'cms.tenant.dashboard.settings.main';
const ROUTES__LOCALE = 'cms.tenant.dashboard.settings.locale';
const ROUTES__CONTENT_VARIABLES = 'cms.tenant.dashboard.settings.content_variables';
/**
* @return RedirectResponse
*
* @Route(
* "",
* name = SettingsController::ROUTES__MAIN
* )
*/
public function mainAction()
{
// AUDIT
$this->denyAccessUnlessGranted('campussuite.cms.tenant.manage');
return $this->redirectToRoute(self::ROUTES__LOCALE);
}
/**
* @return DocumentScene|RedirectResponse
* @throws \Exception
*
* @Route(
* "/locale",
* name = SettingsController::ROUTES__LOCALE
* )
*/
public function localeAction()
{
// AUDIT
$this->denyAccessUnlessGranted('campussuite.cms.tenant.manage');
$tenant = $this->getGlobalContext()->getTenant();
$form = $this->createForm(
LocaleSettingsType::class,
$tenant->getLocale(),
[]
);
if ($this->handleForm($form)) {
/** @var LocaleSettings $locale */
$locale = $form->getData();
$tenant->setLocale($locale);
// save to db
$this->getEntityManager()->save($tenant);
// record log
$this->getActivityLogger()->createLog($tenant);
$this->getSession()->getFlashBag()->add('success', 'Tenant locale updated successfully.');
return $this->redirectToRoute(self::ROUTES__LOCALE);
}
return $this->view(
array(
'form' => $form->createView(),
)
);
}
/**
* @return DocumentScene|RedirectResponse
* @throws \Exception
*
* @Route(
* "/content-variables",
* name = SettingsController::ROUTES__CONTENT_VARIABLES
* )
*/
public function contentVariablesAction()
{
// AUDIT
$this->denyAccessUnlessGranted('campussuite.cms.tenant.manage');
// get our tenant
$tenant = $this->getGlobalContext()->getTenant();
// load up our variables
$variables = $this->getContentVariablesManager()->loadForTenant($tenant);
if (empty($variables)) {
$variables = (new ContentVariables())
->setData(array());
}
// create our form
$form = $this->createForm(
ContentVariablesType::class,
$variables,
[]
);
// handle submission
if ($this->handleForm($form)) {
// save the updated variables
$this->getContentVariablesManager()->storeForTenant($tenant, $variables->getData());
// record log
$this->getActivityLogger()->createLog($tenant);
$this->getSession()->getFlashBag()->add('success', 'Content variables updated successfully.');
return $this->redirectToRoute(self::ROUTES__CONTENT_VARIABLES);
}
return $this->view(
array(
'form' => $form->createView(),
)
);
}
/**
* @return ContentVariablesManager|object
*/
private function getContentVariablesManager(): ContentVariablesManager
{
return $this->get(__METHOD__);
}
}