mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
all views created for person resource
This commit is contained in:
parent
4b188e2df6
commit
0a6a2c968c
@ -15,51 +15,161 @@ use Chill\PersonBundle\Entity\Person\PersonResource;
|
||||
use Chill\PersonBundle\Form\PersonResourceType;
|
||||
use Chill\PersonBundle\Repository\PersonRepository;
|
||||
use Chill\PersonBundle\Repository\PersonResourceRepository;
|
||||
use Chill\PersonBundle\Security\Authorization\PersonVoter;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
|
||||
final class PersonResourceController extends AbstractController
|
||||
{
|
||||
private PersonResourceRepository $personResourceRepository;
|
||||
private PersonRepository $personRepository;
|
||||
private EntityManagerInterface $em;
|
||||
private TranslatorInterface $translator;
|
||||
|
||||
public function __construct(
|
||||
PersonResourceRepository $personResourceRepository,
|
||||
PersonRepository $personRepository,
|
||||
EntityManagerInterface $em
|
||||
EntityManagerInterface $em,
|
||||
TranslatorInterface $translator
|
||||
)
|
||||
{
|
||||
$this->personResourceRepository = $personResourceRepository;
|
||||
$this->personRepository = $personRepository;
|
||||
$this->em = $em;
|
||||
$this->translator = $translator;
|
||||
}
|
||||
|
||||
public function listAction(Request $request, $person_id)
|
||||
{
|
||||
$person = $this->personRepository->find($person_id);
|
||||
$personResource = new PersonResource();
|
||||
$personOwner = $this->personRepository->find($person_id);
|
||||
$this->denyAccessUnlessGranted(PersonVoter::SEE, $personOwner);
|
||||
|
||||
$personResources = [];
|
||||
$personResources = $this->personResourceRepository->findBy(['personOwner' => $personOwner->getId()]);
|
||||
|
||||
$form = $this->createForm(PersonResourceType::class);
|
||||
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($request->getMethod() === Request::METHOD_POST && $form->isValid()) {
|
||||
dump($personResource);
|
||||
|
||||
$this->denyAccessUnlessGranted(PersonVoter::CREATE, $personOwner);
|
||||
|
||||
$personResource = new PersonResource();
|
||||
|
||||
$person = $form['person']->getData();
|
||||
$thirdparty = $form['thirdparty']->getData();
|
||||
$freetext = $form['freetext']->getData();
|
||||
$comment = $form['comment']->getData();
|
||||
$kind = $form['kind']->getData();
|
||||
|
||||
$personResource->setKind($kind);
|
||||
$personResource->setPerson($person);
|
||||
$personResource->setThirdParty($thirdparty);
|
||||
$personResource->setFreeText($freetext);
|
||||
$personResource->setComment($comment);
|
||||
|
||||
$personResource->setPersonOwner($personOwner);
|
||||
|
||||
$this->em->persist($personResource);
|
||||
$this->em->flush();
|
||||
|
||||
return $this->redirectToRoute(
|
||||
'chill_person_resource',
|
||||
['person_id' => $person->getId()]
|
||||
);
|
||||
return $this->redirectToRoute('chill_person_resource_list', [
|
||||
'person_id' => $personOwner->getId(),
|
||||
]);
|
||||
|
||||
}
|
||||
|
||||
return $this->render(
|
||||
'ChillPersonBundle:PersonResource:list.html.twig',
|
||||
[
|
||||
'person' => $person,
|
||||
'person' => $personOwner,
|
||||
'personResources' => $personResources,
|
||||
'form' => $form->createView()
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
public function editAction(Request $request, $resource_id, $person_id): Response
|
||||
{
|
||||
$resource = $this->personResourceRepository->find($resource_id);
|
||||
$personOwner = $this->personRepository->find($person_id);
|
||||
|
||||
$this->denyAccessUnlessGranted(PersonVoter::UPDATE, $personOwner);
|
||||
|
||||
if (null === $resource) {
|
||||
throw $this->createNotFoundException('Unable to find Resource entity.');
|
||||
}
|
||||
|
||||
$form = $this->createForm(PersonResourceType::class, $resource);
|
||||
$form->handleRequest($request);
|
||||
|
||||
if($form->isSubmitted() && $form->isValid()) {
|
||||
$this->em->persist($resource);
|
||||
$this->em->flush();
|
||||
|
||||
return $this->redirectToRoute('chill_person_resource_list', [
|
||||
'person_id' => $personOwner->getId(),
|
||||
]);
|
||||
}
|
||||
|
||||
return $this->render(
|
||||
'ChillPersonBundle:PersonResource:edit.html.twig',
|
||||
[
|
||||
'person' => $personOwner,
|
||||
'resource' => $resource,
|
||||
'form' => $form->createView(),
|
||||
'action' => 'edit'
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
public function deleteAction(Request $request, $person_id, $resource_id): Response
|
||||
{
|
||||
|
||||
$personOwner = $this->personRepository->find($person_id);
|
||||
$resource = $this->personResourceRepository->find($resource_id);
|
||||
|
||||
$this->denyAccessUnlessGranted(PersonVoter::UPDATE, $personOwner);
|
||||
|
||||
if (null === $resource) {
|
||||
throw $this->createNotFoundException('Unable to find Resource entity.');
|
||||
}
|
||||
|
||||
$form = $this->createFormBuilder()
|
||||
->setAction($this->generateUrl('chill_person_resource_delete', [
|
||||
'resource_id' => $resource_id,
|
||||
'person_id' => $person_id,
|
||||
]))
|
||||
->setMethod('DELETE')
|
||||
->add('submit', SubmitType::class, ['label' => 'Delete'])
|
||||
->getForm();
|
||||
|
||||
if($request->getMethod() === Request::METHOD_DELETE) {
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isValid()) {
|
||||
$this->em->remove($resource);
|
||||
$this->em->flush();
|
||||
|
||||
$this->addFlash('success', $this->translator
|
||||
->trans('The resource has been successfully removed.'));
|
||||
|
||||
return $this->redirectToRoute('chill_person_resource_list', [
|
||||
'person_id' => $personOwner->getId(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->render(
|
||||
'ChillPersonBundle:PersonResource:delete.html.twig',
|
||||
[
|
||||
'person' => $personOwner,
|
||||
'resource' => $resource,
|
||||
'form' => $form->createView()
|
||||
]
|
||||
);
|
||||
|
@ -1,7 +1,5 @@
|
||||
<div class="col-md col-xxl">
|
||||
|
||||
<h1>{{ 'Add a person resource'|trans }}</h1>
|
||||
|
||||
{{ form_start(form, {'attr' : {'id' : 'create-form'}}) }}
|
||||
|
||||
{{ form_row(form.kind) }}
|
||||
@ -9,19 +7,19 @@
|
||||
<div id="linked-entity">
|
||||
<fieldset class="mb-3">
|
||||
<div class="row">
|
||||
<legend class="col-sm-4 col-form-label required">Associer un</legend>
|
||||
<legend class="col-sm-4 col-form-label">Associer un</legend>
|
||||
<div class="col-sm-8">
|
||||
<div id="chill_personbundle_person_resource_linkedEntity">
|
||||
<div class="form-check">
|
||||
<input type="radio" id="chill_personbundle_person_resource_linkedEntity_0" class="form-check-input" value="person" />
|
||||
<input type="radio" id="chill_personbundle_person_resource_linkedEntity_0" name="linked-entity" class="form-check-input" value="person" />
|
||||
<label class="form-check-label" for="chill_personbundle_person_resource_linkedEntity_0">Usager</label>
|
||||
</div>
|
||||
<div class="form-check">
|
||||
<input type="radio" id="chill_personbundle_person_resource_linkedEntity_1" class="form-check-input" value="thirdparty" />
|
||||
<input type="radio" id="chill_personbundle_person_resource_linkedEntity_1" name="linked-entity" class="form-check-input" value="thirdparty" />
|
||||
<label class="form-check-label" for="chill_personbundle_person_resource_linkedEntity_1">Tiers</label>
|
||||
</div>
|
||||
<div class="form-check">
|
||||
<input type="radio" id="chill_personbundle_person_resource_linkedEntity_2" class="form-check-input" value="freeText" />
|
||||
<input type="radio" id="chill_personbundle_person_resource_linkedEntity_2" name="linked-entity" class="form-check-input" value="freeText" />
|
||||
<label class="form-check-label" for="chill_personbundle_person_resource_linkedEntity_2">Description libre</label>
|
||||
</div>
|
||||
</div>
|
||||
@ -41,14 +39,26 @@
|
||||
</div>
|
||||
|
||||
{{ form_row(form.comment) }}
|
||||
<ul class="record_actions">
|
||||
<li class="create">
|
||||
<button class="btn btn-create"
|
||||
type="submit" id="newPersonResource">
|
||||
{{ 'Add a person resource'|trans }}
|
||||
</button>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
{% if action is defined %}
|
||||
<ul class="record_actions">
|
||||
<li class="edit">
|
||||
<button class="btn btn-edit"
|
||||
type="submit" id="newPersonResource">
|
||||
{{ 'edit resource'|trans|capitalize }}
|
||||
</button>
|
||||
</li>
|
||||
</ul>
|
||||
{% else %}
|
||||
<ul class="record_actions">
|
||||
<li class="create">
|
||||
<button class="btn btn-create"
|
||||
type="submit" id="newPersonResource">
|
||||
{{ 'Add a person resource'|trans }}
|
||||
</button>
|
||||
</li>
|
||||
</ul>
|
||||
{% endif %}
|
||||
|
||||
{{ form_end(form) }}
|
||||
|
||||
|
@ -0,0 +1,17 @@
|
||||
{% extends "@ChillPerson/Person/layout.html.twig" %}
|
||||
|
||||
{% set activeRouteKey = 'chill_person_resource_list' %}
|
||||
{# {% set person = person %} #}
|
||||
|
||||
{% block title 'Remove resource'|trans %}
|
||||
|
||||
{% block personcontent %}
|
||||
{{ include('@ChillMain/Util/confirmation_template.html.twig',
|
||||
{
|
||||
'title' : 'Remove resource'|trans,
|
||||
'confirm_question' : 'Are you sure you want to remove the resource for "%name%" ?'|trans({ '%name%' : person.firstname ~ ' ' ~ person.lastname } ),
|
||||
'cancel_route' : 'chill_person_resource_list',
|
||||
'cancel_parameters' : { 'person_id' : person.id },
|
||||
'form' : form
|
||||
} ) }}
|
||||
{% endblock %}
|
@ -0,0 +1,17 @@
|
||||
{% extends "@ChillPerson/Person/layout.html.twig" %}
|
||||
|
||||
{% set activeRouteKey = 'chill_person_resource_edit' %}
|
||||
|
||||
{% block title %}{{ 'edit resource'|trans|capitalize }}{% endblock %}
|
||||
|
||||
{% block personcontent %}
|
||||
|
||||
<h1 style="margin-bottom: 2rem;">{{ 'edit resource'|trans }}</h1>
|
||||
|
||||
{% include "@ChillPerson/PersonResource/create.html.twig" %}
|
||||
|
||||
{% endblock %}
|
||||
|
||||
{% block js %}
|
||||
{{ encore_entry_script_tags('page_person_resource') }}
|
||||
{% endblock %}
|
@ -6,33 +6,69 @@
|
||||
|
||||
{% block personcontent %}
|
||||
|
||||
<div class="flex-table">
|
||||
<div class="item-bloc">
|
||||
<div class="item-row">
|
||||
<div class="item-col">Name of resource</div>
|
||||
<div class="item-col">kind of resource</div>
|
||||
<h1>{{ 'List of resources'|trans }}</h1>
|
||||
|
||||
{% if personResources is not null %}
|
||||
{% for resource in personResources %}
|
||||
<div class="flex-table">
|
||||
<div class="item-bloc">
|
||||
<div class="item-row">
|
||||
<div class="wrap-header">
|
||||
<div class="wh-row">
|
||||
<div class="wh-col">
|
||||
{% if resource.person is not null %}
|
||||
<div class="item-col"><p class="h3">{{ resource.person }}</p></div>
|
||||
{% elseif resource.thirdparty is not null %}
|
||||
<div class="item-col"><p class="h3">{{ resource.thirdparty }}</p></div>
|
||||
{% else %}
|
||||
<div class="item-col"><p class="h3">{{ resource.freetext }}</p></div>
|
||||
{% endif %}
|
||||
<div class="wh-col">
|
||||
<span>{{ resource.kind.title.fr }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="item-row separator">
|
||||
<section class="chill-entity entity-comment-embeddable">
|
||||
<blockquote class="chill-user-quote">
|
||||
<div>{{ resource.comment.comment }}<div>
|
||||
</blockquote>
|
||||
</section>
|
||||
</div>
|
||||
<div class="item-row separator">
|
||||
<div class="item-col">
|
||||
<ul class="record_actions">
|
||||
<li>
|
||||
<a href="{{ chill_path_add_return_path('chill_person_resource_edit', {'resource_id': resource.id,
|
||||
'person_id': person.id,}) }}"
|
||||
class="btn btn-sm btn-edit"
|
||||
title="{{ 'Edit'|trans }}"></a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="{{ chill_path_add_return_path('chill_person_resource_delete', {'person_id': person.id,
|
||||
'resource_id': resource.id}) }}"
|
||||
class="btn btn-sm btn-delete"
|
||||
title="{{ 'Delete'|trans }}"></a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{# <div class="item-row separator">
|
||||
<div class="item-col">How</div>
|
||||
<div class="item-col">are</div>
|
||||
</div> #}
|
||||
</div>
|
||||
<div class="item-bloc">
|
||||
<div class="item-row">
|
||||
<div class="item-col">comment zone</div>
|
||||
<div class="item-col">....</div>
|
||||
</div>
|
||||
<div class="item-row">
|
||||
{# <div class="item-col">today</div> #}
|
||||
<div class="item-col">Buttons</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
|
||||
{% else %}
|
||||
<p>{{ 'There are no available resources'|trans }}</p>
|
||||
{% endif %}
|
||||
|
||||
<h1 style="margin-bottom: 2rem;">{{ 'Add a person resource'|trans }}</h1>
|
||||
|
||||
{% include "@ChillPerson/PersonResource/create.html.twig" %}
|
||||
|
||||
{% endblock %}
|
||||
|
||||
{% block js %}
|
||||
{# {{ encore_entry_script_tags('page_person_resource') }} #}
|
||||
{{ encore_entry_script_tags('page_person_resource') }}
|
||||
{% endblock %}
|
@ -56,9 +56,17 @@ chill_person_accompanying_period_re_open:
|
||||
controller: Chill\PersonBundle\Controller\AccompanyingPeriodController::reOpenAction
|
||||
|
||||
chill_person_resource_list:
|
||||
path: /{_locale}/person/resource/{person_id}/general
|
||||
path: /{_locale}/person/{person_id}/resources/list
|
||||
controller: Chill\PersonBundle\Controller\PersonResourceController::listAction
|
||||
|
||||
chill_person_resource_edit:
|
||||
path: /{_locale}/person/{person_id}/resources/{resource_id}/edit
|
||||
controller: Chill\PersonBundle\Controller\PersonResourceController::editAction
|
||||
|
||||
chill_person_resource_delete:
|
||||
path: /{_locale}/person/{person_id}/resources/{resource_id}/delete
|
||||
controller: Chill\PersonBundle\Controller\PersonResourceController::deleteAction
|
||||
|
||||
chill_person_address_list:
|
||||
path: /{_locale}/person/{person_id}/address/list
|
||||
controller: Chill\PersonBundle\Controller\PersonAddressController::listAction
|
||||
|
@ -228,6 +228,12 @@ Concerned scopes: Services concernés
|
||||
person_resources_menu: "Ressources"
|
||||
Person resources: "Ressources de la personne"
|
||||
Add a person resource: "Ajouter une ressource"
|
||||
edit resource: "Modifier ressource"
|
||||
Remove resource: "Supprimer ressource"
|
||||
Are you sure you want to remove the resource for "%name%" ?: Étes-vous sûr de vouloir supprimer cette ressource de %name%?
|
||||
The resource has been successfully removed.: "La ressource a été supprimée."
|
||||
List of resources: "Liste des ressources"
|
||||
There are no available resources: "Il y aucun ressource"
|
||||
|
||||
# pickAPersonType
|
||||
Pick a person: Choisir une personne
|
||||
|
Loading…
x
Reference in New Issue
Block a user