src/Daikin/BaseBundle/Controller/DefaultController.php line 155

Open in your IDE?
  1. <?php
  2. namespace App\Daikin\BaseBundle\Controller;
  3. use App\Daikin\BaseBundle\Entity\Company;
  4. use App\Daikin\BaseBundle\Entity\Staticpages;
  5. use App\Service\Security\UserCredentialsService;
  6. use Symfony\Component\Routing\Annotation\Route;
  7. use Symfony\Component\HttpFoundation\Response;
  8. use Symfony\Component\HttpFoundation\Request;
  9. use App\Daikin\BaseBundle\Entity\User;
  10. use App\Daikin\BaseBundle\Entity\Logs;
  11. use Symfony\Component\HttpFoundation\RedirectResponse;
  12. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  13. use App\Daikin\BaseBundle\Form\UserType;
  14. use App\Daikin\BaseBundle\Form\CompanyAdminType;
  15. class DefaultController extends AbstractDaikinBaseController
  16. {
  17.     /**
  18.      * IndexAction
  19.      *
  20.      * @Route("/", name="homepage")
  21.      */
  22.      public function indexAction()
  23.      {
  24.          $this->init();
  25.          //Company Administrator
  26.          if ($this->authChecker->isGranted('ROLE_ADMIN_COMPANY')) {
  27.              return $this->redirect($this->generateUrl('frontend_home'));
  28.          }
  29.          // Stadtbote Eingangsverwaltung Administrator
  30.          if ($this->authChecker->isGranted('ROLE_SPARE_PARTS_WAREHOUSE')) {
  31.              return $this->redirect($this->generateUrl('spare_parts_warehouse_admin'));
  32.          }
  33.          //Editor
  34.          if ($this->authChecker->isGranted('ROLE_EDITOR')) {
  35. //             return $this->redirect($this->generateUrl('editor_home'));
  36.              return $this->redirect($this->generateUrl('frontend_home'));
  37.          }
  38.          //Admin
  39.          if ($this->authChecker->isGranted('ROLE_ADMIN')) {
  40. //             return $this->redirect($this->generateUrl('admin_home'));
  41.              return $this->redirect($this->generateUrl('frontend_home'));
  42.          }
  43.          if ($this->authChecker->isGranted('ROLE_HELPDESK_READER') &&
  44.              !$this->authChecker->isGranted('ROLE_HELPDESK_WRITER') &&
  45.              !$this->authChecker->isGranted('ROLE_APP_USER')) {
  46.              return $this->redirect($this->generateUrl('frontend_home'));
  47.          }
  48.          // Stadtbote Eingangsverwaltung Administrator
  49.          if ($this->authChecker->isGranted('ROLE_SPARE_PARTS_FOR_CUSTOMER_ORDER')) {
  50.              return $this->redirect($this->generateUrl('spare_part_order_new'));
  51.          }
  52.          if ($this->authChecker->isGranted('ROLE_APP_USER')) {
  53.              return $this->redirect($this->generateUrl('frontend_home'));
  54.          }
  55.          return $this->render('@DaikinBase/default/index.html.twig');
  56.      }
  57.     /**
  58.      * Myprofile
  59.      *
  60.      * @Route("/my_profile", name="_my_profile")
  61.      * @param Request $request
  62.      * @param UserCredentialsService $credentialsService
  63.      * @return array|RedirectResponse
  64.      * @Template()
  65.      */
  66.      public function myProfileAction(Request $requestUserCredentialsService $credentialsService)
  67.      {
  68.          $user $this->em->getRepository(User::class)
  69.              ->find($this->getUser()->getId());
  70.          $form $this->createForm(UserType::class, $user, [
  71.              'change_password' => true,
  72.          ]);
  73.          $form->handleRequest($request);
  74.          if ($form->isSubmitted() && $form->isValid()) {
  75.              if ($user->getPPassword()) {
  76.                  $credentialsService->updatePasswordForUser($user$user->getPPassword());
  77.              }
  78.              
  79.              $logs = new Logs($user->getId(), 'User''Update profile information.');
  80.              $this->em->persist($logs);
  81.              $this->em->persist($user);
  82.              $this->em->flush();
  83.              $this->addFlashMessage('Profile successfully changed!');
  84.              return $this->redirectToRoute('homepage');
  85.          }
  86.          if ($request->getMethod() == 'POST') {
  87.              $this->addFlashMessage('Profile was not changed!');
  88.          }
  89.          return [
  90.              'form'=>$form->createView(),
  91.              'user' => $user
  92.          ];
  93.      }
  94.     /**
  95.      * Company profile
  96.      *
  97.      * @Route("/my_company", name="_my_company")
  98.      * @Template()
  99.      * @param Request $request
  100.      * @return array|RedirectResponse
  101.      */
  102.      public function myCompanyAction(Request $request)
  103.      {
  104.          $user $this->getUser();
  105.          /** @var Company $company */
  106.          $company $user->getCompany();
  107.          $company->setAddMissingPlusPhone(false);
  108.          $form $this->createForm(CompanyAdminType::class, $company);
  109.          $form->handleRequest($request);
  110.          $may_edit false;
  111.          if ($user->hasRole(array( 'ROLE_ADMIN''ROLE_ADMIN_COMPANY'))) {
  112.              if ($form->isSubmitted() && $form->isValid()) {
  113.                  $log = new Logs($user->getId(),'Company','Update company information.');
  114.                  $this->em->persist$log );
  115.                  $this->em->persist$form->getData() );
  116.                  $this->em->flush();
  117.                  $this->addFlashMessage('Company information updated.');
  118.                  return $this->redirect($this->generateUrl('_my_company'));
  119.              }
  120.             $may_edit true;
  121.          }
  122.          return [
  123.              'form' => $form->createView(),
  124.              'company' => $company,
  125.              'may_edit' => $may_edit,
  126.          ];
  127.      }
  128.      public function pagesmenuAction(Request $request$v2 false): Response
  129.      {
  130.           $locale $request->getLocale() ?: 'en';
  131.           $pg $this->em->getRepository(Staticpages::class)->findBy([
  132.               'lang' => $locale,
  133.               'showInFooterMenu' => true
  134.           ]);
  135.           return $this->render('@DaikinBase/default/pagesmenu.html.twig', ['page' => $pg'v2' => $v2]);
  136.      }
  137.     /**
  138.      * @Route("/page/{alias}", name="staticpages")
  139.      * @param Request $request
  140.      * @param $alias
  141.      * @return array
  142.      * @Template()
  143.      */
  144.      public function staticpagesAction(Request $request$alias)
  145.      {
  146.          $locale $request->getLocale() ?: 'en';
  147.          /** @var Staticpages $pg */
  148.          $pg $this->em->getRepository(Staticpages::class)->findOneBy(['alias'=>$alias,'lang'=>$locale]);
  149.          if ($pg instanceof Staticpages) {
  150.              if ($pg->isShowDescriptionOnly()) {
  151.                  die($pg->getDescription());
  152.              }
  153.          } else {
  154.              $pg = array(
  155.                  'name' => 'No page',
  156.                  'description' => 'Page not found.'
  157.              );
  158.          }
  159.          return [
  160.              'page' => $pg,
  161.          ];
  162.      }
  163. }