entityManager->getRepository(UserCase::class)->find($id); $data = json_decode($request->getContent()); $location = new Location(); //$location->setItinerary($itinerary) ; return $this->json($location); } #[Route('/api/filter-address-by-case/{caseId}', name: 'ajax_filter_address_by_case')] public function filterAddressByCase(string $caseId, Request $request): Response { $case = $this->entityManager->getRepository(MemberCase::class)->find($caseId); $addresses = $this->entityManager->getRepository(Location::class)->getLocationsByCase($case); return $this->json($addresses); } #[Route('/api/case/{caseId}/user/{userId}', name: 'ajax_case_user_level_check')] public function checkUserCaseLevel(string $caseId, string $userId, #[CurrentUser()] User $admin) : Response { $ret = true; $user = $this->entityManager->getRepository(User::class)->find($userId); $case = $this->entityManager->getRepository(MemberCase::class)->find($caseId); if (!Libs::checkPermissions($user, $case, $this->entityManager)) { throw new AccessDeniedHttpException ('You do not have permission to access this resource.'); } $res = UserCase::checkLevel($admin, $case); if (!$res) { $ret = [ 'userLevel' => ucwords(str_replace('_', ' ', strtolower($user->getLevel()->name))), 'caseLevel' => ucwords(str_replace('_', ' ', strtolower($case->getLevel()->name))), ]; } return $this->json($ret); } #[Route('/api/filter-cases-by-user', name: 'ajax_filter_cases_by_user')] public function filterCasesByUser(Request $request): Response { /** @var User $user */ $user = $this->entityManager->getRepository(User::class)->find($request->query->get('userId')); /** @var UserCase[] $ucs */ $ucs = $this->entityManager->getRepository(UserCase::class)->findBy(['user' => $user]); $ret = []; foreach ($ucs as $uc) { $ret[] = $uc->getMemberCase(); } return $this->json($ret); } #[Route('/api/filter-resource-by-county', name: 'app_api_filter_resource_by_county')] public function filterResourceByCounty(Request $request): Response { $data = json_decode($request->getContent(), true); $county = $data['county']; if ($county) { $resources = $this->entityManager->getRepository(CommunityResource::class)->findBy(['county' => $county]); } else { $resources = $this->entityManager->getRepository(CommunityResource::class)->findAll(); } return $this->json($resources); } #[Route('/api/get-case-locations/{caseId}', name: 'get_case_locations')] public function createItinerary(string $caseId): Response { $case = $this->entityManager->getRepository(MemberCase::class)->find($caseId); $cls = $this->entityManager->getRepository(CaseLocation::class)->getCaseLocations($case); $crs = $this->entityManager->getRepository(CommunityResource::class)->findAll(); $locations = []; foreach ($cls as $cl) { /** @var CaseLocation $cl */ $locations[] = $cl->getLocation(); } foreach ($crs as $cr) { $locations[] = $cr->toLocation(); } return $this->json($locations); } #[Route('/api/add-location-to-itinerary', name: 'add_location_to_itinerary')] public function addLocationToItinerary(Request $request, Session $session): Response { $case = $this->entityManager->getRepository(MemberCase::class)->find($request->getPayload()->get('caseId')); $origin = $this->entityManager->getRepository(Location::class)->find($request->getPayload()->get('origin')); $destination = $this->entityManager->getRepository(Location::class)->find($request->getPayload()->get('destination')); $departure = $request->getPayload()->get('departure'); $caseMileage = (bool) $request->getPayload()->get('caseMileage'); $date = new DateTime($request->getPayload()->get('date'), new DateTimeZone($_ENV['COMPANY_TIMEZONE'])); $route = Libs::getRouteDistance($origin, $destination); if (!$route) { return $this->json([ 'success' => false, 'message' => 'No route found' ]); } $ci = new CaseItinerary(); $ci->setMemberCase($case) ->setDate($date) ->setCaseMileage($caseMileage) ->setOriginLocation($origin) ->setDestLocation($destination) ->setDeparture(new \DateTimeImmutable($departure)) ->setDistance($route->getDistance()) ->setDuration($route->getDuration()) ->setGpsRoute($route->getGeometry()) ; $this->entityManager->persist($ci); $this->entityManager->flush(); $session->getFlashBag()->add( 'success', 'Location added to itinerary' ); return $this->json([ 'success' => true, 'message' => 'Location added to itinerary' ]); } #[Route('/api/filter-itinerary-by-case', name: 'ajax_filter_itinerary_by_case')] public function filterItineraryByCase(Request $request, #[CurrentUser()] ?User $user): Response { $case = null; $startDate = null; $endDate = null; //dd($request->getPayload()); if ($request->getPayload()->get('caseId')) { $caseId = $request->getPayload()->get('caseId'); $case = $this->entityManager->getRepository(MemberCase::class)->find($caseId); } if ($request->getPayload()->get('startDate')) { $startDate = new DateTime($request->getPayload()->get('startDate'), new DateTimeZone($_ENV['COMPANY_TIMEZONE'])); } if ($request->getPayload()->get('endDate')) { $endDate = new DateTime($request->getPayload()->get('endDate'), new DateTimeZone($_ENV['COMPANY_TIMEZONE'])); } $itineraries = $this->entityManager->getRepository(CaseItinerary::class)->getRecentTravel($user, [ 'case' => $case, 'from' => $startDate, 'to' => $endDate, ]); $ret = []; foreach ($itineraries as $itinerary) { /** @var CaseItinerary $itinerary */ $ret[] = [ 'id' => $itinerary->getId()->toString(), 'date' => $itinerary->getDate()->format('F j, Y'), 'origin' => $itinerary->getOriginLocation(), 'destination' => $itinerary->getDestLocation(), 'distance' => $itinerary->getDistance(), 'duration' => $itinerary->getDuration()->format("%h:%i'%s''"), 'case' => $itinerary->getMemberCase()->getCaseName(), ]; } return $this->json($ret); } #[Route('/api/filter-notes', name: 'api_filter_notes')] public function filterNotes(#[CurrentUser()] User $user, Request $request): Response { $startDate = null; $endDate = null; $referral = null; $case = null; if ($request->getPayload()->get('startDate')) { $startDate = new DateTime($request->getPayload()->get('startDate'), new DateTimeZone($_ENV['COMPANY_TIMEZONE'])); } if ($request->getPayload()->get('endDate')) { $endDate = new DateTime($request->getPayload()->get('endDate'), new DateTimeZone($_ENV['COMPANY_TIMEZONE'])); } if ($request->getPayload()->get('referral')) { $referral = $this->entityManager->getRepository(Referral::class)->find($request->getPayload()->get('referral')); } if ($request->getPayload()->get('case')) { $case = $this->entityManager->getRepository(MemberCase::class)->find($request->getPayload()->get('case')); } $params = [ 'startDate' => $startDate, 'endDate' => $endDate, 'referral' => $referral, 'case' => $case, ]; $notes = array_merge( $this->entityManager->getRepository(VisitNote::class)->filterNotes($user, $params), $this->entityManager->getRepository(StandardNote::class)->filterNotes($user, $params), ); foreach ($notes as $idx => $note) { /** @var VisitNote|StandardNote $note */ /** @var VisitNoteMember[]|StandardNoteMember[] $members */ if ($note instanceof VisitNote) { $members = $this->entityManager->getRepository(VisitNoteMembers::class)->findBy(['note' => $note]); } elseif ($note instanceof StandardNote) { $members = $this->entityManager->getRepository(StandardNoteMember::class)->findBy(['note' => $note]); } else { continue; } $notes[$idx]->setMembers($members); } return new Response(json_encode($notes, 0, 3)); } }