src/Controller/Frontend/MainController.php line 34

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Frontend;
  3. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
  4. use Symfony\Bundle\FrameworkBundle\Controller\Controller;
  5. use Symfony\Component\HttpFoundation\Request;
  6. use Symfony\Component\HttpFoundation\JsonResponse;
  7. use Nzo\UrlEncryptorBundle\Annotations\ParamDecryptor;
  8. use Nzo\UrlEncryptorBundle\Annotations\ParamEncryptor;
  9. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  10. use Symfony\Component\Security\Core\Security;
  11. use App\Service\HelperService;
  12. use Symfony\Component\String\Slugger\SluggerInterface;
  13. use Nzo\UrlEncryptorBundle\Encryptor\Encryptor;
  14. use Symfony\Component\HttpFoundation\RequestStack;
  15. /**
  16.  * @Route("main")
  17.  */
  18. class MainController extends AbstractController
  19. {
  20.     private $requestStack;
  21.     public function __construct(RequestStack $requestStack)
  22.     {
  23.         $this->requestStack $requestStack;
  24.     }
  25.     
  26.     
  27.     public function mainMenuAction(Request $request)
  28.     {
  29.         
  30.         $lastUsername $request->getSession()->get(Security::LAST_USERNAME);        
  31.         if($lastUsername)
  32.         {
  33.             $customerData $request->getSession()->get($lastUsername);
  34.         } else {
  35.             $customerData "";
  36.         }
  37.         
  38.         
  39.         $masterRequest $this->requestStack->getMainRequest();         
  40.         $path $masterRequest->getPathInfo();  
  41.         $slugArray explode("/"$path);
  42.         $slug "";
  43.         if(count($slugArray) > 0)
  44.         {
  45.             $slug $slugArray[1];
  46.         }
  47.         
  48.         
  49.         $routeName  $request->attributes->get('_route');        
  50.         //$client_id  = $this->getParameter('client_id');
  51.         //$client     = $this->getDoctrine()->getRepository(\App\Entity\Client::class)->findOneBy(array("clientId" => $client_id ));        
  52.         $client     $this->getDoctrine()->getRepository(\App\Entity\Client::class)->findOneBy(["slug" => $slug]);        
  53.         
  54.         $settings   $this->getDoctrine()->getRepository(\App\Entity\WebSetting::class)->findOneBy(["Client" => $client ]);        
  55.         $categories $this->getDoctrine()->getRepository(\App\Entity\Category::class)->findBy([
  56.             "Client"        => $client
  57.             "is_active"     => 1
  58.             "featured_menu" => 1
  59.         ]);        
  60.         
  61.         $brands     $this->getDoctrine()->getRepository(\App\Entity\Brand::class)->findBrandsMenu($client->getClientId());        
  62.                 
  63.         return $this->render('Frontend/main_menu.html.twig', array(
  64.             'settings'      => $settings,
  65.             'brands'        => $brands,
  66.             'categories'    => $categories,
  67.             'routeName'     => $routeName,
  68.             'customerData'  => $customerData,
  69.             'client'        => $client,
  70.             'slug'          => $slug,
  71.             'chatWidget'    => $client->getChatWidget()
  72.         ));
  73.     }
  74.     
  75.     
  76.     
  77.     public function chatWidgetAction(Request $request)
  78.     {
  79.         $client_id $this->getParameter('client_id');    
  80.         $settings $this->getDoctrine()->getRepository(\App\Entity\Client::class)->findOneBy(array("clientId" => $client_id ));            
  81.     
  82.         return $this->render('Frontend/chat_widget.html.twig', array(
  83.             'clientObj' => $settings
  84.         ));
  85.         
  86.     }
  87.     public function titleAction(Request $request)
  88.     {
  89.     $client_id $this->getParameter('client_id');        
  90.         $settings $this->getDoctrine()->getRepository(\App\Entity\Client::class)->findOneBy(array("clientId" => $client_id ));            
  91.     
  92.         return $this->render('Frontend/_load_title.html.twig', array(
  93.             'clientObj' => $settings
  94.         ));
  95.         
  96.     }
  97.     
  98.     
  99.     
  100.     
  101.     public function whatsappWidgetAction(Request $request)
  102.     {
  103.     $client_id $this->getParameter('client_id');       
  104.     $settings $this->getDoctrine()->getRepository(\App\Entity\Client::class)->findOneBy(array("clientId" => $client_id ));            
  105.     
  106.         return $this->render('Frontend/whatsapp_widget.html.twig', array(
  107.             'clientObj' => $settings
  108.         ));
  109.         
  110.     }    
  111.     
  112.     
  113.     
  114.         
  115.         
  116.     public function customStylesAction(Request $request)
  117.     {
  118.                 
  119.         $userData $this->get("session")->get("userData");
  120.         $client_id $this->getParameter('client_id');
  121.         $settings $this->getDoctrine()->getRepository(\App\Entity\WebSetting::class)->findOneBy(array("Client" => $client_id ));            
  122.         $mainColorRgba $this->hex2rgba($settings->getMainColor(),'0.8');
  123.         
  124.         return $this->render('Frontend/custom_style.html.twig', array(
  125.             "userData" => $userData,
  126.             'settings' => $settings,
  127.             'mainColorRgba' => $mainColorRgba
  128.         ));
  129.         
  130.     }    
  131.     
  132.     
  133.     public function hex2rgba($color$opacity false)
  134.     {
  135.      
  136.         $default 'rgb(0,0,0)';
  137.      
  138.         //Return default if no color provided
  139.         if(empty($color))
  140.               return $default
  141.      
  142.         //Sanitize $color if "#" is provided 
  143.             if ($color[0] == '#' ) {
  144.                 $color substr$color);
  145.             }
  146.      
  147.             //Check if color has 6 or 3 characters and get values
  148.             if (strlen($color) == 6) {
  149.                     $hex = array( $color[0] . $color[1], $color[2] . $color[3], $color[4] . $color[5] );
  150.             } elseif ( strlen$color ) == ) {
  151.                     $hex = array( $color[0] . $color[0], $color[1] . $color[1], $color[2] . $color[2] );
  152.             } else {
  153.                     return $default;
  154.             }
  155.      
  156.             //Convert hexadec to rgb
  157.             $rgb =  array_map('hexdec'$hex);
  158.      
  159.             //Check if opacity is set(rgba or rgb)
  160.             if($opacity){
  161.                 if(abs($opacity) > 1)
  162.                     $opacity 1.0;
  163.                 $output 'rgba('.implode(",",$rgb).','.$opacity.')';
  164.             } else {
  165.                 $output 'rgb('.implode(",",$rgb).')';
  166.             }
  167.      
  168.             //Return rgb(a) color string
  169.             return $output;
  170.     }    
  171.     
  172.     
  173.    
  174. }