"{$lat1},{$lon1}|{$lat2},{$lon2}", 'mode' => 'drive', 'units' => 'imperial', 'format' => 'json', 'apiKey' => $_ENV['GEOAPIFY_API_KEY'] ]; $url = "https://api.geoapify.com/v1/routing?".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); $route = new Route(json_decode($result)); if (is_a($route, Route::class)) { return $route; } return null; } public static function getRouteDistance(Location $origin, Location $destination): ?Route { $route = self::getRoute($origin->getLat(), $origin->getLon(), $destination->getLat(), $destination->getLon()); if ($route) { return $route; } return null; } public static function Phone(string $phone): string { $phone = preg_replace('/[^0-9]/', '', $phone); if(strlen($phone) > 10 && substr($phone, 0, 1) == '1') { $phone = substr($phone, 1); } 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; } /** * Checks if the user has permission to access a case. * * @param User $user * @param MemberCase $case * @param EntityManagerInterface $em * * @return bool */ public static function checkPermissions(User $user, MemberCase $case, EntityManagerInterface $em): bool { // if user is an admin, allow the action if (in_array('ROLE_ADMIN', $user->getRoles())) { return true; } // if user is assigned to this case, allow the action $uc = $em->getRepository(UserCase::class)->findOneBy(['user' => $user, 'memberCase' => $case]); if ($uc) { return true; } // get user of the case and check if user is a supervisor of the worker /** @var ?UserCase $uc */ $uc = $em->getRepository(UserCase::class)->findOneBy(['memberCase' => $case]); if ($uc) { $sup = $em->getRepository(Supervision::class)->findOneBy(['supervisor' => $user, 'worker' => $uc->getUser()]); if ($sup) { return true; } } // user does not have permissions to the case return false; } }