src/Controller/Frontend/MainController.php line 114

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.         $blogs         $this->getDoctrine()->getRepository(\App\Entity\Blog::class)->findBy(array('is_active' => 1'is_published' => 1'featured'=> 1'Client' => $client));
  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.             'blogs'         => $blogs,
  71.             'slug'          => $slug,
  72.             'chatWidget'    => $client->getChatWidget()
  73.         ));
  74.     }
  75.     
  76.     
  77.     
  78.     public function chatWidgetAction(Request $request)
  79.     {
  80.         $client_id $this->getParameter('client_id');    
  81.         $settings $this->getDoctrine()->getRepository(\App\Entity\Client::class)->findOneBy(array("clientId" => $client_id ));            
  82.     
  83.         return $this->render('Frontend/chat_widget.html.twig', array(
  84.             'clientObj' => $settings
  85.         ));
  86.         
  87.     }
  88.     public function titleAction(Request $request)
  89.     {
  90.     $client_id $this->getParameter('client_id');        
  91.         $settings $this->getDoctrine()->getRepository(\App\Entity\Client::class)->findOneBy(array("clientId" => $client_id ));            
  92.     
  93.         return $this->render('Frontend/_load_title.html.twig', array(
  94.             'clientObj' => $settings
  95.         ));
  96.         
  97.     }
  98.     
  99.     
  100.     
  101.     
  102.     public function whatsappWidgetAction(Request $request)
  103.     {
  104.     $client_id $this->getParameter('client_id');       
  105.     $settings $this->getDoctrine()->getRepository(\App\Entity\Client::class)->findOneBy(array("clientId" => $client_id ));            
  106.     
  107.         return $this->render('Frontend/whatsapp_widget.html.twig', array(
  108.             'clientObj' => $settings
  109.         ));
  110.         
  111.     }    
  112.     
  113.     
  114.     
  115.         
  116.         
  117.     public function customStylesAction(Request $request)
  118.     {
  119.                 
  120.         $userData $this->get("session")->get("userData");
  121.         $client_id $this->getParameter('client_id');
  122.         $settings $this->getDoctrine()->getRepository(\App\Entity\WebSetting::class)->findOneBy(array("Client" => $client_id ));            
  123.         $mainColorRgba $this->hex2rgba($settings->getMainColor(),'0.8');
  124.         
  125.         return $this->render('Frontend/custom_style.html.twig', array(
  126.             "userData" => $userData,
  127.             'settings' => $settings,
  128.             'mainColorRgba' => $mainColorRgba
  129.         ));
  130.         
  131.     }    
  132.     
  133.     
  134.     public function hex2rgba($color$opacity false)
  135.     {
  136.      
  137.         $default 'rgb(0,0,0)';
  138.      
  139.         //Return default if no color provided
  140.         if(empty($color))
  141.               return $default
  142.      
  143.         //Sanitize $color if "#" is provided 
  144.             if ($color[0] == '#' ) {
  145.                 $color substr$color);
  146.             }
  147.      
  148.             //Check if color has 6 or 3 characters and get values
  149.             if (strlen($color) == 6) {
  150.                     $hex = array( $color[0] . $color[1], $color[2] . $color[3], $color[4] . $color[5] );
  151.             } elseif ( strlen$color ) == ) {
  152.                     $hex = array( $color[0] . $color[0], $color[1] . $color[1], $color[2] . $color[2] );
  153.             } else {
  154.                     return $default;
  155.             }
  156.      
  157.             //Convert hexadec to rgb
  158.             $rgb =  array_map('hexdec'$hex);
  159.      
  160.             //Check if opacity is set(rgba or rgb)
  161.             if($opacity){
  162.                 if(abs($opacity) > 1)
  163.                     $opacity 1.0;
  164.                 $output 'rgba('.implode(",",$rgb).','.$opacity.')';
  165.             } else {
  166.                 $output 'rgb('.implode(",",$rgb).')';
  167.             }
  168.      
  169.             //Return rgb(a) color string
  170.             return $output;
  171.     }    
  172.     
  173.     
  174.    
  175. }