update organisation
This commit is contained in:
parent
5ceed1f2f2
commit
8d92d3f9fc
|
|
@ -90,7 +90,7 @@ class OrganizationController extends AbstractController
|
|||
]);
|
||||
}
|
||||
|
||||
#[Route('/{id}', name: 'show',requirements: ['id' => '\d+'], methods: ['GET'])]
|
||||
#[Route('/{id}', name: 'show', requirements: ['id' => '\d+'], methods: ['GET'])]
|
||||
public function show(int $id, ActionService $actionService): Response
|
||||
{
|
||||
if ($this->isGranted('ROLE_ADMIN')) {
|
||||
|
|
@ -137,6 +137,46 @@ class OrganizationController extends AbstractController
|
|||
]);
|
||||
}
|
||||
|
||||
#[Route('/edit/{id}', name: 'edit', requirements: ['id' => '\d+'], methods: ['GET', 'POST'])]
|
||||
public function edit(Request $request): Response
|
||||
{
|
||||
$id = $request->attributes->get('id');
|
||||
if (!$this->isGranted('ROLE_SUPER_ADMIN')) {
|
||||
throw $this->createNotFoundException(self::ACCESS_DENIED);
|
||||
}
|
||||
$organization = $this->entityManager->getRepository(Organizations::class)->find($id);
|
||||
if (!$organization) {
|
||||
throw $this->createNotFoundException(self::NOT_FOUND);
|
||||
}
|
||||
$form = $this->createForm(OrganizationForm::class, $organization);
|
||||
$form->handleRequest($request);
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
$logoFile = $form->get('logoUrl')->getData();
|
||||
|
||||
if ($logoFile) {
|
||||
$currentDate = (new \DateTime())->format('Y-m-d');
|
||||
$organizationName = preg_replace('/[^a-zA-Z0-9]/', '_', $organization->getName());
|
||||
$extension = $logoFile->guessExtension();
|
||||
$newFilename = $currentDate . '_' . $organizationName . '.' . $extension;
|
||||
// Move the file to the directory where logos are stored
|
||||
$logoFile->move(
|
||||
$this->getParameter('logos_directory'),
|
||||
$newFilename
|
||||
);
|
||||
|
||||
// Update the 'logoUrl' property to store the file name
|
||||
$organization->setLogoUrl($newFilename);
|
||||
}
|
||||
$this->entityManager->persist($organization);
|
||||
$this->entityManager->flush();
|
||||
$this->addFlash('success', 'Organization updated successfully');
|
||||
return $this->redirectToRoute('organization_index');
|
||||
}
|
||||
return $this->render('organization/edit.html.twig', [
|
||||
'form' => $form->createView(),
|
||||
'organization' => $organization,
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -148,7 +148,7 @@ class UserController extends AbstractController
|
|||
/**
|
||||
* GET /user/{id}/edit - Show form to edit user
|
||||
*/
|
||||
#[Route('/{id}/edit', name: 'edit', requirements: ['id' => '\d+'], methods: ['GET', 'PUT', 'POST'])]
|
||||
#[Route('/edit/{id}', name: 'edit', requirements: ['id' => '\d+'], methods: ['GET', 'PUT', 'POST'])]
|
||||
public function edit(int $id, EntityManagerInterface $entityManager, Request $request): Response
|
||||
{
|
||||
//Handle access control
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ class OrganizationForm extends AbstractType
|
|||
->add('logoUrl', FileType::class, [
|
||||
'required' => false,
|
||||
'label' => 'Logo',
|
||||
'mapped' => true, // Important if the entity property is not directly mapped
|
||||
'mapped' => false, // Important if the entity property is not directly mapped
|
||||
'attr' => ['accept' => 'image/*'],
|
||||
]);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,21 @@
|
|||
{% extends 'base.html.twig' %}
|
||||
|
||||
{% block body %}
|
||||
<div class=" col-md-10 m-auto p-5">
|
||||
<div class="card">
|
||||
<div class="card-title shadow-sm p-3 d-flex justify-content-between align-items-center">
|
||||
<h2>Modifier l'organisation</h2>
|
||||
{% if is_granted("ROLE_SUPER_ADMIN") %}
|
||||
{# <a href="{{ path('organization_delete', {'id': organization.id}) }}" class="btn btn-danger">Supprimer</a>#}
|
||||
{% endif %}
|
||||
</div>
|
||||
<div class="card-body">
|
||||
|
||||
{{ form_start(form, {'action': path('organization_edit', {'id': organization.id}), 'method': 'PUT'}) }}
|
||||
{{ form_widget(form) }}
|
||||
<button type="submit" class="btn btn-primary">Enregistrer</button>
|
||||
{{ form_end(form) }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
|
@ -5,11 +5,13 @@
|
|||
<div class="col d-flex justify-content-between align-items-center ">
|
||||
<h1 class="mb-4">
|
||||
{% if organization.logoUrl %}
|
||||
<img src="{{ asset('uploads/logos/' ~ organization.logoUrl) }}" alt="Organization logo" class="rounded-circle" style="width:40px; height:40px;">
|
||||
<img src="{{ asset('uploads/logos/' ~ organization.logoUrl) }}" alt="Organization logo"
|
||||
class="rounded-circle" style="width:40px; height:40px;">
|
||||
{% endif %}
|
||||
{{ organization.name|title }} - Dashboard</h1>
|
||||
{% if is_granted("ROLE_SUER_ADMIN") %}
|
||||
{# <a href="{{ path('user_deactivate', {'id': user.id}) }}" class="btn btn-danger">Désactiver</a> #}
|
||||
{% if is_granted("ROLE_SUPER_ADMIN") %}
|
||||
<a href="{{ path('organization_edit', {'id': organization.id}) }}" class="btn btn-primary">Gérer mon
|
||||
organisation</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
{# USER ROW #}
|
||||
|
|
|
|||
Loading…
Reference in New Issue