This repository has been archived by the owner on May 27, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New feat : Add a new Child to an user account
Add Child Feat
- Loading branch information
Showing
11 changed files
with
687 additions
and
0 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
import '../scss/newchild.scss' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
@import "variables"; | ||
|
||
@font-face { | ||
font-family: Gilroy-SemiBold; | ||
src: url("../fonts/Gilroy-SemiBold.woff"); | ||
} | ||
|
||
body { | ||
font-family: 'Gilroy-SemiBold', sans-serif; | ||
|
||
form{ | ||
input[type="date"]{ | ||
width: 350px; | ||
} | ||
|
||
.btn{ | ||
width: 225px; | ||
height: 50px; | ||
color: #fff; | ||
background-color: #28a745; | ||
border-color: #28a745; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<?php | ||
|
||
namespace App\Controller; | ||
|
||
use App\Entity\Child; | ||
use App\Entity\User; | ||
use App\Form\NewChildType; | ||
use Symfony\Component\HttpFoundation\RedirectResponse; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; | ||
use Symfony\Component\HttpFoundation\Response; | ||
use Symfony\Component\Routing\Annotation\Route; | ||
|
||
class DashboardController extends AbstractController | ||
{ | ||
/** | ||
* @Route("/dashboard", name="app_dashboard") | ||
*/ | ||
public function index() | ||
{ | ||
return $this->render('dashboard/index.html.twig', [ | ||
'controller_name' => 'DashboardController' | ||
]); | ||
} | ||
|
||
/** | ||
* @Route("/dashboard/newchild", name="dashboard.newchild") | ||
* @param Request $request | ||
* @return RedirectResponse|Response | ||
*/ | ||
public function newChild(Request $request) | ||
{ | ||
/* Create & Generate Form */ | ||
$child = new Child(); // Nouvelle Objet de l'Entité Child | ||
$form = $this->createForm(NewChildType::class, $child); // Génération du Form à partir du fichier Form | ||
|
||
/* Submit Form Method */ | ||
$form->handleRequest($request); // Récupération des Paramètres (POST/GET) | ||
if($form->isSubmitted() && $form->isValid()){ | ||
|
||
$child | ||
->setNom($form->get('nom')->getData()) // Récupération Data Nom du Form | ||
->setPrenom($form->get('prenom')->getData()) // Récupération Data Prénom du Form | ||
->setDateNaissance($form->get('dateNaissance')->getData()) // Récupération Data Date de Naissance du Form | ||
->setDateInscription() | ||
->setNoUser($this->getUser()) | ||
; | ||
|
||
$entityManager = $this->getDoctrine()->getManager(); | ||
$entityManager->persist($child); // Création Requête avec les données ci-dessus | ||
$entityManager->flush(); // Envoi de la Requête | ||
|
||
/* Redirection */ | ||
return $this->redirectToRoute('dashboard.newchild'); | ||
|
||
} | ||
|
||
return $this->render('dashboard/newchild.html.twig', [ | ||
'addChildForm' => $form->createView() | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
<?php | ||
|
||
namespace App\Entity; | ||
|
||
use ApiPlatform\Core\Annotation\ApiResource; | ||
use Doctrine\ORM\Mapping as ORM; | ||
|
||
/** | ||
* @ApiResource() | ||
* @ORM\Entity(repositoryClass="App\Repository\ChildRepository") | ||
*/ | ||
class Child | ||
{ | ||
/** | ||
* @ORM\Id() | ||
* @ORM\GeneratedValue() | ||
* @ORM\Column(type="integer") | ||
*/ | ||
private $id; | ||
|
||
/** | ||
* @ORM\Column(type="string", length=50) | ||
*/ | ||
private $nom; | ||
|
||
/** | ||
* @ORM\Column(type="string", length=50) | ||
*/ | ||
private $prenom; | ||
|
||
/** | ||
* @ORM\Column(type="date") | ||
*/ | ||
private $dateNaissance; | ||
|
||
/** | ||
* @ORM\Column(type="datetime") | ||
*/ | ||
private $dateInscription; | ||
|
||
/** | ||
* @ORM\ManyToOne(targetEntity="App\Entity\User") | ||
* @ORM\JoinColumn(nullable=false) | ||
*/ | ||
private $noUser; | ||
|
||
public function getId(): ?int | ||
{ | ||
return $this->id; | ||
} | ||
|
||
public function getNom(): ?string | ||
{ | ||
return $this->nom; | ||
} | ||
|
||
public function setNom(string $nom): self | ||
{ | ||
$this->nom = $nom; | ||
|
||
return $this; | ||
} | ||
|
||
public function getPrenom(): ?string | ||
{ | ||
return $this->prenom; | ||
} | ||
|
||
public function setPrenom(string $prenom): self | ||
{ | ||
$this->prenom = $prenom; | ||
|
||
return $this; | ||
} | ||
|
||
public function getDateNaissance(): ?\DateTimeInterface | ||
{ | ||
return $this->dateNaissance; | ||
} | ||
|
||
public function setDateNaissance(\DateTimeInterface $dateNaissance): self | ||
{ | ||
$this->dateNaissance = $dateNaissance; | ||
|
||
return $this; | ||
} | ||
|
||
public function getDateInscription(): ?\DateTimeInterface | ||
{ | ||
return $this->dateInscription; | ||
} | ||
|
||
public function setDateInscription(): self | ||
{ | ||
$this->dateInscription = new \DateTime(); | ||
|
||
return $this; | ||
} | ||
|
||
public function getNoUser(): ?User | ||
{ | ||
return $this->noUser; | ||
} | ||
|
||
public function setNoUser($noUser): self | ||
{ | ||
$this->noUser = $noUser; | ||
|
||
return $this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?php | ||
|
||
namespace App\Form; | ||
|
||
use App\Entity\Child; | ||
use Symfony\Component\Form\AbstractType; | ||
use Symfony\Component\Form\Extension\Core\Type\DateType; | ||
use Symfony\Component\Form\Extension\Core\Type\TextType; | ||
use Symfony\Component\Form\FormBuilderInterface; | ||
use Symfony\Component\OptionsResolver\OptionsResolver; | ||
use Symfony\Component\Validator\Constraints\Length; | ||
use Symfony\Component\Validator\Constraints\NotBlank; | ||
|
||
class NewChildType extends AbstractType | ||
{ | ||
public function buildForm(FormBuilderInterface $builder, array $options) | ||
{ | ||
$builder | ||
->add('nom', TextType::class, [ | ||
'mapped' => false, | ||
'constraints' => [ | ||
new NotBlank([ | ||
'message' => 'Veuillez renseignez le nom de votre enfant !' | ||
]), | ||
new Length([ | ||
'max' => '50', | ||
'maxMessage' => 'Le Nom de l\'Enfant ne peut contenir plus de {{ limit }} caractères !' | ||
]) | ||
], | ||
'label' => 'Nom de l\'Enfant', | ||
'required' => true | ||
]) | ||
->add('prenom', TextType::class, [ | ||
'mapped' => false, | ||
'constraints' => [ | ||
new NotBlank([ | ||
'message' => 'Veuillez renseignez le prénom de votre enfant !' | ||
]), | ||
new Length([ | ||
'max' => '50', | ||
'maxMessage' => 'Le Prénom de l\'Enfant ne peut contenir plus de {{ limit }} caractères !' | ||
]) | ||
], | ||
'label' => 'Prénom de l\'Enfant', | ||
'required' => true | ||
]) | ||
->add('dateNaissance', DateType::class, [ | ||
'widget' => 'single_text', | ||
'mapped' => false, | ||
'constraints' => [ | ||
new NotBlank([ | ||
'message' => 'Veuillez renseignez la date de naissance de votre enfant !' | ||
]) | ||
], | ||
'label' => 'Date de Naissance de l\'Enfant', | ||
'required' => true | ||
]) | ||
; | ||
} | ||
|
||
public function configureOptions(OptionsResolver $resolver) | ||
{ | ||
$resolver->setDefaults([ | ||
'data_class' => Child::class, | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
namespace App\Repository; | ||
|
||
use App\Entity\Child; | ||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; | ||
use Doctrine\Persistence\ManagerRegistry; | ||
|
||
/** | ||
* @method Child|null find($id, $lockMode = null, $lockVersion = null) | ||
* @method Child|null findOneBy(array $criteria, array $orderBy = null) | ||
* @method Child[] findAll() | ||
* @method Child[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) | ||
*/ | ||
class ChildRepository extends ServiceEntityRepository | ||
{ | ||
public function __construct(ManagerRegistry $registry) | ||
{ | ||
parent::__construct($registry, Child::class); | ||
} | ||
|
||
// /** | ||
// * @return Child[] Returns an array of Child objects | ||
// */ | ||
/* | ||
public function findByExampleField($value) | ||
{ | ||
return $this->createQueryBuilder('c') | ||
->andWhere('c.exampleField = :val') | ||
->setParameter('val', $value) | ||
->orderBy('c.id', 'ASC') | ||
->setMaxResults(10) | ||
->getQuery() | ||
->getResult() | ||
; | ||
} | ||
*/ | ||
|
||
/* | ||
public function findOneBySomeField($value): ?Child | ||
{ | ||
return $this->createQueryBuilder('c') | ||
->andWhere('c.exampleField = :val') | ||
->setParameter('val', $value) | ||
->getQuery() | ||
->getOneOrNullResult() | ||
; | ||
} | ||
*/ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{% extends 'base.html.twig' %} | ||
|
||
{% block title %}Hello DashboardController!{% endblock %} | ||
|
||
{% block body %} | ||
<style> | ||
.example-wrapper { margin: 1em auto; max-width: 800px; width: 95%; font: 18px/1.5 sans-serif; } | ||
.example-wrapper code { background: #F5F5F5; padding: 2px 6px; } | ||
</style> | ||
|
||
<div class="example-wrapper"> | ||
<h1>Hello {{ controller_name }}! ✅</h1> | ||
|
||
This friendly message is coming from: | ||
<ul> | ||
<li>Your controller at <code><a href="{{ '/var/www/symfony/src/Controller/DashboardController.php'|file_link(0) }}">src/Controller/DashboardController.php</a></code></li> | ||
<li>Your template at <code><a href="{{ '/var/www/symfony/templates/dashboard/index.html.twig'|file_link(0) }}">templates/dashboard/index.html.twig</a></code></li> | ||
</ul> | ||
</div> | ||
{% endblock %} |
Oops, something went wrong.