Skip to content

Commit

Permalink
#35: Possibilité de modifier un utilisateur dans l'écran d'administra…
Browse files Browse the repository at this point in the history
…tion
  • Loading branch information
baptiste-its committed Mar 1, 2021
1 parent f7847b4 commit a35e7b5
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 60 deletions.
7 changes: 7 additions & 0 deletions public/assets/css/css.css
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,11 @@ h1, h2, h3, h4, h5 {
padding: 5px;
border-radius:20%;
cursor:pointer;
}

.jumbotron label {
color: #0d6efd;
font-family: Pattaya, sans-serif;
margin-top: 8px;
font-size: 18px;
}
31 changes: 8 additions & 23 deletions src/Controller/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Controller;

use App\Entity\HalfDayAdjustment;
use App\Form\EditCustomerType;
use App\Form\HalfDayAdjustmentType;
use App\Repository\HalfDayAdjustmentRepository;
use App\Repository\CheckInRepository;
Expand Down Expand Up @@ -140,36 +141,20 @@ public function activate($id)
*/
public function profile($id, Request $request)
{
$customer = $this->customerRepository->findOneBy(
[
'id' => $id
]
);

$subscription = $this->subscriptionRepository->findOneBy(
[
'customer' => $id
]
);

$promo = $this->promoRepository->findOneBy(
[
'customer' => $id
]
);
$customer = $this->customerRepository->findOneBy(['id' => $id]);
$subscription = $this->subscriptionRepository->findOneBy(['customer' => $id]);
$promo = $this->promoRepository->findOneBy(['customer' => $id]);

$counter = $this->createForm(PromoType::class, $promo);
$counter->handleRequest($request);

if ($counter->isSubmitted() && $counter->isValid()) {
$this->manager->persist($promo);
$this->manager->flush();
};

$status = $this->createForm(CustomerSettingStatusType::class, $customer);
$status->handleRequest($request);

if ($status->isSubmitted() && $status->isValid()) {
$customerForm = $this->createForm(EditCustomerType::class, $customer);
$customerForm->handleRequest($request);
if ($counter->isSubmitted() && $counter->isValid()) {
$this->manager->persist($customer);
$this->manager->flush();
}
Expand All @@ -178,9 +163,9 @@ public function profile($id, Request $request)
'admin/profile.html.twig',
[
'customer' => $customer,
'customerForm' => $customerForm->createView(),
'subscription' => $subscription,
'formPromo' => $counter->createView(),
'formStatus' => $status->createView()
]
);
}
Expand Down
58 changes: 58 additions & 0 deletions src/Form/EditCustomerType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

namespace App\Form;

use App\Entity\Customer;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\PasswordType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

class EditCustomerType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('lastname', TextType::class, [
'label' => 'Nom'
])
->add('firstname', TextType::class, [
'label' => 'Prénom'
])
->add('society', TextType::class, [
'label' => 'Société (facultatif)',
'required' => false
])
->add('country', TextType::class, [
'label' => 'Pays'
])
->add('address', TextType::class, [
'label' => 'Adresse'
])
->add('city', TextType::class, [
'label' => 'Ville'
])
->add('zip', TextType::class, [
'label' => 'Code postal'
])
->add('phone', TextType::class, [
'label' => 'Téléphone'
])
->add('mail', EmailType::class, [
'label' => 'E-mail'
])
->add('status', TextType::class, [
'label' => 'Statut'
])
;
}

public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => Customer::class,
]);
}
}
55 changes: 18 additions & 37 deletions templates/admin/profile.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -10,36 +10,25 @@
<div class="row">
<div class="col-8">
<div class="jumbotron first">
<div class="row">
<div class="col-6">
<h3 class="text-primary">Nom : </h3>
<p class="mb-3 h5">{{ customer.lastname }}</p>
<h3 class="text-primary">Prénom : </h3>
<p class="mb-3 h5">{{ customer.firstname }}</p>
<h3 class="text-primary">Téléphone : </h3>
<p class="mb-3 h5">{{ customer.phone }}</p>
<h3 class="text-primary">E-mail : </h3>
<p class="mb-3 h5">{{ customer.mail }}</p>
{% if customer.society != '' %}
<h3 class="text-primary">Société : </h3>
<p class="mb-3 h5">{{ customer.society }}</p>
{% endif %}
{{ form_start(customerForm) }}
<div class="row">
<div class="col-6">
{{ form_row(customerForm.lastname) }}
{{ form_row(customerForm.firstname) }}
{{ form_row(customerForm.phone) }}
{{ form_row(customerForm.mail) }}
{{ form_row(customerForm.society) }}
</div>
<div class="col-6">
{{ form_row(customerForm.country) }}
{{ form_row(customerForm.address) }}
{{ form_row(customerForm.zip) }}
{{ form_row(customerForm.city) }}
{{ form_row(customerForm.status) }}
</div>
</div>
<div class="col-6">
<h3 class="text-primary">Pays : </h3>
<p class="mb-3 h5">{{ customer.country }}</p>
<h3 class="text-primary">Adresse : </h3>
<p class="mb-3 h5">{{ customer.address }}</p>
<h3 class="text-primary">Code postal : </h3>
<p class="mb-3 h5">{{ customer.zip }}</p>
<h3 class="text-primary">Ville : </h3>
<p class="mb-3 h5">{{ customer.city }}</p>
<h3 class="text-primary">Statut : </h3>
<p class="mb-3 h5">
{{ customer.getStatus }}
</p>
</div>
</div>
<button type="submit" class="btn btn-success btn-lg col-4 offset-4 mt-4">Modifier</button>
{{ form_end(customerForm) }}
</div>
</div>
<div class="col-4">
Expand All @@ -50,14 +39,6 @@
<button type="submit" class="btn btn-success btn-lg col-4 offset-4">Changer</button>
{{ form_end(formPromo) }}
</div>
<br/>
<div class="jumbotron first">
{{ form_start(formStatus) }}
<h3 class="text-primary text-center mb-3">Statut :</h3>
{{ form_row(formStatus.status, {'label':false, 'attr': {'class': 'col-4 offset-4'}}) }}
<button type="submit" class="btn btn-success btn-lg col-4 offset-4">Changer</button>
{{ form_end(formStatus) }}
</div>
</div>

</div>
Expand Down

0 comments on commit a35e7b5

Please sign in to comment.