add formatPhone and getMessages methods. Also, add method to autocomplete addresses
This commit is contained in:
parent
f454888a6f
commit
03cbbc0db6
@ -3,8 +3,13 @@
|
|||||||
namespace App\Libs;
|
namespace App\Libs;
|
||||||
|
|
||||||
use App\Entity\Location;
|
use App\Entity\Location;
|
||||||
|
use App\Entity\Messages;
|
||||||
|
use App\Entity\User;
|
||||||
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
|
||||||
class Libs
|
class Libs extends AbstractController
|
||||||
{
|
{
|
||||||
public static function getLatLonFromGeoapify($address): ?array
|
public static function getLatLonFromGeoapify($address): ?array
|
||||||
{
|
{
|
||||||
@ -61,6 +66,27 @@ class Libs
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[Route('/api/autocomplete-address/{searchText}', name: 'app_api_autocomplete_address')]
|
||||||
|
public function autocompleteAddress(string $searchText): Response
|
||||||
|
{
|
||||||
|
$params = [
|
||||||
|
'text' => $searchText,
|
||||||
|
'format' => 'json',
|
||||||
|
'apiKey' => $_ENV['GEOAPIFY_API_KEY']
|
||||||
|
];
|
||||||
|
|
||||||
|
$url = "https://api.geoapify.com/v1/autocomplete?".http_build_query($params);
|
||||||
|
$ch = curl_init();
|
||||||
|
curl_setopt($ch, CURLOPT_URL, $url);
|
||||||
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||||
|
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
|
||||||
|
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
|
||||||
|
$result = curl_exec($ch);
|
||||||
|
curl_close($ch);
|
||||||
|
|
||||||
|
return AbstractController::json($result);
|
||||||
|
}
|
||||||
|
|
||||||
public static function Phone(string $phone): string
|
public static function Phone(string $phone): string
|
||||||
{
|
{
|
||||||
$phone = preg_replace('/[^0-9]/', '', $phone);
|
$phone = preg_replace('/[^0-9]/', '', $phone);
|
||||||
@ -69,4 +95,17 @@ class Libs
|
|||||||
}
|
}
|
||||||
return $phone;
|
return $phone;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function formatPhone(string $phone): string
|
||||||
|
{
|
||||||
|
$phone = self::Phone($phone);
|
||||||
|
return "(".substr($phone, 0, 3).") ".substr($phone, 3, 3)."-".substr($phone, 6);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getMessages(User $user, EntityManagerInterface $em): array
|
||||||
|
{
|
||||||
|
$msgs = $em->getRepository(Messages::class)->getUnreadMessages($user);
|
||||||
|
|
||||||
|
return $msgs;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user