<?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']);
}
return $this->render('ecom/index.html.twig', array('brands'=> $brands));
}
/**
* @Route("/selectcity/{city}", name="sajong_ecom_city_select")
*/
public function selectcity(Request $request, $city)
{
$em = $this->getDoctrine()->getManager();
$session = $request->getSession();
$session->set('mycity', $city);
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('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]);
return $this->render('ecom/brandcategories.html.twig', array('categories'=> $brandid));
}
/**
* @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 token is expired. Please try again.');
}
return $this->redirect($this->generateUrl('sajong_ecom_contact'));
}
/**
* @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);
}
}