@ -11,6 +11,7 @@ use Exception;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\Uid\Uuid;
use Symfony\Component\Uid\Uuid;
use Doctrine\DBAL\Connection;
use App\Entity\Location;
use App\Entity\Location;
use League\Csv\Reader;
use League\Csv\Reader;
@ -25,16 +26,59 @@ class HandleLocations
{
{
private $session;
private $session;
private $entityManager;
private $entityManager;
private $conn;
private $limit = 4;
private $limit = 4;
public function __construct(
public function __construct(
Connection $connection,
EntityManagerInterface $entityManager,
EntityManagerInterface $entityManager,
RequestStack $requestStack
RequestStack $requestStack
) {
) {
$this->connection = $connection;
$this->entityManager = $entityManager;
$this->entityManager = $entityManager;
$this->session = $requestStack->getSession();
$this->session = $requestStack->getSession();
}
}
public function searchLocations(string $terms)
{
$errorMessage = null;
$response = null;
//$utils = new StringTools();
//$term = $utils->removeCommonWords($terms);
$terms = str_replace(",", "", $terms);
$terms = str_replace(" ", "|", $terms);
try {
$search = $this->connection->fetchAllAssociative("SELECT * FROM searchlocations('$terms')");
} catch (PDOException $error) {
$errorMessage = $error->getMessage();
} catch (DBALException $error) {
$errorMessage = $error->getMessage();
} catch (ORMException $error) {
$errorMessage = $error->getMessage();
} catch (Exception $error) {
$errorMessage = $error->getMessage();
} catch (SyntaxErrorException $error) {
$errorMessage = $error->getMessage();
}
if ($errorMessage != null) {
$response = [
"status" => false,
"message" => $errorMessage,
];
} else {
$response = [
"status" => true,
"message" => "Good Reqeust",
"items" => $search,
"terms" => $terms,
];
}
return $response;
}
public function getActiveLocations()
public function getActiveLocations()
{
{
$listings = $this->entityManager->getRepository(Location::class);
$listings = $this->entityManager->getRepository(Location::class);