src/Cms/TenantBundle/Controller/Dashboard/SettingsController.php line 50

Open in your IDE?
  1. <?php
  2. namespace Cms\TenantBundle\Controller\Dashboard;
  3. use Cms\ContentBundle\Entity\ContentVariables;
  4. use Cms\ContentBundle\Service\ContentVariablesManager;
  5. use Cms\CoreBundle\Form\Type\LocaleSettingsType;
  6. use Cms\CoreBundle\Model\Scenes\DashboardScenes\DocumentScene;
  7. use Cms\CoreBundle\Util\Controller;
  8. use Cms\CoreBundle\Entity\LocaleSettings;
  9. use Cms\TenantBundle\Form\Type\ContentVariablesType;
  10. use Symfony\Component\Routing\Annotation\Route;
  11. use Symfony\Component\HttpFoundation\RedirectResponse;
  12. /**
  13.  * Class SettingsController
  14.  * @package Cms\TenantBundle\Controller\Dashboard
  15.  */
  16. final class SettingsController extends Controller
  17. {
  18.     const ROUTES__MAIN 'cms.tenant.dashboard.settings.main';
  19.     const ROUTES__LOCALE 'cms.tenant.dashboard.settings.locale';
  20.     const ROUTES__CONTENT_VARIABLES 'cms.tenant.dashboard.settings.content_variables';
  21.     /**
  22.      * @return RedirectResponse
  23.      *
  24.      * @Route(
  25.      *     "",
  26.      *     name = SettingsController::ROUTES__MAIN
  27.      * )
  28.      */
  29.     public function mainAction()
  30.     {
  31.         // AUDIT
  32.         $this->denyAccessUnlessGranted('campussuite.cms.tenant.manage');
  33.         return $this->redirectToRoute(self::ROUTES__LOCALE);
  34.     }
  35.     /**
  36.      * @return DocumentScene|RedirectResponse
  37.      * @throws \Exception
  38.      *
  39.      * @Route(
  40.      *     "/locale",
  41.      *     name = SettingsController::ROUTES__LOCALE
  42.      * )
  43.      */
  44.     public function localeAction()
  45.     {
  46.         // AUDIT
  47.         $this->denyAccessUnlessGranted('campussuite.cms.tenant.manage');
  48.         $tenant $this->getGlobalContext()->getTenant();
  49.         $form $this->createForm(
  50.             LocaleSettingsType::class,
  51.             $tenant->getLocale(),
  52.             []
  53.         );
  54.         if ($this->handleForm($form)) {
  55.             /** @var LocaleSettings $locale */
  56.             $locale $form->getData();
  57.             $tenant->setLocale($locale);
  58.             // save to db
  59.             $this->getEntityManager()->save($tenant);
  60.             // record log
  61.             $this->getActivityLogger()->createLog($tenant);
  62.             $this->getSession()->getFlashBag()->add('success''Tenant locale updated successfully.');
  63.             return $this->redirectToRoute(self::ROUTES__LOCALE);
  64.         }
  65.         return $this->view(
  66.             array(
  67.                 'form' => $form->createView(),
  68.             )
  69.         );
  70.     }
  71.     /**
  72.      * @return DocumentScene|RedirectResponse
  73.      * @throws \Exception
  74.      *
  75.      * @Route(
  76.      *     "/content-variables",
  77.      *     name = SettingsController::ROUTES__CONTENT_VARIABLES
  78.      * )
  79.      */
  80.     public function contentVariablesAction()
  81.     {
  82.         // AUDIT
  83.         $this->denyAccessUnlessGranted('campussuite.cms.tenant.manage');
  84.         // get our tenant
  85.         $tenant $this->getGlobalContext()->getTenant();
  86.         // load up our variables
  87.         $variables $this->getContentVariablesManager()->loadForTenant($tenant);
  88.         if (empty($variables)) {
  89.             $variables = (new ContentVariables())
  90.                 ->setData(array());
  91.         }
  92.         // create our form
  93.         $form $this->createForm(
  94.             ContentVariablesType::class,
  95.             $variables,
  96.             []
  97.         );
  98.         // handle submission
  99.         if ($this->handleForm($form)) {
  100.             // save the updated variables
  101.             $this->getContentVariablesManager()->storeForTenant($tenant$variables->getData());
  102.             // record log
  103.             $this->getActivityLogger()->createLog($tenant);
  104.             $this->getSession()->getFlashBag()->add('success''Content variables updated successfully.');
  105.             return $this->redirectToRoute(self::ROUTES__CONTENT_VARIABLES);
  106.         }
  107.         return $this->view(
  108.             array(
  109.                 'form' => $form->createView(),
  110.             )
  111.         );
  112.     }
  113.     /**
  114.      * @return ContentVariablesManager|object
  115.      */
  116.     private function getContentVariablesManager(): ContentVariablesManager
  117.     {
  118.         return $this->get(__METHOD__);
  119.     }
  120. }