src/Controller/DefaultController.php line 14

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Symfony\Contracts\Translation\TranslatorInterface;
  4. use Pimcore\Controller\FrontendController;
  5. use Pimcore\Model\DataObject\Customer;
  6. use Pimcore\Model\DataObject\Faq\Listing;
  7. use Symfony\Component\Routing\Annotation\Route;
  8. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  9. use Symfony\Component\HttpFoundation\Request;
  10. use FrontendPermissionToolkitBundle\Service;
  11. class DefaultController extends FrontendController
  12. {
  13.     /** @var TranslatorInterface */
  14.     protected $translator;
  15.     /** 
  16.      * @var Service 
  17.      */
  18.     private $permissionService;
  19.     public function __construct(TranslatorInterface $translatorService $permissionService )
  20.     {
  21.         $this->translator $translator;
  22.         $this->permissionService $permissionService;
  23.     }
  24.     /**
  25.      * @Template
  26.      * 
  27.      * @Route("/", name="home")
  28.      * @param Request $request
  29.      *
  30.      * @return array
  31.      */
  32.     public function defaultAction(Request $request)
  33.     {
  34.         $params = [];
  35.         $user $this->getUser();
  36.         if(!$user){
  37.             return $this->redirectToRoute('account-login');
  38.         }
  39.         
  40.         $this->setUserParams($params);
  41.         return $params;
  42.     }
  43.     /**
  44.      * @Template
  45.      * @param Request $request
  46.      *
  47.      * @return array
  48.      */
  49.     public function faqAction(Request $request){
  50.         $params = [];
  51.         $user $this->getUser();
  52.         
  53.         if(!$user){
  54.             return $this->redirectToRoute('account-login');
  55.         }
  56.         
  57.         $this->setUserParams($params);
  58.         $faqList = new Listing();
  59.         $faqList->filterByEnabled("1");
  60.         $faqs $faqList->load();
  61.         if($faqs){
  62.             $params['faqs'] = $faqs;
  63.         } else{
  64.             $params['faqs'] = [];
  65.         }
  66.         return $params;
  67.     }
  68.     /**
  69.      * @param Request $request
  70.      * @return array
  71.      */
  72.     public function sentPublicationNewsletterEmailAction(Request $request){
  73.         $params = [
  74.             "customerName" => $request->get('customerName'),
  75.             "materials" => $request->get('materials'),
  76.         ];
  77.         return $this->render("default/publicationNewsletterEmail.html.twig"$params);
  78.     }
  79.     /**
  80.      * Undocumented function
  81.      *
  82.      * @param array $params
  83.      * @return void
  84.      */
  85.     protected function setUserParams(array &$params){
  86.         $user $this->getUser();
  87.         if ($user && $user  instanceof Customer) {
  88.             
  89.             $customerLanguages $user->getLanguages();
  90.             if($customerLanguages){
  91.                 $languages = [];
  92.                 foreach($customerLanguages as $customerLanguage){
  93.                     $language['code'] =  $customerLanguage;
  94.                     $language['lang'] =  locale_get_display_language($customerLanguage'en');
  95.                     array_push($languages,$language);
  96.                 }
  97.                 $params['customerLanguages'] = $languages;
  98.             }
  99.             $params['educationPageAllowed'] = false;
  100.             if($this->permissionService && $this->permissionService->isAllowed($user,"education")){
  101.                 $params['educationPageAllowed'] = true;
  102.             }
  103.             $params['everythingAllowed'] = false;
  104.             if($this->permissionService && $this->permissionService->isAllowed($user,"everything")){
  105.                 $params['everythingAllowed'] = true;
  106.             }
  107.             $params['previewAllowed'] = false;
  108.             if($this->permissionService && $this->permissionService->isAllowed($user,"preview")){
  109.                 $params['previewAllowed'] = true;
  110.             }
  111.             $params['openAssetAllowed'] = false;
  112.             if($this->permissionService && $this->permissionService->isAllowed($user,"openAssets")){
  113.                 $params['openAssetAllowed'] = true;
  114.             }
  115.             $userRole $user->getCustomerRole();
  116.             $params['includedBrands'] = $userRole->getIncludedBrands();
  117.             $params['excludedBrands'] = $userRole->getExcludedBrands();
  118.             $params['includedSublines'] = $userRole->getIncludedSublines();
  119.             $params['excludedSublines'] = $userRole->getExcludedSublines();
  120.             $params['logged'] = true;
  121.             $params['mail'] = $user->getEmail();
  122.         }else{
  123.             $params['logged'] = false;
  124.         }
  125.         return $params;
  126.     }
  127.     /**
  128.      * @Route("/confirm-registration/{guid}", methods={"GET"})
  129.      */
  130.     public function confirmRegistration(Request $request)
  131.     {
  132.         $guid $request->get('guid');
  133.         if (!(empty($guid))) {
  134.             $customer Customer::getByConfirmRegistrationToken($guid1);
  135.             if($customer){
  136.                 $customer->setActive(true);
  137.                 $customer->setConfirmRegistrationToken(null);
  138.                 $language "en";
  139.                 $languages $customer->getLanguages();
  140.                 $guid uuid_create();
  141.                 $customer->setPasswordRecoveryToken($guid);
  142.                 $customer->save();
  143.                 return $this->render('account/passwordRestore.html.twig', array(
  144.                     'errors' => [],
  145.                     'title' => $this->translator->trans("password_creation_title", [], 'messages'$language),
  146.                     'psw_criter_upper' => $this->translator->trans("error_password_uppercase", [], 'messages'$language),
  147.                     'psw_criter_lower' => $this->translator->trans("error_password_lowercase", [], 'messages'$language),
  148.                     'psw_criter_special' => $this->translator->trans("error_password_special", [], 'messages'$language),
  149.                     'psw_criter_twelve' => $this->translator->trans("error_password_number", [], 'messages'$language),
  150.                     'psw_criter_number' => $this->translator->trans("error_password_twelve", [], 'messages'$language),
  151.                     'locale' => $language,
  152.                     'guid' => $guid,
  153.                 ));
  154.             }else{
  155.                 return $this->redirectToRoute('account-login');
  156.             }
  157.             
  158.         } else {
  159.             return $this->redirectToRoute('home');
  160.         }
  161.     }
  162.     /**
  163.      * 
  164.      * @Route("/password-restore/{guid}", methods={"GET"})
  165.      *
  166.      * @param Request $request
  167.      * @return void
  168.      */
  169.     public function passwordRestoreAction(Request $requeststring $guid)
  170.     {
  171.         $customerByGuid Customer::getByPasswordRecoveryToken($guid1);
  172.         if(!$customerByGuid){
  173.             return $this->redirectToRoute('account-login');
  174.         }
  175.         $locale $this->document->getProperty("language");
  176.         if (($customerByGuid instanceof Customer)) {
  177.             $language "en";
  178.             return $this->render('account/passwordRestore.html.twig', array(
  179.                 'guid' => $guid,
  180.                 'psw_criter_upper' => $this->translator->trans("error_password_uppercase", [], 'messages'$language),
  181.                 'psw_criter_lower' => $this->translator->trans("error_password_lowercase", [], 'messages'$language),
  182.                 'psw_criter_special' => $this->translator->trans("error_password_special", [], 'messages'$language),
  183.                 'psw_criter_twelve' => $this->translator->trans("error_password_number", [], 'messages'$language),
  184.                 'psw_criter_number' => $this->translator->trans("error_password_twelve", [], 'messages'$language),
  185.                 'title' => $this->translator->trans("password_restore_title", [], 'messages'$language),
  186.                 'locale' => $locale
  187.             ));
  188.         } else {
  189.             return $this->redirectToRoute('home');
  190.         }
  191.         return $this->json(["success" => true]);
  192.     }
  193.     /**
  194.      * @Route("/password-recovery", methods={"GET"})
  195.      */
  196.     public function passwordRecoveryAction(Request $request)
  197.     {
  198.         return $this->render('account/passwordRecovery.html.twig', array('success' => """error" => "","locale"=>"en"));
  199.     }
  200. }