authorizationHelper = $authorizationHelper; $this->configPersonAltNameHelper = $configPersonAltNameHelper; } public function personAddressApi($id, Request $request, string $_format): Response { return $this->addRemoveSomething('address', $id, $request, $_format, 'address', Address::class, ['groups' => ['read']]); } /** * @Route("/api/1.0/person/address/suggest/by-person/{person_id}.{_format}", * name="chill_person_address_suggest_by_person", * requirements={ * "_format": "json" * } * ) * @ParamConverter("person", options={"id": "person_id"}) */ public function suggestAddress(Person $person, Request $request, string $_format): Response { $this->denyAccessUnlessGranted(PersonVoter::SEE, $person); $addresses = []; // collect addresses from location in courses foreach ($person->getAccompanyingPeriodParticipations() as $participation) { if (null !== $participation->getAccompanyingPeriod()->getAddressLocation()) { $a = $participation->getAccompanyingPeriod()->getAddressLocation(); $addresses[$a->getId()] = $a; } } // remove the actual address $actual = $person->getCurrentHouseholdAddress(); if (null !== $actual) { $addresses = array_filter($addresses, static fn ($a) => $a !== $actual); } return $this->json(array_values($addresses), Response::HTTP_OK, [], ['groups' => ['read']]); } /** * @Route("/api/1.0/person/config/alt_names.{_format}", * name="chill_person_config_alt_names", * requirements={ * "_format": "json" * } * ) */ public function configAltNames(Request $request, string $_format): Response { // TODO: I CANT process php array $configAltNamesChoices = $this->configPersonAltNameHelper->getChoices(); dump($configAltNamesChoices); dump(array_keys($configAltNamesChoices)); dump(array_values($configAltNamesChoices)); $keys = []; foreach(array_keys($configAltNamesChoices) as $k){ array_push($keys, ['key' => $k]); } dump($keys); $values = []; foreach(array_values($configAltNamesChoices) as $v){ array_push($values, ['labels' => $v]); } dump($values); // dump(array_combine($keys, $values)); $configAltNames = [ ["key" => "jeune_fille", "labels" => ["fr" => "Nom de naissance" ]], ["key" => "surnom", "labels" => ["fr" => "Surnom" ]] ]; return $this->json($configAltNames, Response::HTTP_OK, [], ['groups' => ['read']]); } }