From 4a4687d4811fe9eee6f88d3007d29c3fc1578300 Mon Sep 17 00:00:00 2001 From: jelassiahmed <47889856+jelassiahmed@users.noreply.github.com> Date: Thu, 4 Mar 2021 00:43:56 +0100 Subject: [PATCH 1/7] Add files via upload initial commit + integrated template + working create and read --- migrations/Version20210303130124.php | 35 ++++ src/Controller/GerantController.php | 45 ++++ src/Controller/HomeController.php | 10 +- src/Entity/Gerant.php | 116 +++++++++++ src/Form/GerantType.php | 30 +++ src/Kernel.php | 2 - src/Repository/GerantRepository.php | 50 +++++ templates/base.html.twig | 282 +++++++++++--------------- templates/gerant/addGerant.html.twig | 80 ++++++++ templates/gerant/index.html.twig | 20 ++ templates/gerant/listGerant.html.twig | 36 ++++ templates/home/index.html.twig | 30 +++ 12 files changed, 569 insertions(+), 167 deletions(-) create mode 100644 migrations/Version20210303130124.php create mode 100644 src/Controller/GerantController.php create mode 100644 src/Entity/Gerant.php create mode 100644 src/Form/GerantType.php create mode 100644 src/Repository/GerantRepository.php create mode 100644 templates/gerant/addGerant.html.twig create mode 100644 templates/gerant/index.html.twig create mode 100644 templates/gerant/listGerant.html.twig create mode 100644 templates/home/index.html.twig diff --git a/migrations/Version20210303130124.php b/migrations/Version20210303130124.php new file mode 100644 index 0000000..e3054ed --- /dev/null +++ b/migrations/Version20210303130124.php @@ -0,0 +1,35 @@ +abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.'); + + $this->addSql('CREATE TABLE gerant (id_gerant VARCHAR(16) NOT NULL, nom VARCHAR(10) NOT NULL, prenom VARCHAR(10) NOT NULL, date_nais DATE NOT NULL, ad_email VARCHAR(50) NOT NULL, cin VARCHAR(8) NOT NULL, PRIMARY KEY(id_gerant)) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE = InnoDB'); + } + + public function down(Schema $schema) : void + { + // this down() migration is auto-generated, please modify it to your needs + $this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.'); + + $this->addSql('DROP TABLE gerant'); + } +} diff --git a/src/Controller/GerantController.php b/src/Controller/GerantController.php new file mode 100644 index 0000000..7cb995a --- /dev/null +++ b/src/Controller/GerantController.php @@ -0,0 +1,45 @@ +getDoctrine()->getRepository(Gerant::class)->findAll(); + return $this->render('gerant/listGerant.html.twig', array('gerants' => $gerants)); + } + + /** + * @return Response + * @Route ("/add",name="addGerant") + */ + public function addGerant(Request $request){ + $gerant=new Gerant(); + $form=$this->createForm(GerantType::class,$gerant); + $form->add('ajouter',SubmitType::class,['attr'=> + ['class'=>'btn_3']]); + $form->handleRequest($request); + if($form->isSubmitted()){ + $em=$this->getDoctrine()->getManager(); + $em->persist($gerant); + $em->flush(); + return $this->redirectToRoute('gerant'); + } + return $this->render("gerant/addGerant.html.twig",['form'=>$form->createView()]); + } + public function showGerant(){ + + } +} diff --git a/src/Controller/HomeController.php b/src/Controller/HomeController.php index e3dedc9..365ae8e 100644 --- a/src/Controller/HomeController.php +++ b/src/Controller/HomeController.php @@ -8,16 +8,12 @@ class HomeController extends AbstractController { - - - - /** - * @Route("/test", name="test") + * @Route("/", name="home") */ - public function test(): Response + public function index(): Response { - return $this->render('test.html.twig', [ + return $this->render('home/index.html.twig', [ 'controller_name' => 'HomeController', ]); } diff --git a/src/Entity/Gerant.php b/src/Entity/Gerant.php new file mode 100644 index 0000000..ba6b50a --- /dev/null +++ b/src/Entity/Gerant.php @@ -0,0 +1,116 @@ +Id_gerant; + } + + public function setIdGerant(string $Id_gerant): self + { + $this->Id_gerant = $Id_gerant; + + return $this; + } + + 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 getDateNais(): ?\DateTimeInterface + { + return $this->Date_nais; + } + + public function setDateNais(\DateTimeInterface $Date_nais): self + { + $this->Date_nais = $Date_nais; + + return $this; + } + + public function getAdEmail(): ?string + { + return $this->Ad_Email; + } + + public function setAdEmail(string $Ad_Email): self + { + $this->Ad_Email = $Ad_Email; + + return $this; + } + + public function getCin(): ?string + { + return $this->Cin; + } + + public function setCin(string $Cin): self + { + $this->Cin = $Cin; + + return $this; + } +} diff --git a/src/Form/GerantType.php b/src/Form/GerantType.php new file mode 100644 index 0000000..4fadc7a --- /dev/null +++ b/src/Form/GerantType.php @@ -0,0 +1,30 @@ +add('Id_gerant') + ->add('Nom') + ->add('Prenom') + ->add('Date_nais') + ->add('Ad_Email') + ->add('Cin') + ; + } + + public function configureOptions(OptionsResolver $resolver) + { + $resolver->setDefaults([ + 'data_class' => Gerant::class, + ]); + } +} diff --git a/src/Kernel.php b/src/Kernel.php index ee3343b..1cd0572 100644 --- a/src/Kernel.php +++ b/src/Kernel.php @@ -23,8 +23,6 @@ public function registerBundles(): iterable yield new $class(); } } - - } public function getProjectDir(): string diff --git a/src/Repository/GerantRepository.php b/src/Repository/GerantRepository.php new file mode 100644 index 0000000..164505c --- /dev/null +++ b/src/Repository/GerantRepository.php @@ -0,0 +1,50 @@ +createQueryBuilder('g') + ->andWhere('g.exampleField = :val') + ->setParameter('val', $value) + ->orderBy('g.id', 'ASC') + ->setMaxResults(10) + ->getQuery() + ->getResult() + ; + } + */ + + /* + public function findOneBySomeField($value): ?Gerant + { + return $this->createQueryBuilder('g') + ->andWhere('g.exampleField = :val') + ->setParameter('val', $value) + ->getQuery() + ->getOneOrNullResult() + ; + } + */ +} diff --git a/templates/base.html.twig b/templates/base.html.twig index b7365fa..9102023 100644 --- a/templates/base.html.twig +++ b/templates/base.html.twig @@ -1,175 +1,94 @@ - + - {% block title %}Welcome!{% endblock %} + {% block title %} {% endblock %} - - {% block stylesheets %} - - {#{{ encore_entry_link_tags('app') }}#} - - - - - - - - - - - - - - - - - {% endblock %} - - {% block javascripts %} - - - - - {% endblock %} + + + + + + + + + + + + + + - {% block preloader %} {% endblock preloader %} -
- {% block header %} -
-
-
-
- {% block body %} - - - - {% endblock %} - -{% block scripts %} - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - {% endblock scripts %} + + {% endblock %} + {% block content %} - - + {% endblock %} + {% block js %} +
+
+
+
+
+ +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + {% endblock %} + + + diff --git a/templates/gerant/addGerant.html.twig b/templates/gerant/addGerant.html.twig new file mode 100644 index 0000000..4d6c7a2 --- /dev/null +++ b/templates/gerant/addGerant.html.twig @@ -0,0 +1,80 @@ +{# {{ form(form) }}#} +{% extends 'base.html.twig' %} + {% block title%} BestHost | Ajout Gérant {% endblock title %} +{% block content %} +
+ +
+
+
+
+
+
+

Ajout Gérant

+
+
+
+
+
+
+ + +
+
+
+ + + +
+
+ +
+ + +
+
+
+
+
+ +
+
+
+{{ form_end(form) }} +{% endblock %} \ No newline at end of file diff --git a/templates/gerant/index.html.twig b/templates/gerant/index.html.twig new file mode 100644 index 0000000..1afd365 --- /dev/null +++ b/templates/gerant/index.html.twig @@ -0,0 +1,20 @@ +{% extends 'base.html.twig' %} + +{% block title %}Hello GerantController!{% endblock %} + +{% block body %} + + +
+

Hello {{ controller_name }}! ✅

+ + This friendly message is coming from: + +
+{% endblock %} diff --git a/templates/gerant/listGerant.html.twig b/templates/gerant/listGerant.html.twig new file mode 100644 index 0000000..02f83f7 --- /dev/null +++ b/templates/gerant/listGerant.html.twig @@ -0,0 +1,36 @@ +{% extends 'base.html.twig' %} + {% block title%} BestHost | Liste Gérant {% endblock title %} +{% block content %} + {% if gerants %} + + + + + + + + + + {% for gerant in gerants %} + + + + + {% endfor %} + +
Les gérantsActions

{{ gerant.Nom }}

+

{{ gerant.Prenom }}

+

{{ gerant.Cin }}

+
+ Edit + Delete +
+{% else %} +

No articles to display

+ {% endif %} +{% endblock %} + +{% block javascripts %} + +{% endblock %} + diff --git a/templates/home/index.html.twig b/templates/home/index.html.twig new file mode 100644 index 0000000..5869d67 --- /dev/null +++ b/templates/home/index.html.twig @@ -0,0 +1,30 @@ +{% extends 'base.html.twig' %} +{% block title %} +Homepage +{% endblock %} +{% block content %} +
+
+ +
+
+
+
+
+

Select Your New Perfect Style

+

Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat is aute irure.

+ +
+ Shop Now +
+
+
+
+
+ +
+
+
+
+
+{% endblock %} \ No newline at end of file From 4fb63bc6bf397687f9352e916db03b24daa0a54e Mon Sep 17 00:00:00 2001 From: jelassiahmed <47889856+jelassiahmed@users.noreply.github.com> Date: Thu, 4 Mar 2021 16:13:35 +0100 Subject: [PATCH 2/7] Add files via upload MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit CRUD completed for both gérant and activity +validator completed + template integrated --- migrations/Version20210304133126.php | 36 ++++++ src/Controller/ActivityController.php | 99 ++++++++++++++++ src/Controller/GerantController.php | 96 +++++++++++---- src/Entity/Activity.php | 137 ++++++++++++++++++++++ src/Entity/Gerant.php | 56 +++++++++ src/Form/ActivityType.php | 30 +++++ src/Form/Gerant1Type.php | 30 +++++ src/Repository/ActivityRepository.php | 50 ++++++++ templates/activity/_delete_form.html.twig | 5 + templates/activity/_form.html.twig | 43 +++++++ templates/activity/edit.html.twig | 13 ++ templates/activity/index.html.twig | 43 +++++++ templates/activity/new.html.twig | 11 ++ templates/activity/show.html.twig | 42 +++++++ templates/base.html.twig | 22 ++-- templates/gerant/_delete_form.html.twig | 5 + templates/gerant/_form.html.twig | 46 ++++++++ templates/gerant/edit.html.twig | 25 ++++ templates/gerant/index.html.twig | 51 +++++--- templates/gerant/new.html.twig | 11 ++ templates/gerant/show.html.twig | 42 +++++++ 21 files changed, 848 insertions(+), 45 deletions(-) create mode 100644 migrations/Version20210304133126.php create mode 100644 src/Controller/ActivityController.php create mode 100644 src/Entity/Activity.php create mode 100644 src/Form/ActivityType.php create mode 100644 src/Form/Gerant1Type.php create mode 100644 src/Repository/ActivityRepository.php create mode 100644 templates/activity/_delete_form.html.twig create mode 100644 templates/activity/_form.html.twig create mode 100644 templates/activity/edit.html.twig create mode 100644 templates/activity/index.html.twig create mode 100644 templates/activity/new.html.twig create mode 100644 templates/activity/show.html.twig create mode 100644 templates/gerant/_delete_form.html.twig create mode 100644 templates/gerant/_form.html.twig create mode 100644 templates/gerant/edit.html.twig create mode 100644 templates/gerant/new.html.twig create mode 100644 templates/gerant/show.html.twig diff --git a/migrations/Version20210304133126.php b/migrations/Version20210304133126.php new file mode 100644 index 0000000..de977e2 --- /dev/null +++ b/migrations/Version20210304133126.php @@ -0,0 +1,36 @@ +abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.'); + + $this->addSql('CREATE TABLE activity (id INT AUTO_INCREMENT NOT NULL, id_act VARCHAR(16) NOT NULL, type VARCHAR(16) NOT NULL, description VARCHAR(255) DEFAULT NULL, date_val DATE NOT NULL, categorie VARCHAR(255) NOT NULL, Id_gerant VARCHAR(16) NOT NULL, INDEX IDX_AC74095A75126B3E (Id_gerant), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE = InnoDB'); + $this->addSql('ALTER TABLE activity ADD CONSTRAINT FK_AC74095A75126B3E FOREIGN KEY (Id_gerant) REFERENCES gerant (Id_gerant)'); + } + + public function down(Schema $schema) : void + { + // this down() migration is auto-generated, please modify it to your needs + $this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.'); + + $this->addSql('DROP TABLE activity'); + } +} diff --git a/src/Controller/ActivityController.php b/src/Controller/ActivityController.php new file mode 100644 index 0000000..b1d795b --- /dev/null +++ b/src/Controller/ActivityController.php @@ -0,0 +1,99 @@ +render('activity/index.html.twig', [ + 'activities' => $activityRepository->findAll(), + ]); + } + + /** + * @Route("/new", name="activity_new", methods={"GET","POST"}) + */ + public function new(Request $request): Response + { + $activity = new Activity(); + $form = $this->createForm(ActivityType::class, $activity); + $form->add('ajouter',SubmitType::class,['attr'=> + ['class'=>'btn_3']]); + $form->handleRequest($request); + + if ($form->isSubmitted() && $form->isValid()) { + $entityManager = $this->getDoctrine()->getManager(); + $entityManager->persist($activity); + $entityManager->flush(); + + return $this->redirectToRoute('activity_index'); + } + + return $this->render('activity/new.html.twig', [ + 'activity' => $activity, + 'form' => $form->createView(), + ]); + } + + /** + * @Route("/{id}", name="activity_show", methods={"GET"}) + */ + public function show(Activity $activity): Response + { + return $this->render('activity/show.html.twig', [ + 'activity' => $activity, + ]); + } + + /** + * @Route("/{id}/edit", name="activity_edit", methods={"GET","POST"}) + */ + public function edit(Request $request, Activity $activity): Response + { + $form = $this->createForm(ActivityType::class, $activity); + $form->add('Modifier',SubmitType::class,['attr'=> + ['class'=>'btn_3']]); + $form->handleRequest($request); + + if ($form->isSubmitted() && $form->isValid()) { + $this->getDoctrine()->getManager()->flush(); + + return $this->redirectToRoute('activity_index'); + } + + return $this->render('activity/edit.html.twig', [ + 'activity' => $activity, + 'form' => $form->createView(), + ]); + } + + /** + * @Route("/{id}", name="activity_delete", methods={"DELETE"}) + */ + public function delete(Request $request, Activity $activity): Response + { + if ($this->isCsrfTokenValid('delete'.$activity->getId(), $request->request->get('_token'))) { + $entityManager = $this->getDoctrine()->getManager(); + $entityManager->remove($activity); + $entityManager->flush(); + } + + return $this->redirectToRoute('activity_index'); + } +} diff --git a/src/Controller/GerantController.php b/src/Controller/GerantController.php index 7cb995a..2015b5b 100644 --- a/src/Controller/GerantController.php +++ b/src/Controller/GerantController.php @@ -1,45 +1,101 @@ getDoctrine()->getRepository(Gerant::class)->findAll(); - return $this->render('gerant/listGerant.html.twig', array('gerants' => $gerants)); + return $this->render('gerant/index.html.twig', [ + 'gerants' => $gerantRepository->findAll(), + ]); } /** - * @return Response - * @Route ("/add",name="addGerant") + * @Route("/new", name="gerant_new", methods={"GET","POST"}) */ - public function addGerant(Request $request){ - $gerant=new Gerant(); - $form=$this->createForm(GerantType::class,$gerant); + public function new(Request $request): Response + { + $gerant = new Gerant(); + $form = $this->createForm(Gerant1Type::class, $gerant); $form->add('ajouter',SubmitType::class,['attr'=> - ['class'=>'btn_3']]); + ['class'=>'btn_3']]); + $form->handleRequest($request); + + if ($form->isSubmitted() && $form->isValid()) { + $entityManager = $this->getDoctrine()->getManager(); + $entityManager->persist($gerant); + $entityManager->flush(); + + return $this->redirectToRoute('gerant_index'); + } + + return $this->render('gerant/new.html.twig', [ + 'gerant' => $gerant, + 'form' => $form->createView(), + ]); + } + + /** + * @Route("/{Id_gerant}", name="gerant_show", methods={"GET"}) + */ + public function show(Gerant $gerant): Response + { + return $this->render('gerant/show.html.twig', [ + 'gerant' => $gerant, + ]); + } + + /** + * @Route("/edit/{Id_gerant}", name="gerant_edit", methods={"GET","POST"}) + */ + + + + + public function edit(Request $request, Gerant $gerant): Response + { + $form = $this->createForm(Gerant1Type::class, $gerant); + $form->add('Modifier',SubmitType::class,['attr'=> + ['class'=>'btn_3']]); $form->handleRequest($request); - if($form->isSubmitted()){ - $em=$this->getDoctrine()->getManager(); - $em->persist($gerant); - $em->flush(); - return $this->redirectToRoute('gerant'); + + if ($form->isSubmitted() && $form->isValid()) { + $this->getDoctrine()->getManager()->flush(); + + return $this->redirectToRoute('gerant_index'); } - return $this->render("gerant/addGerant.html.twig",['form'=>$form->createView()]); + + return $this->render('gerant/edit.html.twig', [ + 'gerant' => $gerant, + 'form' => $form->createView(), + ]); } - public function showGerant(){ + /** + * @Route("/{Id_gerant}", name="gerant_delete", methods={"DELETE"}) + */ + public function delete(Request $request, Gerant $gerant): Response + { + if ($this->isCsrfTokenValid('delete'.$gerant->getIdgerant(), $request->request->get('_token'))) { + $entityManager = $this->getDoctrine()->getManager(); + $entityManager->remove($gerant); + $entityManager->flush(); + } + + return $this->redirectToRoute('gerant_index'); } } diff --git a/src/Entity/Activity.php b/src/Entity/Activity.php new file mode 100644 index 0000000..67e8a0d --- /dev/null +++ b/src/Entity/Activity.php @@ -0,0 +1,137 @@ +id; + } + + public function getIdAct(): ?string + { + return $this->Id_act; + } + + public function setIdAct(string $Id_act): self + { + $this->Id_act = $Id_act; + + return $this; + } + + public function getType(): ?string + { + return $this->Type; + } + + public function setType(string $Type): self + { + $this->Type = $Type; + + return $this; + } + + public function getDescription(): ?string + { + return $this->Description; + } + + public function setDescription(?string $Description): self + { + $this->Description = $Description; + + return $this; + } + + public function getDateVal(): ?\DateTimeInterface + { + return $this->Date_val; + } + + public function setDateVal(\DateTimeInterface $Date_val): self + { + $this->Date_val = $Date_val; + + return $this; + } + + public function getCategorie(): ?string + { + return $this->Categorie; + } + + public function setCategorie(string $Categorie): self + { + $this->Categorie = $Categorie; + + return $this; + } + + public function getGerant(): ?Gerant + { + return $this->gerant; + } + + public function setGerant(?Gerant $gerant): self + { + $this->gerant = $gerant; + + return $this; + } +} + diff --git a/src/Entity/Gerant.php b/src/Entity/Gerant.php index ba6b50a..85f6e4b 100644 --- a/src/Entity/Gerant.php +++ b/src/Entity/Gerant.php @@ -3,7 +3,10 @@ namespace App\Entity; use App\Repository\GerantRepository; +use Doctrine\Common\Collections\ArrayCollection; +use Doctrine\Common\Collections\Collection; use Doctrine\ORM\Mapping as ORM; +use Symfony\Component\Validator\Constraints as Assert; /** * @ORM\Entity(repositoryClass=GerantRepository::class) @@ -13,34 +16,53 @@ class Gerant /** * @ORM\Id * @ORM\Column(type="string", length=16) + * @Assert\NotBlank(message="REQUIRED") */ private $Id_gerant; /** * @ORM\Column(type="string", length=10) + * @Assert\NotBlank(message="REQUIRED") */ private $Nom; /** * @ORM\Column(type="string", length=10) + * @Assert\NotBlank(message="REQUIRED") */ private $Prenom; /** * @ORM\Column(type="date") + * @Assert\NotBlank(message="REQUIRED") */ private $Date_nais; /** * @ORM\Column(type="string", length=50) + * @Assert\NotBlank(message="REQUIRED") + * @Assert\Date() */ private $Ad_Email; /** * @ORM\Column(type="string", length=8) + * @Assert\NotBlank(message="REQUIRED") + * @Assert\Email(message="Email {{value}} is not validmessage="REQUIRED"") */ private $Cin; + /** + * @ORM\OneToMany(targetEntity=Activity::class, mappedBy="gerant", orphanRemoval=true) + * @Assert\NotBlank(message="REQUIRED") + */ + private $Activity; + + public function __construct() + { + $this->Activity = new ArrayCollection(); + } + public function getIdGerant(): ?string { @@ -113,4 +135,38 @@ public function setCin(string $Cin): self return $this; } + + /** + * @return Collection|Activity[] + */ + public function getActivity(): Collection + { + return $this->Activity; + } + + public function addActivity(Activity $activity): self + { + if (!$this->Activity->contains($activity)) { + $this->Activity[] = $activity; + $activity->setGerant($this); + } + + return $this; + } + + public function removeActivity(Activity $activity): self + { + if ($this->Activity->removeElement($activity)) { + // set the owning side to null (unless already changed) + if ($activity->getGerant() === $this) { + $activity->setGerant(null); + } + } + + return $this; + } + public function __toString() + { + return $this->Id_gerant; + } } diff --git a/src/Form/ActivityType.php b/src/Form/ActivityType.php new file mode 100644 index 0000000..2a7cf18 --- /dev/null +++ b/src/Form/ActivityType.php @@ -0,0 +1,30 @@ +add('Id_act') + ->add('Type') + ->add('Description') + ->add('Date_val') + ->add('Categorie') + ->add('gerant') + ; + } + + public function configureOptions(OptionsResolver $resolver) + { + $resolver->setDefaults([ + 'data_class' => Activity::class, + ]); + } +} diff --git a/src/Form/Gerant1Type.php b/src/Form/Gerant1Type.php new file mode 100644 index 0000000..fdfea6c --- /dev/null +++ b/src/Form/Gerant1Type.php @@ -0,0 +1,30 @@ +add('Id_gerant') + ->add('Nom') + ->add('Prenom') + ->add('Date_nais') + ->add('Ad_Email') + ->add('Cin') + ; + } + + public function configureOptions(OptionsResolver $resolver) + { + $resolver->setDefaults([ + 'data_class' => Gerant::class, + ]); + } +} diff --git a/src/Repository/ActivityRepository.php b/src/Repository/ActivityRepository.php new file mode 100644 index 0000000..836ca6e --- /dev/null +++ b/src/Repository/ActivityRepository.php @@ -0,0 +1,50 @@ +createQueryBuilder('a') + ->andWhere('a.exampleField = :val') + ->setParameter('val', $value) + ->orderBy('a.id', 'ASC') + ->setMaxResults(10) + ->getQuery() + ->getResult() + ; + } + */ + + /* + public function findOneBySomeField($value): ?Activity + { + return $this->createQueryBuilder('a') + ->andWhere('a.exampleField = :val') + ->setParameter('val', $value) + ->getQuery() + ->getOneOrNullResult() + ; + } + */ +} diff --git a/templates/activity/_delete_form.html.twig b/templates/activity/_delete_form.html.twig new file mode 100644 index 0000000..fb940af --- /dev/null +++ b/templates/activity/_delete_form.html.twig @@ -0,0 +1,5 @@ +
+ + + +
diff --git a/templates/activity/_form.html.twig b/templates/activity/_form.html.twig new file mode 100644 index 0000000..47579d3 --- /dev/null +++ b/templates/activity/_form.html.twig @@ -0,0 +1,43 @@ + diff --git a/templates/activity/edit.html.twig b/templates/activity/edit.html.twig new file mode 100644 index 0000000..d2cdcc1 --- /dev/null +++ b/templates/activity/edit.html.twig @@ -0,0 +1,13 @@ +{% extends 'base.html.twig' %} + +{% block title %}Edit Activity{% endblock %} + +{% block content %} +

Edit Activity

+ + {{ include('activity/_form.html.twig', {'button_label': 'Update'}) }} + + back to list + + {{ include('activity/_delete_form.html.twig') }} +{% endblock %} diff --git a/templates/activity/index.html.twig b/templates/activity/index.html.twig new file mode 100644 index 0000000..4433bfb --- /dev/null +++ b/templates/activity/index.html.twig @@ -0,0 +1,43 @@ +{% extends 'base.html.twig' %} + +{% block title %}Activity index{% endblock %} + +{% block content %} +

Activity index

+ + + + + + + + + + + + + + + {% for activity in activities %} + + + + + + + + + + {% else %} + + + + {% endfor %} + +
IdId_actTypeDescriptionDate_valCategorieactions
{{ activity.id }}{{ activity.IdAct }}{{ activity.Type }}{{ activity.Description }}{{ activity.DateVal ? activity.DateVal|date('Y-m-d') : '' }}{{ activity.Categorie }} + show + edit +
no records found
+ + Create new +{% endblock %} diff --git a/templates/activity/new.html.twig b/templates/activity/new.html.twig new file mode 100644 index 0000000..10e7a5f --- /dev/null +++ b/templates/activity/new.html.twig @@ -0,0 +1,11 @@ +{% extends 'base.html.twig' %} + +{% block title %}New Activity{% endblock %} + +{% block content %} +

Create new Activity

+ + {{ include('activity/_form.html.twig') }} + + back to list +{% endblock %} diff --git a/templates/activity/show.html.twig b/templates/activity/show.html.twig new file mode 100644 index 0000000..2a7c3bb --- /dev/null +++ b/templates/activity/show.html.twig @@ -0,0 +1,42 @@ +{% extends 'base.html.twig' %} + +{% block title %}Activity{% endblock %} + +{% block content %} +

Activity

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Id{{ activity.id }}
Id_act{{ activity.IdAct }}
Type{{ activity.Type }}
Description{{ activity.Description }}
Date_val{{ activity.DateVal ? activity.DateVal|date('Y-m-d') : '' }}
Categorie{{ activity.Categorie }}
+ + back to list + + edit + + {{ include('activity/_delete_form.html.twig') }} +{% endblock %} diff --git a/templates/base.html.twig b/templates/base.html.twig index 9102023..7bc75ed 100644 --- a/templates/base.html.twig +++ b/templates/base.html.twig @@ -10,17 +10,17 @@ - - - - - - - - - - - + + + + + + + + + + + {% block header %} diff --git a/templates/gerant/_delete_form.html.twig b/templates/gerant/_delete_form.html.twig new file mode 100644 index 0000000..145497a --- /dev/null +++ b/templates/gerant/_delete_form.html.twig @@ -0,0 +1,5 @@ +
+ + + +
diff --git a/templates/gerant/_form.html.twig b/templates/gerant/_form.html.twig new file mode 100644 index 0000000..ce801ba --- /dev/null +++ b/templates/gerant/_form.html.twig @@ -0,0 +1,46 @@ + + \ No newline at end of file diff --git a/templates/gerant/edit.html.twig b/templates/gerant/edit.html.twig new file mode 100644 index 0000000..c3b36b2 --- /dev/null +++ b/templates/gerant/edit.html.twig @@ -0,0 +1,25 @@ + + {% extends 'base.html.twig' %} + + {% block title %}Edit Gerant{% endblock %} + {% block head %} + + + + + + + + + + + + {% endblock %} + + {% block content %} +

Edit Gerant

+ + {{ include('gerant/_form.html.twig',{'button_label': 'Update'}) }} + + back to list + {% endblock %} diff --git a/templates/gerant/index.html.twig b/templates/gerant/index.html.twig index 1afd365..bd1ea6f 100644 --- a/templates/gerant/index.html.twig +++ b/templates/gerant/index.html.twig @@ -1,20 +1,43 @@ {% extends 'base.html.twig' %} -{% block title %}Hello GerantController!{% endblock %} +{% block title %}Gerant index{% endblock %} -{% block body %} - +{% block content %} +

Gerant index

-
-

Hello {{ controller_name }}! ✅

+ + + + + + + + + + + + + + {% for gerant in gerants %} + + + + + + + + + + {% else %} + + + + {% endfor %} + +
Id_gerantNomPrenomDate_naisAd_EmailCinactions
{{ gerant.IdGerant }}{{ gerant.Nom }}{{ gerant.Prenom }}{{ gerant.DateNais ? gerant.DateNais|date('Y-m-d') : '' }}{{ gerant.AdEmail }}{{ gerant.Cin }} + show + edit +
no records found
- This friendly message is coming from: - -
+ Create new {% endblock %} diff --git a/templates/gerant/new.html.twig b/templates/gerant/new.html.twig new file mode 100644 index 0000000..16ed3f9 --- /dev/null +++ b/templates/gerant/new.html.twig @@ -0,0 +1,11 @@ +{% extends 'base.html.twig' %} + +{% block title %}New Gerant{% endblock %} + +{% block content %} +

Create new Gerant

+ + {{ include('gerant/_form.html.twig') }} + + back to list +{% endblock %} diff --git a/templates/gerant/show.html.twig b/templates/gerant/show.html.twig new file mode 100644 index 0000000..b46209e --- /dev/null +++ b/templates/gerant/show.html.twig @@ -0,0 +1,42 @@ +{% extends 'base.html.twig' %} + +{% block title %}Gerant{% endblock %} + +{% block content %} +

Gerant

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Id_gerant{{ gerant.IdGerant }}
Nom{{ gerant.Nom }}
Prenom{{ gerant.Prenom }}
Date_nais{{ gerant.DateNais ? gerant.DateNais|date('Y-m-d') : '' }}
Ad_Email{{ gerant.AdEmail }}
Cin{{ gerant.Cin }}
+ + back to list + + edit + + {{ include('gerant/_delete_form.html.twig') }} +{% endblock %} From 578653cf16eddc2d85da4adb73ad46fd3fa083a8 Mon Sep 17 00:00:00 2001 From: jelassiahmed <47889856+jelassiahmed@users.noreply.github.com> Date: Fri, 12 Mar 2021 01:28:22 +0100 Subject: [PATCH 3/7] Add files via upload Added like/dislike button + pdf generator + printer --- src/Controller/ActivityController.php | 139 ++++++++++++++++ src/Controller/GerantController.php | 88 +++++++++- src/Controller/LoginAuthController.php | 36 +++++ src/Controller/UserController.php | 94 +++++++++++ src/DataFixtures/AppFixtures.php | 63 ++++++++ src/Entity/ActLike.php | 58 +++++++ src/Entity/Activity.php | 60 ++++++- src/Entity/Gerant.php | 3 +- src/Entity/User.php | 205 ++++++++---------------- src/Form/RatingType.php | 42 +++++ src/Form/UserType.php | 27 ++++ src/Kernel.php | 4 +- src/Repository/ActLikeRepository.php | 51 ++++++ src/Repository/UserRepository.php | 19 ++- src/Security/LoginAuthAuthenticator.php | 107 +++++++++++++ 15 files changed, 843 insertions(+), 153 deletions(-) create mode 100644 src/Controller/LoginAuthController.php create mode 100644 src/Controller/UserController.php create mode 100644 src/DataFixtures/AppFixtures.php create mode 100644 src/Entity/ActLike.php create mode 100644 src/Form/RatingType.php create mode 100644 src/Form/UserType.php create mode 100644 src/Repository/ActLikeRepository.php create mode 100644 src/Security/LoginAuthAuthenticator.php diff --git a/src/Controller/ActivityController.php b/src/Controller/ActivityController.php index b1d795b..d415f05 100644 --- a/src/Controller/ActivityController.php +++ b/src/Controller/ActivityController.php @@ -3,13 +3,19 @@ namespace App\Controller; use App\Entity\Activity; +use App\Entity\ActLike; use App\Form\ActivityType; use App\Repository\ActivityRepository; +use Doctrine\Persistence\ObjectManager; 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\Component\Routing\Annotation\Route; +use App\Repository\ActLikeRepository; +use Doctrine\ORM\EntityManagerInterface; +use Dompdf\Dompdf; +use Dompdf\Options; /** * @Route("/activity") @@ -24,6 +30,18 @@ public function index(ActivityRepository $activityRepository): Response return $this->render('activity/index.html.twig', [ 'activities' => $activityRepository->findAll(), ]); + } + /** + * @Route("/user", name="activity_user") + */ + public function user(ActivityRepository $activityRepository): Response + { + return $this->render('activity/user.html.twig', [ + 'activities' => $activityRepository->findAll(), + ]); + + + } /** @@ -37,6 +55,7 @@ public function new(Request $request): Response ['class'=>'btn_3']]); $form->handleRequest($request); + if ($form->isSubmitted() && $form->isValid()) { $entityManager = $this->getDoctrine()->getManager(); $entityManager->persist($activity); @@ -60,6 +79,15 @@ public function show(Activity $activity): Response 'activity' => $activity, ]); } + /** + * @Route("/user/{id}", name="us_show") + */ + public function usershow(Activity $activity): Response + { + return $this->render('activity/usershow.html.twig', [ + 'activity' => $activity, + ]); + } /** * @Route("/{id}/edit", name="activity_edit", methods={"GET","POST"}) @@ -96,4 +124,115 @@ public function delete(Request $request, Activity $activity): Response return $this->redirectToRoute('activity_index'); } + + /** + * @Route("/activity/{id}/like" , name="act_like") + * @param Activity $activity + * @param EntityManagerInterface $manager + * @param ActLikeRepository $likeRepo + * @return Response + */ +public function like(Activity $activity, EntityManagerInterface $manager , ActLikeRepository $likeRepo) : Response +{ + $user = $this->getUser(); + if(!$user) return $this->redirectToRoute('app_login'); + + if($activity->isLikedByUser($user)){ + $like = $likeRepo->findOneBy([ + 'post' => $activity, + 'user'=> $user]); + $manager->remove($like); + $manager->flush(); + return $this->redirectToRoute('activity_user'); + } + $like = new ActLike(); + $like->setPost($activity) + ->setUser($user); + $manager->persist($like); + $manager->flush(); + + return $this->redirectToRoute('activity_user'); + +} + /** + * @Route("/recherche", name="recherche") + */ + public function searchAction(Request $request) + { + + $data = $request->request->get('search'); + + + $em = $this->getDoctrine()->getManager(); + $query = $em->createQuery('SELECT e FROM App\Entity\Activity e WHERE e.Id_act LIKE :data') + ->setParameter('data', '%'.$data.'%'); + + + $events = $query->getResult(); + + return $this->render('activity/index.html.twig', [ + 'activities' => $events, + ]); + } + /** + * @Route("/tri", name="tri") + */ + public function TriAction(Request $request) + { + + + + + $em = $this->getDoctrine()->getManager(); + $query = $em->createQuery( + 'SELECT e FROM App\Entity\Activity e + ORDER BY e.Id_act '); + + + + $candidats = $query->getResult(); + + return $this->render('activity/index.html.twig', array( + 'activities' => $candidats)); + + } + + /** + * @Route("/list/{id}", name="activity_list", methods={"GET"}) + */ + public function listp(Activity $produits) : Response + { +// Configure Dompdf according to your needs + $pdfOptions = new Options(); + $pdfOptions->set('defaultFont', 'Arial'); + + // Instantiate Dompdf with our options + $dompdf = new Dompdf($pdfOptions); + + + // Retrieve the HTML generated in our twig file + $html = $this->renderView('activity/list.html.twig', [ + 'activity' =>$produits, + ]); + + $html .= ''; + + // Load HTML to Dompdf + $dompdf->loadHtml($html); + + // (Optional) Setup the paper size and orientation 'portrait' or 'portrait' + $dompdf->setPaper('A4', 'portrait'); + + // Render the HTML as PDF + $dompdf->render(); + + // Output the generated PDF to Browser (force download) + $dompdf->stream("mypdf.pdf", [ + "Attachment" => true + ]); + + + + } + } diff --git a/src/Controller/GerantController.php b/src/Controller/GerantController.php index 2015b5b..b2caeb0 100644 --- a/src/Controller/GerantController.php +++ b/src/Controller/GerantController.php @@ -10,8 +10,12 @@ use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Annotation\Route; +use Dompdf\Dompdf; +use Dompdf\Options; - +/** + * @Route("/gerant") + */ class GerantController extends AbstractController { /** @@ -63,9 +67,6 @@ public function show(Gerant $gerant): Response * @Route("/edit/{Id_gerant}", name="gerant_edit", methods={"GET","POST"}) */ - - - public function edit(Request $request, Gerant $gerant): Response { $form = $this->createForm(Gerant1Type::class, $gerant); @@ -98,4 +99,83 @@ public function delete(Request $request, Gerant $gerant): Response return $this->redirectToRoute('gerant_index'); } + /** + * @Route("/list/{Id_gerant}", name="gerant_list", methods={"GET"}) + */ + public function listp(Gerant $produits) : Response + { +// Configure Dompdf according to your needs + $pdfOptions = new Options(); + $pdfOptions->set('defaultFont', 'Arial'); + + // Instantiate Dompdf with our options + $dompdf = new Dompdf($pdfOptions); + + + // Retrieve the HTML generated in our twig file + $html = $this->renderView('gerant/list.html.twig', [ + 'gerant' =>$produits, + ]); + + $html .= ''; + + // Load HTML to Dompdf + $dompdf->loadHtml($html); + + // (Optional) Setup the paper size and orientation 'portrait' or 'portrait' + $dompdf->setPaper('A4', 'portrait'); + + // Render the HTML as PDF + $dompdf->render(); + + // Output the generated PDF to Browser (force download) + $dompdf->stream("mypdf.pdf", [ + "Attachment" => false + ]); + + + + } + /** + * @Route("/tri", name="tri_g") + */ + public function TriAction(Request $request) + { + + + + + $em = $this->getDoctrine()->getManager(); + $query = $em->createQuery( + 'SELECT e FROM App\Entity\Gerant e + ORDER BY e.Id_gerant '); + + + + $candidats = $query->getResult(); + + return $this->render('gerant/index.html.twig', array( + 'gerants' => $candidats)); + + } + /** + * @Route("/recherche", name="recherche_g") + */ + public function searchAction(Request $request) + { + + $data = $request->request->get('search'); + + + $em = $this->getDoctrine()->getManager(); + $query = $em->createQuery('SELECT e FROM App\Entity\Gerant e WHERE e.Id_gerant LIKE :data') + ->setParameter('data', '%'.$data.'%'); + + + $events = $query->getResult(); + + return $this->render('gerant/index.html.twig', [ + 'gerants' => $events, + ]); + } } diff --git a/src/Controller/LoginAuthController.php b/src/Controller/LoginAuthController.php new file mode 100644 index 0000000..ca46c0c --- /dev/null +++ b/src/Controller/LoginAuthController.php @@ -0,0 +1,36 @@ +getUser()) { + // return $this->redirectToRoute('target_path'); + // } + + // get the login error if there is one + $error = $authenticationUtils->getLastAuthenticationError(); + // last username entered by the user + $lastUsername = $authenticationUtils->getLastUsername(); + + return $this->render('security/login.html.twig', ['last_username' => $lastUsername, 'error' => $error]); + } + + /** + * @Route("/user/logout", name="app_logout") + */ + public function logout() + { + throw new \LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.'); + } +} diff --git a/src/Controller/UserController.php b/src/Controller/UserController.php new file mode 100644 index 0000000..831d651 --- /dev/null +++ b/src/Controller/UserController.php @@ -0,0 +1,94 @@ +render('user/index.html.twig', [ + 'users' => $userRepository->findAll(), + ]); + } + + /** + * @Route("/new", name="user_new", methods={"GET","POST"}) + */ + public function new(Request $request): Response + { + $user = new User(); + $form = $this->createForm(UserType::class, $user); + $form->handleRequest($request); + + if ($form->isSubmitted() && $form->isValid()) { + $entityManager = $this->getDoctrine()->getManager(); + $entityManager->persist($user); + $entityManager->flush(); + + return $this->redirectToRoute('user_index'); + } + + return $this->render('user/new.html.twig', [ + 'user' => $user, + 'form' => $form->createView(), + ]); + } + + /** + * @Route("/{id}", name="user_show", methods={"GET"}) + */ + public function show(User $user): Response + { + return $this->render('user/show.html.twig', [ + 'user' => $user, + ]); + } + + /** + * @Route("/{id}/edit", name="user_edit", methods={"GET","POST"}) + */ + public function edit(Request $request, User $user): Response + { + $form = $this->createForm(UserType::class, $user); + $form->handleRequest($request); + + if ($form->isSubmitted() && $form->isValid()) { + $this->getDoctrine()->getManager()->flush(); + + return $this->redirectToRoute('user_index'); + } + + return $this->render('user/edit.html.twig', [ + 'user' => $user, + 'form' => $form->createView(), + ]); + } + + /** + * @Route("/{id}", name="user_delete", methods={"DELETE"}) + */ + public function delete(Request $request, User $user): Response + { + if ($this->isCsrfTokenValid('delete'.$user->getId(), $request->request->get('_token'))) { + $entityManager = $this->getDoctrine()->getManager(); + $entityManager->remove($user); + $entityManager->flush(); + } + + return $this->redirectToRoute('user_index'); + } +} diff --git a/src/DataFixtures/AppFixtures.php b/src/DataFixtures/AppFixtures.php new file mode 100644 index 0000000..92ccc7e --- /dev/null +++ b/src/DataFixtures/AppFixtures.php @@ -0,0 +1,63 @@ +encoder = $encoder; + } + + public function load(ObjectManager $manager) + { + $faker = Factory::create(); + $users=[]; + $user = new User(); + $user->setEmail('user@symfony.com') + ->setPassword($this->encoder->encodePassword($user, 'password')); + + $manager->persist($user); + $users[] = $user; + for($i = 0; $i<20;$i++) + { + $user = new User(); + $user->setEmail($faker->email) + ->setPassword($this->encoder->encodePassword($user,'password')); + $manager->persist($user); + $users[] = $user; + } + for ($i = 0; $i < 20; $i++) { + $post = new Activity(); + $post->setIdAct($faker->word) + ->setDescription($faker->paragraph()) + ->setCategorie($faker->sentence(1))->setType($faker->word); + + $manager->persist($post); + for($j=0; $j<10; $j++) + { + $like = new ActLike(); + $like->setPost($post) + ->setUser($faker->randomElement($users)); + $manager->persist($like); + } + } + + $manager->flush(); + } +} \ No newline at end of file diff --git a/src/Entity/ActLike.php b/src/Entity/ActLike.php new file mode 100644 index 0000000..13e1dde --- /dev/null +++ b/src/Entity/ActLike.php @@ -0,0 +1,58 @@ +id; + } + + public function getPost(): ?Activity + { + return $this->post; + } + + public function setPost(?Activity $post): self + { + $this->post = $post; + + return $this; + } + + public function getUser(): ?User + { + return $this->user; + } + + public function setUser(?User $user): self + { + $this->user = $user; + + return $this; + } +} diff --git a/src/Entity/Activity.php b/src/Entity/Activity.php index 67e8a0d..50a333c 100644 --- a/src/Entity/Activity.php +++ b/src/Entity/Activity.php @@ -1,10 +1,14 @@ Likes = new ArrayCollection(); + } + public function getId(): ?int { return $this->id; @@ -133,5 +146,48 @@ public function setGerant(?Gerant $gerant): self return $this; } + + /** + * @return Collection|ActLike[] + */ + public function getLikes(): Collection + { + return $this->Likes; + } + + public function addLike(ActLike $like): self + { + if (!$this->Likes->contains($like)) { + $this->Likes[] = $like; + $like->setPost($this); + } + + return $this; + } + + public function removeLike(ActLike $like): self + { + if ($this->Likes->removeElement($like)) { + // set the owning side to null (unless already changed) + if ($like->getPost() === $this) { + $like->setPost(null); + } + } + + return $this; + } + + /** + * @param User $user + * @return bool + */ + public function isLikedByUser(User $user) : bool + { + foreach ($this->Likes as $like){ + if($like->getUser() === $user) return true; + } + return false; + + } } diff --git a/src/Entity/Gerant.php b/src/Entity/Gerant.php index 85f6e4b..8d63fd2 100644 --- a/src/Entity/Gerant.php +++ b/src/Entity/Gerant.php @@ -41,14 +41,13 @@ class Gerant /** * @ORM\Column(type="string", length=50) * @Assert\NotBlank(message="REQUIRED") - * @Assert\Date() + * @Assert\Email(message="Email {{value}} is not validmessage=REQUIRED") */ private $Ad_Email; /** * @ORM\Column(type="string", length=8) * @Assert\NotBlank(message="REQUIRED") - * @Assert\Email(message="Email {{value}} is not validmessage="REQUIRED"") */ private $Cin; diff --git a/src/Entity/User.php b/src/Entity/User.php index 57fd32e..065582c 100644 --- a/src/Entity/User.php +++ b/src/Entity/User.php @@ -3,22 +3,15 @@ namespace App\Entity; use App\Repository\UserRepository; -use DateTime; +use Doctrine\Common\Collections\ArrayCollection; +use Doctrine\Common\Collections\Collection; use Doctrine\ORM\Mapping as ORM; -use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; use Symfony\Component\Security\Core\User\UserInterface; -use Symfony\Component\Validator\Constraints as Assert; - /** * @ORM\Entity(repositoryClass=UserRepository::class) - * @ORM\Table(name="`user`") - * @UniqueEntity( - * fields={"email"}, - * message="email existant" - * ) */ -class User implements UserInterface +class User implements UserInterface { /** * @ORM\Id @@ -27,70 +20,32 @@ class User implements UserInterface */ private $id; - - /** - * @ORM\Column(type="string", length=255) - * + * @ORM\Column(type="string", length=180, unique=true) */ private $email; /** - * @ORM\Column(type="string", length=255, nullable=true) - */ - private $first_name; - - /** - * @ORM\Column(type="string", length=255, nullable=true) - */ - private $last_name; - - /** - * @ORM\Column(type="string", length=255) - * @Assert\Length(min="8",minMessage="Password needs to be at least 8 characters long") - * - **/ - private $password; - /** - * @Assert\EqualTo (propertyPath="password",message="password mismatch") - * - */ - private $confirm_password; - - /** - * @ORM\Column(type="string", nullable=true,length=255) - */ - private $google_id; - - /** - * @ORM\Column(type="string", length=255, nullable=true) - */ - private $avatar; - - /** - * @ORM\Column(type="json", nullable=true) + * @ORM\Column(type="json") */ private $roles = []; /** - * @ORM\Column(type="integer", nullable=true) + * @var string The hashed password + * @ORM\Column(type="string") */ - private $cin; + private $password; /** - * @ORM\Column(type="datetime") + * @ORM\OneToMany(targetEntity=ActLike::class, mappedBy="user") */ - private $created_at; - + private $likes; public function __construct() { - $this->created_at=DateTime::createFromFormat('d-m-Y H:i:s','now'); + $this->likes = new ArrayCollection(); } - - - public function getId(): ?int { return $this->id; @@ -108,33 +63,41 @@ public function setEmail(string $email): self return $this; } - public function getFirstName(): ?string + /** + * A visual identifier that represents this user. + * + * @see UserInterface + */ + public function getUsername(): string { - return $this->first_name; + return (string) $this->email; } - public function setFirstName(?string $first_name): self + /** + * @see UserInterface + */ + public function getRoles(): array { - $this->first_name = $first_name; - - return $this; - } + $roles = $this->roles; + // guarantee every user at least has ROLE_USER + $roles[] = 'ROLE_USER'; - public function getLastName(): ?string - { - return $this->last_name; + return array_unique($roles); } - public function setLastName(?string $last_name): self + public function setRoles(array $roles): self { - $this->last_name = $last_name; + $this->roles = $roles; return $this; } - public function getPassword(): ?string + /** + * @see UserInterface + */ + public function getPassword(): string { - return $this->password; + return (string) $this->password; } public function setPassword(string $password): self @@ -144,95 +107,53 @@ public function setPassword(string $password): self return $this; } - public function getGoogleId(): ?string - { - return $this->google_id; - } - - public function setGoogleId(?string $google_id): self - { - $this->google_id = $google_id; - - return $this; - } - - public function getConfirmPassword():?string - { - return $this->confirm_password; - } - public function getAvatar(): ?string - { - return $this->avatar; - } - - public function setAvatar(?string $avatar): self - { - $this->avatar = $avatar; - - return $this; - } - public function getCin(): ?int - { - return $this->cin; - } - - public function setCin(?int $cin): self - { - $this->cin = $cin; - - return $this; - } - - public function setConfirmPassword(?string $confirm_password):self - { - $this->confirm_password=$confirm_password; - return $this; - } - - - public function getSalt() - { - // TODO: Implement getSalt() method. - } - - public function getUsername() + /** + * Returning a salt is only needed, if you are not using a modern + * hashing algorithm (e.g. bcrypt or sodium) in your security.yaml. + * + * @see UserInterface + */ + public function getSalt(): ?string { - return $this->email; + return null; } + /** + * @see UserInterface + */ public function eraseCredentials() { - // TODO: Implement eraseCredentials() method. + // If you store any temporary, sensitive data on the user, clear it here + // $this->plainPassword = null; } - - public function getRoles():array + /** + * @return Collection|ActLike[] + */ + public function getLikes(): Collection { - $roles = $this->roles; - - - return array_unique($roles); + return $this->likes; } - public function setRoles(?array $roles): self + public function addLike(ActLike $like): self { - $this->roles = $roles; + if (!$this->likes->contains($like)) { + $this->likes[] = $like; + $like->setUser($this); + } return $this; } - public function getCreatedAt(): ?\DateTimeInterface + public function removeLike(ActLike $like): self { - return $this->created_at; - } - - public function setCreatedAt(\DateTimeInterface $created_at): self - { - $this->created_at = $created_at; + if ($this->likes->removeElement($like)) { + // set the owning side to null (unless already changed) + if ($like->getUser() === $this) { + $like->setUser(null); + } + } return $this; } - - - } diff --git a/src/Form/RatingType.php b/src/Form/RatingType.php new file mode 100644 index 0000000..bab6ccf --- /dev/null +++ b/src/Form/RatingType.php @@ -0,0 +1,42 @@ +vars = array_replace($view->vars, [ + 'stars' => $options['stars'] + ]); + } + + public function configureOptions(OptionsResolver $resolver) + { + $resolver->setDefaults([ + 'attr' => [ + 'class' => 'rating', + ], + 'scale' => 1, + 'stars' => 5, + ]); + } + + public function getParent() + { + return NumberType::class; + } + + public function getName() + { + return 'rating'; + } + +} \ No newline at end of file diff --git a/src/Form/UserType.php b/src/Form/UserType.php new file mode 100644 index 0000000..b227d1d --- /dev/null +++ b/src/Form/UserType.php @@ -0,0 +1,27 @@ +add('email') + ->add('roles') + ->add('password') + ; + } + + public function configureOptions(OptionsResolver $resolver) + { + $resolver->setDefaults([ + 'data_class' => User::class, + ]); + } +} diff --git a/src/Kernel.php b/src/Kernel.php index 1cd0572..41a2607 100644 --- a/src/Kernel.php +++ b/src/Kernel.php @@ -1,14 +1,12 @@ import($confDir.'/{routes}/*'.self::CONFIG_EXTS, '/', 'glob'); $routes->import($confDir.'/{routes}'.self::CONFIG_EXTS, '/', 'glob'); } + } diff --git a/src/Repository/ActLikeRepository.php b/src/Repository/ActLikeRepository.php new file mode 100644 index 0000000..aad4a97 --- /dev/null +++ b/src/Repository/ActLikeRepository.php @@ -0,0 +1,51 @@ +createQueryBuilder('a') + ->andWhere('a.exampleField = :val') + ->setParameter('val', $value) + ->orderBy('a.id', 'ASC') + ->setMaxResults(10) + ->getQuery() + ->getResult() + ; + } + */ + + /* + public function findOneBySomeField($value): ?ActLike + { + return $this->createQueryBuilder('a') + ->andWhere('a.exampleField = :val') + ->setParameter('val', $value) + ->getQuery() + ->getOneOrNullResult() + ; + } + */ +} diff --git a/src/Repository/UserRepository.php b/src/Repository/UserRepository.php index 2ebc111..1a38975 100644 --- a/src/Repository/UserRepository.php +++ b/src/Repository/UserRepository.php @@ -5,6 +5,9 @@ use App\Entity\User; use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; use Doctrine\Persistence\ManagerRegistry; +use Symfony\Component\Security\Core\Exception\UnsupportedUserException; +use Symfony\Component\Security\Core\User\PasswordUpgraderInterface; +use Symfony\Component\Security\Core\User\UserInterface; /** * @method User|null find($id, $lockMode = null, $lockVersion = null) @@ -12,13 +15,27 @@ * @method User[] findAll() * @method User[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) */ -class UserRepository extends ServiceEntityRepository +class UserRepository extends ServiceEntityRepository implements PasswordUpgraderInterface { public function __construct(ManagerRegistry $registry) { parent::__construct($registry, User::class); } + /** + * Used to upgrade (rehash) the user's password automatically over time. + */ + public function upgradePassword(UserInterface $user, string $newEncodedPassword): void + { + if (!$user instanceof User) { + throw new UnsupportedUserException(sprintf('Instances of "%s" are not supported.', \get_class($user))); + } + + $user->setPassword($newEncodedPassword); + $this->_em->persist($user); + $this->_em->flush(); + } + // /** // * @return User[] Returns an array of User objects // */ diff --git a/src/Security/LoginAuthAuthenticator.php b/src/Security/LoginAuthAuthenticator.php new file mode 100644 index 0000000..1824490 --- /dev/null +++ b/src/Security/LoginAuthAuthenticator.php @@ -0,0 +1,107 @@ +entityManager = $entityManager; + $this->urlGenerator = $urlGenerator; + $this->csrfTokenManager = $csrfTokenManager; + $this->passwordEncoder = $passwordEncoder; + } + + public function supports(Request $request) + { + return self::LOGIN_ROUTE === $request->attributes->get('_route') + && $request->isMethod('POST'); + } + + public function getCredentials(Request $request) + { + $credentials = [ + 'email' => $request->request->get('email'), + 'password' => $request->request->get('password'), + 'csrf_token' => $request->request->get('_csrf_token'), + ]; + $request->getSession()->set( + Security::LAST_USERNAME, + $credentials['email'] + ); + + return $credentials; + } + + public function getUser($credentials, UserProviderInterface $userProvider) + { + $token = new CsrfToken('authenticate', $credentials['csrf_token']); + if (!$this->csrfTokenManager->isTokenValid($token)) { + throw new InvalidCsrfTokenException(); + } + + $user = $this->entityManager->getRepository(User::class)->findOneBy(['email' => $credentials['email']]); + + if (!$user) { + // fail authentication with a custom error + throw new CustomUserMessageAuthenticationException('Email could not be found.'); + } + + return $user; + } + + public function checkCredentials($credentials, UserInterface $user) + { + return $this->passwordEncoder->isPasswordValid($user, $credentials['password']); + } + + /** + * Used to upgrade (rehash) the user's password automatically over time. + */ + public function getPassword($credentials): ?string + { + return $credentials['password']; + } + + public function onAuthenticationSuccess(Request $request, TokenInterface $token, $providerKey) + { + if ($targetPath = $this->getTargetPath($request->getSession(), $providerKey)) { + return new RedirectResponse($targetPath); + } + + return new RedirectResponse($this->urlGenerator->generate('activity_user')); + throw new \Exception('TODO: provide a valid redirect inside '.__FILE__); + } + + protected function getLoginUrl() + { + return $this->urlGenerator->generate(self::LOGIN_ROUTE); + } +} From 0f5b1f7cf6662ebaa38385be94645bcd698852c4 Mon Sep 17 00:00:00 2001 From: jelassiahmed <47889856+jelassiahmed@users.noreply.github.com> Date: Fri, 12 Mar 2021 01:30:19 +0100 Subject: [PATCH 4/7] Add files via upload fixed some icons + added fake user to test like button --- templates/activity/_form.html.twig | 2 +- templates/activity/edit.html.twig | 2 +- templates/activity/index.html.twig | 21 +- templates/activity/list.html.twig | 31 + templates/activity/new.html.twig | 2 +- templates/activity/pdf.html.twig | 9 + templates/activity/show.html.twig | 5 +- templates/activity/user.html.twig | 77 +++ templates/activity/usershow.html.twig | 39 ++ templates/back.html.twig | 874 ++++++++++++++++++++++++++ templates/base.html.twig | 61 +- templates/gerant/_form.html.twig | 1 - templates/gerant/addGerant.html.twig | 2 +- templates/gerant/edit.html.twig | 4 +- templates/gerant/index.html.twig | 22 +- templates/gerant/list.html.twig | 30 + templates/gerant/new.html.twig | 4 +- templates/gerant/show.html.twig | 8 +- templates/security/login.html.twig | 40 ++ 19 files changed, 1188 insertions(+), 46 deletions(-) create mode 100644 templates/activity/list.html.twig create mode 100644 templates/activity/pdf.html.twig create mode 100644 templates/activity/user.html.twig create mode 100644 templates/activity/usershow.html.twig create mode 100644 templates/back.html.twig create mode 100644 templates/gerant/list.html.twig create mode 100644 templates/security/login.html.twig diff --git a/templates/activity/_form.html.twig b/templates/activity/_form.html.twig index 47579d3..de30751 100644 --- a/templates/activity/_form.html.twig +++ b/templates/activity/_form.html.twig @@ -21,7 +21,7 @@
{{ form_label(form.Date_val,"Date de validité") }} {{ form_errors(form.Date_val) }} - {{form_widget(form.Date_val,{ 'attr':{'placeholder':'Date de validité', 'class':'Datetype' }})}} + {{form_widget(form.Date_val,{ 'attr':{'placeholder':'Date de validité' }})}}
{{ form_errors(form.Categorie) }} diff --git a/templates/activity/edit.html.twig b/templates/activity/edit.html.twig index d2cdcc1..d6d9a5c 100644 --- a/templates/activity/edit.html.twig +++ b/templates/activity/edit.html.twig @@ -1,4 +1,4 @@ -{% extends 'base.html.twig' %} +{% extends 'back.html.twig' %} {% block title %}Edit Activity{% endblock %} diff --git a/templates/activity/index.html.twig b/templates/activity/index.html.twig index 4433bfb..8438715 100644 --- a/templates/activity/index.html.twig +++ b/templates/activity/index.html.twig @@ -1,10 +1,27 @@ -{% extends 'base.html.twig' %} +{% extends 'back.html.twig' %} {% block title %}Activity index{% endblock %} {% block content %}

Activity index

+ + @@ -39,5 +56,7 @@
+ Create new {% endblock %} + diff --git a/templates/activity/list.html.twig b/templates/activity/list.html.twig new file mode 100644 index 0000000..ba95ca9 --- /dev/null +++ b/templates/activity/list.html.twig @@ -0,0 +1,31 @@ + +

Activity

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Id{{ activity.id }}
Id_act{{ activity.IdAct }}
Type{{ activity.Type }}
Description{{ activity.Description }}
Date_val{{ activity.DateVal ? activity.DateVal|date('Y-m-d') : '' }}
Categorie{{ activity.Categorie }}
diff --git a/templates/activity/new.html.twig b/templates/activity/new.html.twig index 10e7a5f..239248d 100644 --- a/templates/activity/new.html.twig +++ b/templates/activity/new.html.twig @@ -1,4 +1,4 @@ -{% extends 'base.html.twig' %} +{% extends 'back.html.twig' %} {% block title %}New Activity{% endblock %} diff --git a/templates/activity/pdf.html.twig b/templates/activity/pdf.html.twig new file mode 100644 index 0000000..5c00739 --- /dev/null +++ b/templates/activity/pdf.html.twig @@ -0,0 +1,9 @@ + + + + Title of the PDF + + +

{{ title }}

+

Lorem Ipsum

+ diff --git a/templates/activity/show.html.twig b/templates/activity/show.html.twig index 2a7c3bb..00ce941 100644 --- a/templates/activity/show.html.twig +++ b/templates/activity/show.html.twig @@ -1,10 +1,9 @@ -{% extends 'base.html.twig' %} +{% extends 'back.html.twig' %} {% block title %}Activity{% endblock %} {% block content %}

Activity

- @@ -37,6 +36,8 @@ back to listedit + Download pdf + {{ include('activity/_delete_form.html.twig') }} {% endblock %} diff --git a/templates/activity/user.html.twig b/templates/activity/user.html.twig new file mode 100644 index 0000000..e13e7b8 --- /dev/null +++ b/templates/activity/user.html.twig @@ -0,0 +1,77 @@ +{% extends 'base.html.twig' %} + + {% block title %}Activity index{% endblock %} + +{% block content %} +

Activity index

+ + + {% for activity in activities %} + + + {% else %} + + + + + {% endfor %} + + + + Create new +{% endblock %} + +{% block js %} + + + +{% endblock %} \ No newline at end of file diff --git a/templates/activity/usershow.html.twig b/templates/activity/usershow.html.twig new file mode 100644 index 0000000..eb12e41 --- /dev/null +++ b/templates/activity/usershow.html.twig @@ -0,0 +1,39 @@ +{% extends 'base.html.twig' %} + +{% block title %}Activity{% endblock %} + +{% block content %} +

Activity

+ +
no records found
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Id{{ activity.id }}
Id_act{{ activity.IdAct }}
Type{{ activity.Type }}
Description{{ activity.Description }}
Date_val{{ activity.DateVal ? activity.DateVal|date('Y-m-d') : '' }}
Categorie{{ activity.Categorie }}
+ + back to list + +{% endblock %} diff --git a/templates/back.html.twig b/templates/back.html.twig new file mode 100644 index 0000000..abadbe8 --- /dev/null +++ b/templates/back.html.twig @@ -0,0 +1,874 @@ + + + + + + {% block title %} {% endblock %} + + + + + + + + + + +{% block header %} +
+ AdminLTELogo +
+ + + + + + + + + + + + +{% endblock %} +{% block content %} +{% endblock %} +{% block footer %} + Copyright © 2014-2021 AdminLTE.io. + All rights reserved. +
+ Version 3.1.0-rc +
+{% endblock %} +{% block js %} + + + + + + + + + + + + + + + + + + + + + + +{% endblock %} + + \ No newline at end of file diff --git a/templates/base.html.twig b/templates/base.html.twig index 7bc75ed..6667132 100644 --- a/templates/base.html.twig +++ b/templates/base.html.twig @@ -6,10 +6,12 @@ {% block title %} {% endblock %} - - + + + + @@ -30,15 +32,14 @@ @@ -97,7 +98,7 @@