src/Controller/NobleController.php line 24

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  4. use Symfony\Component\HttpFoundation\Response;
  5. use Symfony\Component\HttpFoundation\Request;
  6. use Symfony\Component\HttpFoundation\JsonResponse;
  7. use Symfony\Component\Routing\Annotation\Route;
  8. use Symfony\Component\HttpFoundation\Session\Session;
  9. use App\Entity\Contact;
  10. use App\Entity\PushCause;
  11. class NobleController extends AbstractController
  12. {
  13.     /**
  14.      * @Route("/", name="sajong_ecom_index")
  15.      */
  16.     public function index(Request $request)
  17.     {
  18.         $em $this->getDoctrine()->getManager();
  19.         $session $request->getSession();
  20.         if(!empty($session->get('mycity'))) {
  21.           $city $em->getRepository('App\Entity\City')->findOneByName($session->get('mycity'));
  22.           $brands $em->getRepository('App\Entity\Brand')->findBy(['city'=>$city->getId(), 'status'=>1], ['access'=>'DESC']);
  23.         }
  24.         else {
  25.           $brands $em->getRepository('App\Entity\Brand')->findBy(['status'=>1], ['access'=>'DESC']);
  26.         }
  27.         $brandcities = array();
  28.         /*foreach($brands as $b) {
  29.           $brandcities[$b->getCity()] = $em->getRepository('App\Entity\City')->find($b->getCity());
  30.         }
  31.         print_r($brands);
  32.         print_r($brandcities); exit;*/
  33.         return $this->render('ecom/index.html.twig', array('brands'=> $brands'brandcities'=> $brandcities));
  34.     }
  35.     
  36.     /**
  37.      * @Route("/selectcity/{city}", name="sajong_ecom_city_select")
  38.      */
  39.     public function selectcity(Request $request$city)
  40.     {
  41.         $em $this->getDoctrine()->getManager();
  42.         $session $request->getSession();
  43.         $citydetails $em->getRepository('App\Entity\City')->find($city);
  44.         $session->set('mycity'$citydetails->getName());
  45.         return new JsonResponse(array('success'=>'City selected successfully'));
  46.     }
  47.     
  48.     /**
  49.      * @Route("/city/{city}", name="sajong_ecom_city_brands")
  50.      */
  51.     public function citybrands(Request $request$city)
  52.     {
  53.         $em $this->getDoctrine()->getManager();
  54.         $session $request->getSession();
  55.         $session->set('mycity'$city);
  56.         $city $em->getRepository('App\Entity\City')->findOneByName($session->get('mycity'));
  57.         $brands $em->getRepository('App\Entity\Brand')->findBy(['city'=>$city->getId(), 'status'=>1], ['access'=>'DESC']);
  58.         return $this->render('ecom/citybrands.html.twig', array('city'=> $city'brands'=> $brands));
  59.     }
  60.     
  61.     /**
  62.      * @Route("/citybrands", name="sajong_ecom_city_citybrands")
  63.      */
  64.     public function selcitybrands(Request $request)
  65.     {
  66.         $em $this->getDoctrine()->getManager();
  67.         $session $request->getSession();
  68.         if(empty($session->get('mycity'))) {
  69.           $session->set('mycity''Brooklyn');
  70.         }
  71.         $city $em->getRepository('App\Entity\City')->findOneByName($session->get('mycity'));
  72.         $brands $em->getRepository('App\Entity\Brand')->findBy(['city'=>$city->getId(), 'status'=>1], ['access'=>'DESC']);
  73.         return $this->render('ecom/citybrands.html.twig', array('city'=> $city'brands'=> $brands));
  74.     }
  75.     
  76.     /**
  77.      * @Route("/brand/{brand}", name="sajong_ecom_brand_categories")
  78.      */
  79.     public function brandcategories(Request $request$brand)
  80.     {
  81.         $em $this->getDoctrine()->getManager();
  82.         $session $request->getSession();
  83.         $brandid explode("_"$brand);
  84.         //$categories = $em->getRepository('App\Entity\Style')->findBy(['brand'=>$brandid[count($brandid)-1], 'status'=>1]);
  85.         $brand $em->getRepository('App\Entity\Brand')->find($brandid[count($brandid)-1]);
  86.         $categories $em->createQuery("SELECT DISTINCT s FROM App\Entity\BrandCategory bc, App\Entity\Style s WHERE bc.brand=:brand AND bc.category=s.id AND s.status=:status")->setParameters(['brand'=>$brandid[count($brandid)-1], 'status'=>])->getArrayResult();
  87.         return $this->render('ecom/brandcategories.html.twig', array('brand'=> $brand'categories'=> $categories));
  88.     }
  89.     
  90.     /**
  91.      * @Route("/about", name="sajong_ecom_about")
  92.      */
  93.     public function about()
  94.     {
  95.         return $this->render('ecom/about.html.twig');
  96.     }
  97.     
  98.     /**
  99.      * @Route("/faq", name="sajong_ecom_faq")
  100.      */
  101.     public function faq()
  102.     {
  103.         $em $this->getDoctrine()->getManager();
  104.         $faq_categories $em->getRepository('App\Entity\FaqCategory')->findByStatus(1);
  105.         $faq = array();
  106.         foreach ($faq_categories as $fc) {
  107.           $faq[$fc->getId()] = $em->getRepository('App\Entity\Faq')->findBy(['category'=>$fc->getId(), 'status'=>1]);
  108.         }
  109.         return $this->render('ecom/faq.html.twig', ['faq_categories'=>$faq_categories'faqs'=>$faq]);
  110.     }
  111.     
  112.     /**
  113.      * @Route("/blogs", name="sajong_ecom_blogs")
  114.      */
  115.     public function blogs()
  116.     {
  117.         return $this->render('ecom/blogs.html.twig');
  118.     }
  119.     
  120.     /**
  121.      * @Route("/contact", name="sajong_ecom_contact")
  122.      */
  123.     public function contact()
  124.     {
  125.         return $this->render('ecom/contact.html.twig');
  126.     }
  127.     
  128.     /**
  129.      * @Route("/nn/save/contact", name="sajong_ecom_save_contact")
  130.      */
  131.     public function savecontact(Request $request)
  132.     {
  133.       if($this->isCsrfTokenValid('contact_form'$request->get('form_token'))) {
  134.         $em $this->getDoctrine()->getManager();
  135.         $contact = new Contact();
  136.         $contact->setCreated(new \DateTime()); 
  137.         $this->addFlash('success''Thank you for contacting us. We will get in touch with you shortly.');
  138.         $contact->setName($request->get('name')); 
  139.         $contact->setEmail($request->get('email')); 
  140.         $contact->setPhone($request->get('phone')); 
  141.         $contact->setTitle($request->get('subject')); 
  142.         $contact->setDescription($request->get('description')); 
  143.         $contact->setNotes(''); 
  144.         $contact->setUid(0); 
  145.         $contact->setAttachments(''); 
  146.         $contact->setStage('Initiated'); 
  147.         $contact->setUpdated(new \DateTime()); 
  148.         $contact->setStatus(1); 
  149.         $em->persist($contact);
  150.         $em->flush();
  151.       }
  152.       else {
  153.         $this->addFlash('success''Your session is expired. Please try again.');
  154.       }
  155.       return $this->redirect($this->generateUrl('sajong_ecom_contact'));
  156.     }
  157.     
  158.     /**
  159.      * @Route("/designercollab", name="sajong_ecom_designer_collab")
  160.      */
  161.     public function designercollab()
  162.     {
  163.         return $this->render('ecom/designer_collab.html.twig', ['topics'=>array()]);
  164.     }
  165.     
  166.     /**
  167.      * @Route("/nn/save/designercollab", name="sajong_ecom_save_designercollab")
  168.      */
  169.     public function savedesignercollab(Request $request)
  170.     {
  171.       if($this->isCsrfTokenValid('contact_form'$request->get('form_token'))) {
  172.         $em $this->getDoctrine()->getManager();
  173.         
  174.         $body 'Here is my details </br> Full name: '.$request->get('name') .'<br/>Email: '.$request->get('email').'<br/>Telephone: '.$request->get('phone').'<br/><br/>More Details:'.$request->get('description');
  175.         $siteemail $em->getRepository('App\Entity\Content')->findOneByPath('site_mail');
  176.         $email = (new Email())
  177.                   ->from($request->get('email'))
  178.                   ->to($siteemail->getBody())
  179.                   ->subject($request->get('topic'))
  180.                   ->html($body);
  181.         $mailer->send($email);
  182.         $this->addFlash('success''Thanks, we will be in contact with more information soon.');
  183.         
  184.         /*$contact = new Contact();
  185.         $contact->setCreated(new \DateTime()); 
  186.         $this->addFlash('success', 'Thank you for contacting us. We will get in touch with you shortly.');
  187.         $contact->setName($request->get('name')); 
  188.         $contact->setEmail($request->get('email')); 
  189.         $contact->setPhone($request->get('phone')); 
  190.         $contact->setTitle($request->get('subject')); 
  191.         $contact->setDescription($request->get('description')); 
  192.         $contact->setNotes(''); 
  193.         $contact->setUid(0); 
  194.         $contact->setAttachments(''); 
  195.         $contact->setStage('Initiated'); 
  196.         $contact->setUpdated(new \DateTime()); 
  197.         $contact->setStatus(1); 
  198.         $em->persist($contact);
  199.         $em->flush();*/
  200.       }
  201.       else {
  202.         $this->addFlash('success''Your session is expired. Please try again.');
  203.       }
  204.       return $this->redirect($this->generateUrl('sajong_ecom_designer_collab'));
  205.     }
  206.     
  207.     /**
  208.      * @Route("/brandcollab", name="sajong_ecom_brand_collab")
  209.      */
  210.     public function brandcollab()
  211.     {
  212.         return $this->render('ecom/brand_collab.html.twig', ['topics'=>array()]);
  213.     }
  214.     
  215.     /**
  216.      * @Route("/nn/save/brandcollab", name="sajong_ecom_save_brandcollab")
  217.      */
  218.     public function savebrandcollab(Request $request)
  219.     {
  220.       if($this->isCsrfTokenValid('contact_form'$request->get('form_token'))) {
  221.         $em $this->getDoctrine()->getManager();
  222.         
  223.         $body 'Here is my details </br> Full name: '.$request->get('name') .'<br/>Email: '.$request->get('email').'<br/>Telephone: '.$request->get('phone').'<br/><br/>More Details:'.$request->get('description');
  224.         $siteemail $em->getRepository('App\Entity\Content')->findOneByPath('site_mail');
  225.         $email = (new Email())
  226.                   ->from($request->get('email'))
  227.                   ->to($siteemail->getBody())
  228.                   ->subject($request->get('topic'))
  229.                   ->html($body);
  230.         $mailer->send($email);
  231.         $this->addFlash('success''Thanks, we will be in contact with more information soon.');
  232.       }
  233.       else {
  234.         $this->addFlash('success''Your session is expired. Please try again.');
  235.       }
  236.       return $this->redirect($this->generateUrl('sajong_ecom_brand_collab'));
  237.     }
  238.     
  239.     /**
  240.      * @Route("/brandrequest", name="sajong_ecom_brand_request")
  241.      */
  242.     public function brandrequest()
  243.     {
  244.         return $this->render('ecom/brand_request.html.twig', ['topics'=>array()]);
  245.     }
  246.     
  247.     /**
  248.      * @Route("/nn/save/brandrequest", name="sajong_ecom_save_brandrequest")
  249.      */
  250.     public function savebrandrequest(Request $request)
  251.     {
  252.       if($this->isCsrfTokenValid('contact_form'$request->get('form_token'))) {
  253.         $em $this->getDoctrine()->getManager();
  254.         $body 'Here is my details </br> Full name: '.$request->get('name') .'<br/>Email: '.$request->get('email').'<br/>Telephone: '.$request->get('phone').'<br/>Brand Name: '.$request->get('brand').'<br/><br/>More Details:'.$request->get('description');
  255.         $siteemail $em->getRepository('App\Entity\Content')->findOneByPath('site_mail');
  256.         $email = (new Email())
  257.                   ->from($request->get('email'))
  258.                   ->to($siteemail->getBody())
  259.                   ->subject('Request for a new Brand: ' $request->get('brand'))
  260.                   ->html($body);
  261.         $mailer->send($email);
  262.         $this->addFlash('success''Thanks, we will be in contact with more information soon.');
  263.       }
  264.       else {
  265.         $this->addFlash('success''Your session is expired. Please try again.');
  266.       }
  267.       return $this->redirect($this->generateUrl('sajong_ecom_brand_request'));
  268.     }
  269.     
  270.     /**
  271.      * @Route("/admin/contacts", name="sajong_ecom_admin_contacts")
  272.      */
  273.     public function admincontacts()
  274.     {
  275.         return $this->render('admin/contacts.html.twig');
  276.     }
  277.     
  278.     /**
  279.      * @Route("/admin/nn/save/contact", name="sajong_ecom_admin_save_contact")
  280.      */
  281.     public function adminsavecontact(Request $request)
  282.     {
  283.         $em $this->getDoctrine()->getManager();
  284.         if(!empty($request->get('contactid'))) {
  285.             $contact $em->getRepository('App\Entity\Contact')->find($request->get('contactid'));
  286.             $this->addFlash('success''Contact updated successfully');
  287.         }
  288.         else {
  289.             $contact = new Contact();
  290.             $contact->setCreated(new \DateTime()); 
  291.             $this->addFlash('success''Contact added successfully');
  292.         }
  293.         $contact->setEmail($request->get('email')); 
  294.         $contact->setPhone($request->get('phone')); 
  295.         $contact->setTitle($request->get('title')); 
  296.         $contact->setDescription($request->get('description')); 
  297.         $contact->setNotes($request->get('notes')); 
  298.         $contact->setUid(0); 
  299.         $contact->setAttachments($request->get('attachments')); 
  300.         $contact->setStage($request->get('stage')); 
  301.         $contact->setUpdated(new \DateTime()); 
  302.         $contact->setStatus($request->get('status')); 
  303.         $em->persist($contact);
  304.         $em->flush();
  305.         return $this->redirect($this->generateUrl('sajong_ecom_list_contact'));
  306.     }
  307.     
  308.     /**
  309.      * @Route("/inquiry", name="sajong_ecom_inquiry")
  310.      */
  311.     public function inquiry()
  312.     {
  313.         return $this->render('ecom/inquiry.html.twig');
  314.     }
  315.     
  316.     /**
  317.      * @Route("/rules", name="sajong_ecom_rules")
  318.      */
  319.     public function rules()
  320.     {
  321.         return $this->render('ecom/rules.html.twig');
  322.     }
  323.     
  324.     /**
  325.      * @Route("/privacy", name="sajong_ecom_privacy")
  326.      */
  327.     public function privacy()
  328.     {
  329.         return $this->render('ecom/privacy.html.twig');
  330.     }
  331.     
  332.     /**
  333.      * @Route("/terms", name="sajong_ecom_terms")
  334.      */
  335.     public function terms()
  336.     {
  337.         return $this->render('ecom/terms.html.twig');
  338.     }
  339.     
  340.     /**
  341.      * @Route("/disclosure", name="sajong_ecom_disclosure")
  342.      */
  343.     public function disclosure()
  344.     {
  345.         return $this->render('ecom/disclosure.html.twig');
  346.     }
  347.     
  348.     /**
  349.      * @Route("/ajax/department/{institute}", name="sajong_ecom_ajax_department")
  350.      */
  351.     public function ajaxdepartment($institute)
  352.     {
  353.         $em $this->getDoctrine()->getManager();
  354.         $department $em->getRepository('App\Entity\Department')->findByInstituteId($institute);
  355.         $results = array();
  356.         foreach($department as $d) {
  357.             $results[] = array('label' => $d->getName(), 'value' => $d->getName(), 'id'=> $d->getId()); 
  358.         }
  359.         return new JsonResponse($results);
  360.     }
  361. }