|
<?php |
|
namespace AppBundle\Controller; |
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
|
|
|
use AppBundle\Entity\Items; |
|
use Symfony\Component\HttpFoundation\Response; |
|
|
|
class TagsController extends Controller |
|
{ |
|
const CITY = 'miejscowosc'; |
|
|
|
public function indexAction(Request $request) |
|
{ |
|
$request->query->get('woj') == null ? $query = $request->attributes->get('woj') : |
|
$query = $request->query->get('woj'); |
|
|
|
//wojewodzkie |
|
if(!isset($query)){ |
|
$cities = $this->getCities('', ''); |
|
|
|
return $this->render('@App/tags/tags.html.twig', array( |
|
'places' => $cities |
|
)); |
|
}else { |
|
//powiatowe |
|
$cities = $this->getCities('', ''); |
|
foreach ($cities as $city) |
|
$district[] = $this->getDistrict($city[self::CITY], 'woj'); |
|
$towns = $this->getCities($query, 'pow'); |
|
} |
|
return $this->render('@App/tags/tags.html.twig', array( |
|
'places' => $cities |
|
)); |
|
} |
|
|
|
private function getDistrict($city, $district) |
|
{ |
|
$sql = "select $district from items where miejscowosc = '$city' group by $district"; |
|
$em = $this->getDoctrine()->getManager(); |
|
$stmt = $em->getConnection()->prepare($sql); |
|
$stmt->execute(); |
|
return $stmt->fetch()[$district]; |
|
|
|
} |
|
private function getCities($district, $code){ |
|
|
|
if($district != '' && $code != '') { |
|
$where = "where $code = '$district'"; |
|
}else{ |
|
$where = ''; |
|
} |
|
$sql = "select miejscowosc from items $where group by miejscowosc order by count(*) desc limit 10"; |
|
$em = $this->getDoctrine()->getManager(); |
|
$stmt = $em->getConnection()->prepare($sql); |
|
$stmt->execute(); |
|
return $city = $stmt->fetchAll(); |
|
} |
|
|
|
} |