mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
116 lines
3.9 KiB
PHP
116 lines
3.9 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Chill is a software for social workers
|
|
*
|
|
* For the full copyright and license information, please view
|
|
* the LICENSE file that was distributed with this source code.
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Chill\PersonBundle\Controller;
|
|
|
|
use Chill\MainBundle\CRUD\Controller\ApiController;
|
|
use Chill\MainBundle\Entity\Address;
|
|
use Chill\MainBundle\Security\Authorization\AuthorizationHelper;
|
|
use Chill\PersonBundle\Config\ConfigPersonAltNamesHelper;
|
|
use Chill\PersonBundle\Entity\Person;
|
|
use Chill\PersonBundle\Security\Authorization\PersonVoter;
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
use Symfony\Component\Routing\Annotation\Route;
|
|
|
|
use function array_filter;
|
|
use function array_values;
|
|
|
|
class PersonApiController extends ApiController
|
|
{
|
|
private AuthorizationHelper $authorizationHelper;
|
|
private ConfigPersonAltNamesHelper $configPersonAltNameHelper;
|
|
|
|
public function __construct(
|
|
AuthorizationHelper $authorizationHelper,
|
|
ConfigPersonAltNamesHelper $configPersonAltNameHelper
|
|
)
|
|
{
|
|
$this->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']]);
|
|
}
|
|
|
|
}
|