<?php
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\HttpFoundation\Session\Session;
use App\Entity\Contact;
use App\Entity\PushCause;
class NobleController extends AbstractController
{
/**
* @Route("/", name="sajong_ecom_index")
*/
public function index(Request $request)
{
$em = $this->getDoctrine()->getManager();
$session = $request->getSession();
if(!empty($session->get('mycity'))) {
$city = $em->getRepository('App\Entity\City')->findOneByName($session->get('mycity'));
$brands = $em->getRepository('App\Entity\Brand')->findBy(['city'=>$city->getId(), 'status'=>1], ['access'=>'DESC']);
}
else {
$brands = $em->getRepository('App\Entity\Brand')->findBy(['status'=>1], ['access'=>'DESC']);
}
$brandcities = array();
/*foreach($brands as $b) {
$brandcities[$b->getCity()] = $em->getRepository('App\Entity\City')->find($b->getCity());
}
print_r($brands);
print_r($brandcities); exit;*/
return $this->render('ecom/index.html.twig', array('brands'=> $brands, 'brandcities'=> $brandcities));
}
/**
* @Route("/selectcity/{city}", name="sajong_ecom_city_select")
*/
public function selectcity(Request $request, $city)
{
$em = $this->getDoctrine()->getManager();
$session = $request->getSession();
$citydetails = $em->getRepository('App\Entity\City')->find($city);
$session->set('mycity', $citydetails->getName());
return new JsonResponse(array('success'=>'City selected successfully'));
}
/**
* @Route("/city/{city}", name="sajong_ecom_city_brands")
*/
public function citybrands(Request $request, $city)
{
$em = $this->getDoctrine()->getManager();
$session = $request->getSession();
$session->set('mycity', $city);
$city = $em->getRepository('App\Entity\City')->findOneByName($session->get('mycity'));
$brands = $em->getRepository('App\Entity\Brand')->findBy(['city'=>$city->getId(), 'status'=>1], ['access'=>'DESC']);
return $this->render('ecom/citybrands.html.twig', array('city'=> $city, 'brands'=> $brands));
}
/**
* @Route("/citybrands", name="sajong_ecom_city_citybrands")
*/
public function selcitybrands(Request $request)
{
$em = $this->getDoctrine()->getManager();
$session = $request->getSession();
if(empty($session->get('mycity'))) {
$session->set('mycity', 'Brooklyn');
}
$city = $em->getRepository('App\Entity\City')->findOneByName($session->get('mycity'));
$brands = $em->getRepository('App\Entity\Brand')->findBy(['city'=>$city->getId(), 'status'=>1], ['access'=>'DESC']);
return $this->render('ecom/citybrands.html.twig', array('city'=> $city, 'brands'=> $brands));
}
/**
* @Route("/brand/{brand}", name="sajong_ecom_brand_categories")
*/
public function brandcategories(Request $request, $brand)
{
$em = $this->getDoctrine()->getManager();
$session = $request->getSession();
$brandid = explode("_", $brand);
//$categories = $em->getRepository('App\Entity\Style')->findBy(['brand'=>$brandid[count($brandid)-1], 'status'=>1]);
$brand = $em->getRepository('App\Entity\Brand')->find($brandid[count($brandid)-1]);
$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'=>1 ])->getArrayResult();
return $this->render('ecom/brandcategories.html.twig', array('brand'=> $brand, 'categories'=> $categories));
}
/**
* @Route("/about", name="sajong_ecom_about")
*/
public function about()
{
return $this->render('ecom/about.html.twig');
}
/**
* @Route("/faq", name="sajong_ecom_faq")
*/
public function faq()
{
$em = $this->getDoctrine()->getManager();
$faq_categories = $em->getRepository('App\Entity\FaqCategory')->findByStatus(1);
$faq = array();
foreach ($faq_categories as $fc) {
$faq[$fc->getId()] = $em->getRepository('App\Entity\Faq')->findBy(['category'=>$fc->getId(), 'status'=>1]);
}
return $this->render('ecom/faq.html.twig', ['faq_categories'=>$faq_categories, 'faqs'=>$faq]);
}
/**
* @Route("/blogs", name="sajong_ecom_blogs")
*/
public function blogs()
{
return $this->render('ecom/blogs.html.twig');
}
/**
* @Route("/contact", name="sajong_ecom_contact")
*/
public function contact()
{
return $this->render('ecom/contact.html.twig');
}
/**
* @Route("/nn/save/contact", name="sajong_ecom_save_contact")
*/
public function savecontact(Request $request)
{
if($this->isCsrfTokenValid('contact_form', $request->get('form_token'))) {
$em = $this->getDoctrine()->getManager();
$contact = new Contact();
$contact->setCreated(new \DateTime());
$this->addFlash('success', 'Thank you for contacting us. We will get in touch with you shortly.');
$contact->setName($request->get('name'));
$contact->setEmail($request->get('email'));
$contact->setPhone($request->get('phone'));
$contact->setTitle($request->get('subject'));
$contact->setDescription($request->get('description'));
$contact->setNotes('');
$contact->setUid(0);
$contact->setAttachments('');
$contact->setStage('Initiated');
$contact->setUpdated(new \DateTime());
$contact->setStatus(1);
$em->persist($contact);
$em->flush();
}
else {
$this->addFlash('success', 'Your session is expired. Please try again.');
}
return $this->redirect($this->generateUrl('sajong_ecom_contact'));
}
/**
* @Route("/designercollab", name="sajong_ecom_designer_collab")
*/
public function designercollab()
{
return $this->render('ecom/designer_collab.html.twig', ['topics'=>array()]);
}
/**
* @Route("/nn/save/designercollab", name="sajong_ecom_save_designercollab")
*/
public function savedesignercollab(Request $request)
{
if($this->isCsrfTokenValid('contact_form', $request->get('form_token'))) {
$em = $this->getDoctrine()->getManager();
$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');
$siteemail = $em->getRepository('App\Entity\Content')->findOneByPath('site_mail');
$email = (new Email())
->from($request->get('email'))
->to($siteemail->getBody())
->subject($request->get('topic'))
->html($body);
$mailer->send($email);
$this->addFlash('success', 'Thanks, we will be in contact with more information soon.');
/*$contact = new Contact();
$contact->setCreated(new \DateTime());
$this->addFlash('success', 'Thank you for contacting us. We will get in touch with you shortly.');
$contact->setName($request->get('name'));
$contact->setEmail($request->get('email'));
$contact->setPhone($request->get('phone'));
$contact->setTitle($request->get('subject'));
$contact->setDescription($request->get('description'));
$contact->setNotes('');
$contact->setUid(0);
$contact->setAttachments('');
$contact->setStage('Initiated');
$contact->setUpdated(new \DateTime());
$contact->setStatus(1);
$em->persist($contact);
$em->flush();*/
}
else {
$this->addFlash('success', 'Your session is expired. Please try again.');
}
return $this->redirect($this->generateUrl('sajong_ecom_designer_collab'));
}
/**
* @Route("/brandcollab", name="sajong_ecom_brand_collab")
*/
public function brandcollab()
{
return $this->render('ecom/brand_collab.html.twig', ['topics'=>array()]);
}
/**
* @Route("/nn/save/brandcollab", name="sajong_ecom_save_brandcollab")
*/
public function savebrandcollab(Request $request)
{
if($this->isCsrfTokenValid('contact_form', $request->get('form_token'))) {
$em = $this->getDoctrine()->getManager();
$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');
$siteemail = $em->getRepository('App\Entity\Content')->findOneByPath('site_mail');
$email = (new Email())
->from($request->get('email'))
->to($siteemail->getBody())
->subject($request->get('topic'))
->html($body);
$mailer->send($email);
$this->addFlash('success', 'Thanks, we will be in contact with more information soon.');
}
else {
$this->addFlash('success', 'Your session is expired. Please try again.');
}
return $this->redirect($this->generateUrl('sajong_ecom_brand_collab'));
}
/**
* @Route("/brandrequest", name="sajong_ecom_brand_request")
*/
public function brandrequest()
{
return $this->render('ecom/brand_request.html.twig', ['topics'=>array()]);
}
/**
* @Route("/nn/save/brandrequest", name="sajong_ecom_save_brandrequest")
*/
public function savebrandrequest(Request $request)
{
if($this->isCsrfTokenValid('contact_form', $request->get('form_token'))) {
$em = $this->getDoctrine()->getManager();
$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');
$siteemail = $em->getRepository('App\Entity\Content')->findOneByPath('site_mail');
$email = (new Email())
->from($request->get('email'))
->to($siteemail->getBody())
->subject('Request for a new Brand: ' . $request->get('brand'))
->html($body);
$mailer->send($email);
$this->addFlash('success', 'Thanks, we will be in contact with more information soon.');
}
else {
$this->addFlash('success', 'Your session is expired. Please try again.');
}
return $this->redirect($this->generateUrl('sajong_ecom_brand_request'));
}
/**
* @Route("/admin/contacts", name="sajong_ecom_admin_contacts")
*/
public function admincontacts()
{
return $this->render('admin/contacts.html.twig');
}
/**
* @Route("/admin/nn/save/contact", name="sajong_ecom_admin_save_contact")
*/
public function adminsavecontact(Request $request)
{
$em = $this->getDoctrine()->getManager();
if(!empty($request->get('contactid'))) {
$contact = $em->getRepository('App\Entity\Contact')->find($request->get('contactid'));
$this->addFlash('success', 'Contact updated successfully');
}
else {
$contact = new Contact();
$contact->setCreated(new \DateTime());
$this->addFlash('success', 'Contact added successfully');
}
$contact->setEmail($request->get('email'));
$contact->setPhone($request->get('phone'));
$contact->setTitle($request->get('title'));
$contact->setDescription($request->get('description'));
$contact->setNotes($request->get('notes'));
$contact->setUid(0);
$contact->setAttachments($request->get('attachments'));
$contact->setStage($request->get('stage'));
$contact->setUpdated(new \DateTime());
$contact->setStatus($request->get('status'));
$em->persist($contact);
$em->flush();
return $this->redirect($this->generateUrl('sajong_ecom_list_contact'));
}
/**
* @Route("/inquiry", name="sajong_ecom_inquiry")
*/
public function inquiry()
{
return $this->render('ecom/inquiry.html.twig');
}
/**
* @Route("/rules", name="sajong_ecom_rules")
*/
public function rules()
{
return $this->render('ecom/rules.html.twig');
}
/**
* @Route("/privacy", name="sajong_ecom_privacy")
*/
public function privacy()
{
return $this->render('ecom/privacy.html.twig');
}
/**
* @Route("/terms", name="sajong_ecom_terms")
*/
public function terms()
{
return $this->render('ecom/terms.html.twig');
}
/**
* @Route("/disclosure", name="sajong_ecom_disclosure")
*/
public function disclosure()
{
return $this->render('ecom/disclosure.html.twig');
}
/**
* @Route("/ajax/department/{institute}", name="sajong_ecom_ajax_department")
*/
public function ajaxdepartment($institute)
{
$em = $this->getDoctrine()->getManager();
$department = $em->getRepository('App\Entity\Department')->findByInstituteId($institute);
$results = array();
foreach($department as $d) {
$results[] = array('label' => $d->getName(), 'value' => $d->getName(), 'id'=> $d->getId());
}
return new JsonResponse($results);
}
}