<?php
namespace Troika\RealEstateBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Troika\MainBundle\Command\GenerateShitFiltersCommand;
class DefaultController extends \Symfony\Bundle\FrameworkBundle\Controller\AbstractController
{
public function aboutAction()
{
$repository = $this->getDoctrine()->getRepository('TroikaMainBundle:About');
$about = $repository->find(1);
if (empty($about)) {
throw new NotFoundHttpException();
}
return $this->render('TroikaRealEstateBundle:About:about.html.twig', [
'title' => $about->getTitle(),
'description' => $about->getDescription(),
'keywords' => $about->getKeywords(),
'content1' => $about->getContent1(),
'content2' => $about->getContent2(),
'content3' => $about->getContent3(),
'content4' => $about->getContent4(),
'img1' => $about->getWebPathImg1(),
'img2' => $about->getWebPathImg2(),
'img3' => $about->getWebPathImg3(),
'img4' => $about->getWebPathImg4(),
]);
}
public function agreementAction()
{
$page = $this->getDoctrine()->getRepository('TroikaMainBundle:MainPage')->find(2);
return $this->render('TroikaRealEstateBundle:About:agreement.html.twig',['page'=>$page]);
}
public function analyticAction()
{
$page = $_GET['page'] ?? 1;
$analytics = $this->container->get('analytic.model')->getPage($page);
$em = $this->getDoctrine()->getEntityManager();
$connection = $em->getConnection();
$statement =
$connection->prepare("select left(date,4) as date,
count(*) from Analytic where published = 1 group by left(date,4) order by left(date,4) DESC");
$statement->execute();
$date = $statement->fetchAll();
$page = $this->getDoctrine()->getRepository('TroikaMainBundle:MainPage')->find(2);
return $this->render('TroikaRealEstateBundle:About:analytic.html.twig', ['analytics' => $analytics, 'year' => null, 'date' => $date, 'page' => $page]
);
}
public function analyticByYearAction($year)
{
$page = $_GET['page'] ?? 1;
$analytics = $this->container->get('analytic.model')->getPageByYear($page, $year);
$em = $this->getDoctrine()->getEntityManager();
$connection = $em->getConnection();
$statement =
$connection->prepare("select left(date,4) as date, count(*) from Analytic where published = 1
group by left(date,4) order by left(date,4) DESC");
$statement->execute();
$date = $statement->fetchAll();
$page = $this->getDoctrine()->getRepository('TroikaMainBundle:MainPage')->find(2);
return $this->render(
'TroikaRealEstateBundle:About:analytic.html.twig',
['analytics' => $analytics, 'year' => $year, 'date' => $date, 'page' => $page]
);
}
public function analyticItemAction($item)
{
$analytic = $this->container->get('analytic.model')->getSlug($item);
if (empty($analytic)) {
throw new NotFoundHttpException();
}
$em = $this->getDoctrine()->getEntityManager();
$connection = $em->getConnection();
$statement =
$connection->prepare("select left(date,4) as date,
count(*) from Analytic where published = 1 group by left(date,4) order by left(date,4) DESC");
$statement->execute();
$date = $statement->fetchAll();
$page = $this->getDoctrine()->getRepository('TroikaMainBundle:MainPage')->find(2);
return $this->render('TroikaRealEstateBundle:About:analytic_item.html.twig', ['analytic' => $analytic, 'date' => $date, 'page' => $page]);
}
public function contactsAction()
{
$contacts = $this->container->get('contact.model')->getAll();
$page = $this->getDoctrine()->getRepository('TroikaMainBundle:MainPage')->find(2);
return $this->render('TroikaRealEstateBundle:About:contacts.html.twig', ['contacts' => $contacts,'page'=>$page]);
}
public function faveAction()
{
$page = $this->getDoctrine()->getRepository('TroikaMainBundle:MainPage')->find(2);
return $this->render('TroikaRealEstateBundle:About:fave.html.twig', ['page'=>$page]);
}
public function faveListAction(Request $request)
{
$page = $this->getDoctrine()->getRepository('TroikaMainBundle:MainPage')->find(2);
$lots = $request->get('lots');
$lots = $this->container->get('lot.model')->getFave($lots);
return $this->render('TroikaRealEstateBundle:EstateList:fave.item.html.twig', ['lots' => $lots,'page'=>$page]);
}
public function indexAction(\Symfony\Component\HttpFoundation\Request $request)
{
$recent = $this->get('lot.model')->getRecent();
$items = $this->get('menuitem.model')->getActive();
$repository = $this->getDoctrine()->getRepository('TroikaMainBundle:Home');
$home = $repository->find(1);
$page = $this->getDoctrine()->getRepository('TroikaMainBundle:MainPage')->find(2);
$tagSlots = $this->getDoctrine()->getRepository('TroikaMainBundle:TagSlot')->findAll();
$types = $this->getDoctrine()->getRepository('TroikaMainBundle:TypeHouse')->findAll();
$districts = $this->get('district.model')->getInUseSale(1);
$settlements = $this->get('settlement.model')->getInUseSale(2);
$adistricts = $this->get('district.model')->getInUseRent(1);
$districts_com = $this->get('district.model')->getInUseSale(3);
$adistricts_com = $this->get('district.model')->getInUseRent(3);
$subways = $this->get('subway.model')->getInUseSale(3);
$translit = new GenerateShitFiltersCommand();
foreach ($subways as &$subway) {
$subway['enName'] = $translit->toAscii($translit->str2url($subway['name']));
}
foreach ($settlements as &$settlement) {
$settlement['enName'] = $translit->toAscii($translit->str2url($settlement['name']));
}
foreach ($districts as &$district) {
$district['enName'] = $translit->toAscii($translit->str2url($district['name']));
}
foreach ($districts_com as &$district_com) {
$district_com['enName'] = $translit->toAscii($translit->str2url($district_com['name']));
}
foreach ($adistricts as &$district) {
$district['enName'] = $translit->toAscii($translit->str2url($district['name']));
}
foreach ($adistricts_com as &$district_com) {
$district_com['enName'] = $translit->toAscii($translit->str2url($district_com['name']));
}
$highways = $this->get('highway.model')->getInUseSale(2);
$ahighways = $this->get('highway.model')->getInUseRent(2);
foreach ($highways as &$highway) {
$highway['enname'] = $translit->toAscii($translit->str2url($highway['name']));
}
foreach ($ahighways as &$highway) {
$highway['enname'] = $translit->toAscii($translit->str2url($highway['name']));
}
$countries = $this->get('country.model')->getInUseSale(4);
$acountries = $this->get('country.model')->getInUseRent(4);
foreach ($countries as &$country) {
$country['enname'] = $translit->toAscii($translit->str2url($country['name']));
}
foreach ($acountries as &$country) {
$country['enname'] = $translit->toAscii($translit->str2url($country['name']));
}
$blog = $this->getDoctrine()->getRepository('TroikaMainBundle:Blog')->findAll();
if ($page->getPromoType() == "filter") {
$filter = $page->filter->getAttributes();
if ($filter['price'] && $filter['price']['max']) {
$filter['price']['max'] = $this->get('troika_main.currency')->getDollars($filter['price']['max'] / 1000, 1);
}
if ($filter['price'] && $filter['price']['min']) {
$filter['price']['min'] = $this->get('troika_main.currency')->getDollars($filter['price']['min'] / 1000, 1);
}
$f_lots = $this->get('lot.model')->getByFilter($filter);
$page->filter->lots = $f_lots;
}
$r = $request;
$complexes = $this->get('lot.model')->getComplexesList($r);
$complexesAll = $this->getDoctrine()->getRepository('TroikaMainBundle:ComplexPage')->findBy([], ['name' => 'ASC']);
$districtsAll = $this->getDoctrine()->getRepository('TroikaMainBundle:Area2')->findAll();
$subwaysAll = $this->getDoctrine()->getRepository('TroikaMainBundle:Subway2')->findAll();
$districts_t = [];
$subways_t = [];
$cs = [];
$districtIds = [];
$subwayIds = [];
foreach ($complexesAll as $complex) {
$cs[] = $complex->getName();
if (!in_array($complex->getArea2()->getId(), $districtIds, true)) {
$districtIds[] = $complex->getArea2()->getId();
}
if (!in_array($complex->getSubway2()->getId(), $subwayIds, true)) {
$subwayIds[] = $complex->getSubway2()->getId();
}
}
foreach ($districtIds as $id) {
foreach ($districtsAll as $district) {
if ($id == $district->getId()) {
$districts_t[] = $district;
}
}
}
foreach ($subwayIds as $id) {
foreach ($subwaysAll as $subway) {
if ($id == $subway->getId()) {
$subways_t[] = $subway;
}
}
}
$cityNum = $this->get('lot.model')->getByCityFilter([
"sorter" => ["order" => "date", "direction" => "desc"],
"page" => 1,
'lot' => 1,
'operation' => 1,
"price" => [
[
"min" => 0,
"max" => 100_000_000,
],
],
"space" => [
[
"min" => 0,
"max" => 100_000_000,
],
],
]);
$cityNum = $cityNum['count'];
$subNum = $this->get('lot.model')->getBySuburbanFilter([
"sorter" => ["order" => "date", "direction" => "desc"],
"page" => 1,
'lot' => 2,
'operation' => 1,
"price" => [
[
"min" => 0,
"max" => 100_000_000,
],
],
"space" => [
[
"min" => 0,
"max" => 100_000_000,
],
],
"distance" => [
[
"min" => 0,
"max" => 100,
],
],
]);
$subNum = $subNum['count'];
$comNum = $this->get('lot.model')->getByCityFilter([
"sorter" => ["order" => "date", "direction" => "desc"],
"page" => 1,
'lot' => 3,
'operation' => 1,
"price" => [
[
"min" => 0,
"max" => 100_000_000,
],
],
"space" => [
[
"min" => 0,
"max" => 100_000_000,
],
],
]);
$comNum = $comNum['count'];
$newNum = $complexes->getTotalItemCount();
return $this->render(
'TroikaRealEstateBundle:Pages:main.html.twig',
[
'blog' => $blog,
'page' => $page,
'recent' => $recent,
'items' => $items,
//'slider' => $slider,
'ogImg' => null,
'title' => $page->getMetaTitle(),
'description' => $page->getMetaDescription(),
'keywords' => $page->getMetaKeywords(),
'content' => $home->getContent(),
'types' => $types,
'districts' => $districts,
'districts_com' => $districts_com,
'highways' => $highways,
'countries' => $countries,
'settlements' => $settlements,
'adistricts' => $adistricts,
'adistricts_com' => $adistricts_com,
'ahighways' => $ahighways,
'acountries' => $acountries,
'tagSlots' => $tagSlots,
'subways' => $subways,
'districts_t' => $districts_t,
'subways_t' => $subways_t,
'cityNum' => $cityNum,
'subNum' => $subNum,
'comNum' => $comNum,
'newNum' => $newNum,
]
);
}
public function indexRedirectAction()
{
return $this->redirect("/", 301);;
}
public function mapAction()
{
$preset_city = [
"sale" => [
"area" => $this->get('filter_preset.model')->getPresetByAttr('District3', 1, 1),
"TypeHouse" => $this->get('filter_preset.model')->getPresetByAttr('TypeHouse', 1, 1),
"subway" => $this->get('filter_preset.model')->getPresetByAttr('Subway2', 1, 1),
],
"rent" => [
"area" => $this->get('filter_preset.model')->getPresetByAttr('District3', 1, 2),
"TypeHouse" => $this->get('filter_preset.model')->getPresetByAttr('TypeHouse', 1, 2),
"subway" => $this->get('filter_preset.model')->getPresetByAttr('Subway2', 1, 2),
],
];
$preset_suburban = [
"sale" => [
"highway" => $this->get('filter_preset.model')->getPresetByAttr('Highway', 2, 1),
"settlement" => $this->get('filter_preset.model')->getPresetByAttr('Settlement', 2, 1),
"TypeHouse" => $this->get('filter_preset.model')->getPresetByAttr('TypeHouse', 2, 1),
],
];
$preset_foreign = [
"sale" => $this->get('filter_preset.model')->getPresetByAttr('Country', 4, 1),
"rent" => $this->get('filter_preset.model')->getPresetByAttr('Country', 4, 2),
];
return $this->render('TroikaRealEstateBundle:Map:map.html.twig', [
'preset_city' => $preset_city,
'preset_suburban' => $preset_suburban,
'preset_foreign' => $preset_foreign,
]
);
}
public function n_servicesAction()
{
$repository = $this->getDoctrine()->getRepository('TroikaMainBundle:NServices');
$about = $repository->find(1);
return $this->render('TroikaRealEstateBundle:About:n_services.html.twig', [
'title' => $about->getTitle(),
'description' => $about->getDescription(),
'keywords' => $about->getKeywords(),
'content1' => $about->getContent1(),
'content2' => $about->getContent2(),
'content3' => $about->getContent3(),
'content4' => $about->getContent4(),
'img1' => $about->getWebPathImg1(),
'img2' => $about->getWebPathImg2(),
'img3' => $about->getWebPathImg3(),
'img4' => $about->getWebPathImg4(),
]);
}
public function newsAction()
{
$page = $_GET['page'] ?? 1;
$news = $this->container->get('news.model')->getPage($page);
return $this->render('TroikaRealEstateBundle:About:news.html.twig', ['news' => $news, 'year' => null]);
}
public function newsByYearAction($year)
{
$date = getdate();
if ($year < 2009) {
return $this->redirectToRoute('troika_year_news', ['year' => 2009], 301);
} elseif ($year > $date['year']) {
return $this->redirectToRoute('troika_year_news', ['year' => $date['year']], 301);
}
$page = $_GET['page'] ?? 1;
$news = $this->container->get('news.model')->getPageByYear($page, $year);
return $this->render('TroikaRealEstateBundle:About:news.html.twig', ['news' => $news, 'year' => $year]);
}
public function newsItemAction($id)
{
$news = $this->container->get('news.model')->getOne($id);
$links = $this->container->get('news.model')->getPage(1);
return $this->render('TroikaRealEstateBundle:About:news_item.html.twig', ['news' => $news, 'links' => $links]);
}
public function newsItemSlugAction($slug, $id)
{
$news = $this->container->get('news.model')->getSlug($slug, $id);
$links = $this->container->get('news.model')->getPage(1);
if (!$news) {
throw $this->createNotFoundException('The news does not exist');
}
return $this->render('TroikaRealEstateBundle:About:news_item.html.twig', ['news' => $news, 'links' => $links]);
}
public function partnersAction()
{
$blog = $this->getDoctrine()->getRepository('TroikaMainBundle:Blog')->findAll();
$partners = $this->getDoctrine()->getRepository('TroikaMainBundle:Partners')->findAll();
$page = $this->getDoctrine()->getRepository('TroikaMainBundle:MainPage')->find(2);
return $this->render('TroikaRealEstateBundle:About:partners.html.twig', ['partners' => $partners, 'page' => $page]);
}
public function pressAction()
{
$em = $this->getDoctrine()->getEntityManager();
$connection = $em->getConnection();
$statement =
$connection->prepare("select left(date,4) as date, count(*) from Press group by left(date,4) order by left(date,4) DESC");
$statement->execute();
$date = $statement->fetchAll();
$page = $_GET['page'] ?? 1;
$presses = $this->container->get('press.model')->getPage($page);
return $this->render('TroikaRealEstateBundle:About:press.html.twig', ['presses' => $presses, 'date' => $date, 'year' => null]);
}
public function pressByYearAction($year)
{
$page = $_GET['page'] ?? 1;
$press = $this->container->get('press.model')->getPageByYear($page, $year);
$em = $this->getDoctrine()->getEntityManager();
$connection = $em->getConnection();
$statement =
$connection->prepare("select left(date,4) as date, count(*) from Press group by left(date,4) order by left(date,4) DESC");
$statement->execute();
$date = $statement->fetchAll();
return $this->render('TroikaRealEstateBundle:About:press.html.twig', ['presses' => $press, 'year' => $year, 'date' => $date]);
}
public function servicesAction()
{
$repository = $this->getDoctrine()->getRepository('TroikaMainBundle:Service');
$service = $repository->find(1);
$blog = $this->getDoctrine()->getRepository('TroikaMainBundle:Blog')->findAll();
return $this->render('TroikaRealEstateBundle:About:services.html.twig', [
'title' => $service->getTitle(),
'description' => $service->getDescription(),
'keywords' => $service->getKeywords(),
'content' => $service->getContent(),
'blog' => $blog,
]);
}
}