mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-20 14:43:49 +00:00
Merge branch 'features/household-validation' into features/household-edit-members-forms-improve-household
This commit is contained in:
@@ -86,8 +86,19 @@ class AccompanyingCourseController extends Controller
|
||||
*/
|
||||
public function indexAction(AccompanyingPeriod $accompanyingCourse): Response
|
||||
{
|
||||
// compute some warnings
|
||||
// get persons without household
|
||||
$withoutHousehold = [];
|
||||
foreach ($accompanyingCourse->getParticipations() as
|
||||
$p) {
|
||||
if (FALSE === $p->getPerson()->isSharingHousehold()) {
|
||||
$withoutHousehold[] = $p->getPerson();
|
||||
}
|
||||
}
|
||||
|
||||
return $this->render('@ChillPerson/AccompanyingCourse/index.html.twig', [
|
||||
'accompanyingCourse' => $accompanyingCourse
|
||||
'accompanyingCourse' => $accompanyingCourse,
|
||||
'withoutHousehold' => $withoutHousehold
|
||||
]);
|
||||
}
|
||||
|
||||
|
@@ -3,10 +3,13 @@
|
||||
namespace Chill\PersonBundle\Controller;
|
||||
|
||||
use Chill\MainBundle\Entity\Address;
|
||||
use Chill\PersonBundle\Form\HouseholdType;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use Symfony\Component\Translation\TranslatorInterface;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
|
||||
use Chill\PersonBundle\Entity\Household\Household;
|
||||
use Chill\PersonBundle\Entity\Household\Position;
|
||||
@@ -16,6 +19,16 @@ use Chill\PersonBundle\Entity\Household\Position;
|
||||
*/
|
||||
class HouseholdController extends AbstractController
|
||||
{
|
||||
private TranslatorInterface $translator;
|
||||
|
||||
/**
|
||||
* @param TranslatorInterface $translator
|
||||
*/
|
||||
public function __construct(TranslatorInterface $translator)
|
||||
{
|
||||
$this->translator = $translator;
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route(
|
||||
* "/{household_id}/summary",
|
||||
@@ -66,10 +79,17 @@ class HouseholdController extends AbstractController
|
||||
// some queries
|
||||
$household->getMembers()->initialize();
|
||||
|
||||
if ($request->query->has('edit')) {
|
||||
$form = $this->createMetadataForm($household);
|
||||
} else {
|
||||
$form = null;
|
||||
}
|
||||
|
||||
return $this->render('@ChillPerson/Household/members.html.twig',
|
||||
[
|
||||
'household' => $household,
|
||||
'positions' => $positions
|
||||
'positions' => $positions,
|
||||
'form' => NULL !== $form ? $form->createView(): $form
|
||||
]
|
||||
);
|
||||
}
|
||||
@@ -143,4 +163,53 @@ class HouseholdController extends AbstractController
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route(
|
||||
* "/{household_id}/members/metadata/edit",
|
||||
* name="chill_person_household_members_metadata_edit",
|
||||
* methods={"GET", "POST"}
|
||||
* )
|
||||
* @ParamConverter("household", options={"id" = "household_id"})
|
||||
*/
|
||||
public function editHouseholdMetadata(Request $request, Household $household)
|
||||
{
|
||||
// TODO ACL
|
||||
$form = $this->createMetadataForm($household);
|
||||
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isSubmitted() and $form->isValid()) {
|
||||
$this->getDoctrine()->getManager()->flush();
|
||||
|
||||
$this->addFlash('success', $this->translator->trans('household.data_saved'));
|
||||
|
||||
return $this->redirectToRoute('chill_person_household_members', [
|
||||
'household_id' => $household->getId()
|
||||
]);
|
||||
}
|
||||
|
||||
return $this->render('@ChillPerson/Household/edit_member_metadata.html.twig', [
|
||||
'household' => $household,
|
||||
'form' => $form->createView()
|
||||
]);
|
||||
}
|
||||
|
||||
private function createMetadataForm(Household $household): FormInterface
|
||||
{
|
||||
$form = $this->createForm(
|
||||
HouseholdType::class,
|
||||
$household,
|
||||
[
|
||||
'action' => $this->generateUrl(
|
||||
'chill_person_household_members_metadata_edit',
|
||||
[
|
||||
'household_id' => $household->getId()
|
||||
]
|
||||
)
|
||||
]
|
||||
);
|
||||
|
||||
return $form;
|
||||
}
|
||||
}
|
||||
|
@@ -50,8 +50,12 @@ class HouseholdMemberController extends ApiController
|
||||
|
||||
// TODO ACL
|
||||
//
|
||||
// TODO validation
|
||||
//
|
||||
$errors = $editor->validate();
|
||||
|
||||
if (count($errors) > 0) {
|
||||
return $this->json($errors, 422);
|
||||
}
|
||||
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
|
||||
// if new household, persist it
|
||||
@@ -155,7 +159,9 @@ class HouseholdMemberController extends ApiController
|
||||
{
|
||||
// TODO ACL
|
||||
|
||||
$form = $this->createForm(HouseholdMemberType::class, $member);
|
||||
$form = $this->createForm(HouseholdMemberType::class, $member, [
|
||||
'validation_groups' => [ 'household_memberships' ]
|
||||
]);
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
|
@@ -41,6 +41,8 @@ use Chill\PersonBundle\Config\ConfigPersonAltNamesHelper;
|
||||
use Chill\PersonBundle\Repository\PersonNotDuplicateRepository;
|
||||
use Symfony\Component\Validator\Validator\ValidatorInterface;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
|
||||
|
||||
final class PersonController extends AbstractController
|
||||
{
|
||||
@@ -416,4 +418,29 @@ final class PersonController extends AbstractController
|
||||
|
||||
return $person;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @Route(
|
||||
* "/{_locale}/person/household/{person_id}/history",
|
||||
* name="chill_person_household_person_history",
|
||||
* methods={"GET", "POST"}
|
||||
* )
|
||||
* @ParamConverter("person", options={"id" = "person_id"})
|
||||
*/
|
||||
public function householdHistoryByPerson(Request $request, Person $person): Response
|
||||
{
|
||||
$this->denyAccessUnlessGranted('CHILL_PERSON_SEE', $person,
|
||||
"You are not allowed to see this person.");
|
||||
|
||||
$event = new PrivacyEvent($person);
|
||||
$this->eventDispatcher->dispatch(PrivacyEvent::PERSON_PRIVACY_EVENT, $event);
|
||||
|
||||
return $this->render(
|
||||
'@ChillPerson/Person/household_history.html.twig',
|
||||
[
|
||||
'person' => $person
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user