mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-20 22:53:49 +00:00
first impl for household editor
This commit is contained in:
@@ -2,6 +2,9 @@
|
||||
|
||||
namespace Chill\PersonBundle\Controller;
|
||||
|
||||
use Chill\PersonBundle\Entity\Household\Position;
|
||||
use Chill\PersonBundle\Security\Authorization\PersonVoter;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use Symfony\Component\HttpFoundation\Exception\BadRequestException;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
@@ -15,7 +18,7 @@ class HouseholdMemberController extends ApiController
|
||||
/**
|
||||
* @Route(
|
||||
* "/api/1.0/person/household/members/move.{_format}",
|
||||
* name="chill_person_household_members_move"
|
||||
* name="chill_api_person_household_members_move"
|
||||
* )
|
||||
*/
|
||||
public function move(Request $request, $_format): Response
|
||||
@@ -27,7 +30,6 @@ class HouseholdMemberController extends ApiController
|
||||
} catch (Exception\InvalidArgumentException | Exception\UnexpectedValueException $e) {
|
||||
throw new BadRequestException("Deserialization error: {$e->getMessage()}", 45896, $e);
|
||||
}
|
||||
dump($editor);
|
||||
// TODO ACL
|
||||
//
|
||||
// TODO validation
|
||||
@@ -44,7 +46,52 @@ class HouseholdMemberController extends ApiController
|
||||
$em->flush();
|
||||
$em->commit();
|
||||
|
||||
|
||||
return $this->json($editor->getHousehold(), Response::HTTP_OK, ["groups" => ["read"]]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route(
|
||||
* "/{_locale}/person/household/members/editor",
|
||||
* name="chill_person_household_members_editor"
|
||||
* )
|
||||
*/
|
||||
public function editor(Request $request)
|
||||
{
|
||||
if ($request->query->has('persons')) {
|
||||
$ids = $request->query->get('persons', []);
|
||||
|
||||
if (0 === count($ids)) {
|
||||
throw new BadRequestExceptions("parameters persons in query ".
|
||||
"is not an array or empty");
|
||||
}
|
||||
|
||||
$persons = $this->getDoctrine()->getManager()
|
||||
->getRepository(Person::class)
|
||||
->findById($ids)
|
||||
;
|
||||
|
||||
foreach ($persons as $person) {
|
||||
$this->denyAccessUnlessGranted(PersonVoter::SEE, $person,
|
||||
"You are not allowed to see person with id {$person->getId()}"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$positions = $this->getDoctrine()->getManager()
|
||||
->getRepository(Position::class)
|
||||
->findAll()
|
||||
;
|
||||
|
||||
$data = [
|
||||
'persons' => $persons ?? false ?
|
||||
$this->getSerializer()->normalize($persons, 'json', [ 'groups' => [ 'read' ]]): [],
|
||||
'household' => null,
|
||||
'positions' =>
|
||||
$this->getSerializer()->normalize($positions, 'json', [ 'groups' => [ 'read' ]])
|
||||
];
|
||||
|
||||
return $this->render('@ChillPerson/Household/members_editor.html.twig', [
|
||||
'data' => $data
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user