<?php
namespace App\Controller\Frontend;
use App\Entity\File;
use App\Entity\Section;
use App\Entity\User;
use App\Service\TextHelper;
use App\Service\UrlHelper;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
use Knp\Component\Pager\PaginatorInterface;
class HomeController extends AbstractController
{
public function __construct()
{
// echo 'We can use __contruct<br />';
}
// /**
// * @Route("/private_area/home", name="home")
// */
// public function index(Request $request, TextHelper $textHelper, UrlHelper $urlHelper, PaginatorInterface $paginator)
// {
// $oneSection = $this->getDoctrine()->getRepository(Section::Class)->findOneBy(['code' => 'home']);
// $text = ($textHelper->getBySection($oneSection)) ? $textHelper->getBySection($oneSection) : [];
// $company = $this->getDoctrine()->getRepository(User::Class)->findOneBy(['id' => 2]);
// // $company = $this->getDoctrine()->getRepository(User::Class)->findOneBy(['id' => $this->getUser()]);
// $lastImport = $this->getDoctrine()->getRepository(Import::Class)->findOneBy(['owner' => $company->getId()], ['date_created'=> 'DESC']);
// $calls = $this->getCalls(0, 10);
// $paginatedEvents = $paginator->paginate(
// // Doctrine Query, not results
// $calls,
// // Define the page parameter
// $request->query->getInt('page', 1),
// // Items per page
// 5
// );
// // $this->insertShipmentFormData($object, $repository, $form, $lang, $em, $errorHandler);
// return $this->render('Frontend/home/home.html.twig', []);
// }
/**
* @Route("/private_area/search/single_company/{id}", name="single_company_frontend")
*/
public function single_company($id, Request $request, TextHelper $textHelper, UrlHelper $urlHelper)
{
$oneSection = $this->getDoctrine()->getRepository(Section::Class)->findOneBy(['code' => 'home']);
$text = ($textHelper->getBySection($oneSection)) ? $textHelper->getBySection($oneSection) : [];
$record = $this->getDoctrine()->getRepository(User::Class)->findOneById($id);
$recordAdFiles['company'] = $record;
$image = $this->getDoctrine()->getRepository(File::class)->findOneBy(['itemId' => $record->getId(), 'section' => 'news', 'type' => 'mainImage']);
$recordAdFiles['mainImage'] = ($image) ? $urlHelper->createImageUrl('mainImage', $record->getId(), 'resized', $image->getId(), 'backendGallery', $image->getExtension()) : null;
return $this->render('Frontend/home/home.html.twig', ['form' => $form->createView(), 'records' => $companies]);
}
/**
* @Route("/ajax/search_region", name="search_region")
*/
public function getRegionByCountry(Request $request, TextHelper $textHelper, UrlHelper $urlHelper)
{
$countryId = $request->request->get('countryId');
$country = $this->getDoctrine()->getRepository(Country::Class)->findOneById($countryId);
$regionsArray = [];
if ($country) {
foreach ($country->getRegions() as $key => $region) {
$regionsArray[$key]['id'] = $region->getId();
$regionsArray[$key]['title'] = $region->getTitle();
}
}
echo(json_encode($regionsArray));
die;
}
/**
* @Route("/ajax/search_city", name="search_city")
*/
public function getCityByRegion(Request $request, TextHelper $textHelper, UrlHelper $urlHelper)
{
$countryId = $request->request->get('regionId');
$country = $this->getDoctrine()->getRepository(Region::Class)->findOneById($countryId);
$regionsArray = [];
if ($country) {
foreach ($country->getCities() as $key => $region) {
$regionsArray[$key]['id'] = $region->getId();
$regionsArray[$key]['title'] = $region->getTitle();
}
}
echo(json_encode($regionsArray));
die;
}
/**
* @Route("/", name="home3")
*/
public function indexempty()
{
return $this->redirectToRoute('login');
}
}