Skip to content

Commit

Permalink
Modification de la base de donnée
Browse files Browse the repository at this point in the history
  • Loading branch information
Tendry-Rkt56 committed Jul 19, 2024
1 parent 1d01e9b commit cac5b82
Show file tree
Hide file tree
Showing 13 changed files with 90 additions and 35 deletions.
57 changes: 28 additions & 29 deletions pharmacies.sql
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ CREATE TABLE `category` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`nom` varchar(100) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
Expand All @@ -36,13 +36,13 @@ CREATE TABLE `category` (
LOCK TABLES `category` WRITE;
/*!40000 ALTER TABLE `category` DISABLE KEYS */;
INSERT INTO `category` VALUES
(1,'Analgésiques'),
(2,'Antibiotiques '),
(4,'Antihypertenseurs'),
(5,'Antidiabétiques'),
(6,'Suppléments Vitaminiques'),
(7,'Antiviraux '),
(8,'Antihistaminiques');
(8,'Antihistaminiques'),
(9,'Analgésique');
/*!40000 ALTER TABLE `category` ENABLE KEYS */;
UNLOCK TABLES;

Expand All @@ -63,7 +63,7 @@ CREATE TABLE `detail` (
KEY `IDX_2E067F937DC7170A` (`vente_id`),
CONSTRAINT `FK_2E067F937DC7170A` FOREIGN KEY (`vente_id`) REFERENCES `vente` (`id`),
CONSTRAINT `FK_2E067F93AB0D61F7` FOREIGN KEY (`medicament_id`) REFERENCES `medicament` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=28 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
) ENGINE=InnoDB AUTO_INCREMENT=36 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
Expand All @@ -73,15 +73,14 @@ CREATE TABLE `detail` (
LOCK TABLES `detail` WRITE;
/*!40000 ALTER TABLE `detail` DISABLE KEYS */;
INSERT INTO `detail` VALUES
(19,1,8,10),
(20,6,8,10),
(21,1,9,10),
(22,6,9,20),
(23,6,10,2),
(24,4,10,1),
(25,1,11,8),
(26,2,11,8),
(27,1,12,1200);
(28,1,13,5),
(29,6,13,2),
(30,2,13,2),
(31,8,14,12),
(32,9,15,20),
(33,1,15,10000),
(34,6,16,4),
(35,2,16,2);
/*!40000 ALTER TABLE `detail` ENABLE KEYS */;
UNLOCK TABLES;

Expand Down Expand Up @@ -144,14 +143,14 @@ CREATE TABLE `medicament` (
LOCK TABLES `medicament` WRITE;
/*!40000 ALTER TABLE `medicament` DISABLE KEYS */;
INSERT INTO `medicament` VALUES
(1,'Paracétamol',1200,10800,0,1),
(2,'Vitamine D',2500,12000,0,6),
(1,'Paracétamol',1200,10114,0,9),
(2,'Vitamine D',2500,11996,0,6),
(3,'Vitamine C',2600,1200,0,6),
(4,'Amoxilline',1500,1200,0,2),
(6,'Lisinopril',8000,285,1,4),
(8,'Cetirizine',2700,1205,0,8),
(9,'Ciprofloxacine',7000,5800,1,2),
(10,'Metformine',4000,0,1,5);
(6,'Lisinopril',8000,2790,1,4),
(8,'Cetirizine',2700,1193,0,8),
(9,'Ciprofloxacine',7000,5780,1,2),
(10,'Metformine',4000,100001,1,5);
/*!40000 ALTER TABLE `medicament` ENABLE KEYS */;
UNLOCK TABLES;

Expand Down Expand Up @@ -205,7 +204,7 @@ CREATE TABLE `user` (
`telephone` varchar(100) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `UNIQ_IDENTIFIER_EMAIL` (`email`)
) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
) ENGINE=InnoDB AUTO_INCREMENT=12 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
Expand All @@ -215,8 +214,9 @@ CREATE TABLE `user` (
LOCK TABLES `user` WRITE;
/*!40000 ALTER TABLE `user` DISABLE KEYS */;
INSERT INTO `user` VALUES
(1,'[email protected]','[\"ROLE_ADMIN\"]','$2y$13$UijfwyQb/.OB6wpOCOEMTuuTUr4OfrnB7eCG/R0c/JPa7UI4mgSKq','Tendry','Rkt','82549f4e26330467d27cc3e4bbd4026f.jpg','Antananarivo, Ankaraobato','0346413187'),
(5,'[email protected]','[]','$2y$13$3ovIC9WkFs35t7QQktvGV.9gtOO3JiCk1FX0iPPbNqI6l7Zvqoe/O','Eric','','9bb0f4341838119829cc94fae84e23ab.jpg','Mandraka, Mandraka','0321212021');
(9,'[email protected]','[\"ROLE_ADMIN\"]','$2y$13$TnXVAxDhMLXCH6MkBa0xweCDYLo4PtYHDjb4.95dFpLCw/qAkt.yi','admin','01','921ca1b9c33105fcf44d86e6ab2738ba.jpg','Mahamasina, Antananarivo','0341200220'),
(10,'[email protected]','[]','$2y$13$oNgRAz5VoriNU1CfqFCGreR5AO9DNb9MySf/Wa.CvmlMNA6oZr0Na','user','01','21f5fe4ac0143e554ca5e408c684d687.jpg','Dans ton coeur','0331260000'),
(11,'[email protected]','[]','$2y$13$TM5TiZUFpuDvWaD6otFmRuyJ/1ySAwpG.ePgbbPZwOFBqi0KhkOTm','user','02',NULL,'Dans le monde, Terre','0331258545');
/*!40000 ALTER TABLE `user` ENABLE KEYS */;
UNLOCK TABLES;

Expand All @@ -235,7 +235,7 @@ CREATE TABLE `vente` (
PRIMARY KEY (`id`),
KEY `IDX_888A2A4CA76ED395` (`user_id`),
CONSTRAINT `FK_888A2A4CA76ED395` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=13 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
) ENGINE=InnoDB AUTO_INCREMENT=17 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
Expand All @@ -245,11 +245,10 @@ CREATE TABLE `vente` (
LOCK TABLES `vente` WRITE;
/*!40000 ALTER TABLE `vente` DISABLE KEYS */;
INSERT INTO `vente` VALUES
(8,1,92000,'2024-07-19 03:36:05'),
(9,1,172000,'2024-07-19 04:05:27'),
(10,5,17500,'2024-07-19 07:32:39'),
(11,5,29600,'2024-07-19 07:56:08'),
(12,5,1440000,'2024-07-19 08:01:44');
(13,10,27000,'2024-07-19 14:11:16'),
(14,10,32400,'2024-07-19 14:12:33'),
(15,9,12140000,'2024-07-19 14:20:02'),
(16,11,37000,'2024-07-19 14:23:47');
/*!40000 ALTER TABLE `vente` ENABLE KEYS */;
UNLOCK TABLES;
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
Expand All @@ -262,4 +261,4 @@ UNLOCK TABLES;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;

-- Dump completed on 2024-07-19 8:07:27
-- Dump completed on 2024-07-19 14:27:20
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
7 changes: 5 additions & 2 deletions src/Controller/Admin/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
namespace App\Controller\Admin;

use App\Entity\User;
use App\Event\DeleteUserEvent;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
Expand Down Expand Up @@ -106,9 +108,10 @@ public function update (Request $request, UserPasswordHasherInterface $hasher)
}

#[Route('/delete/{id}', name: 'delete', methods: ['POST'])]
public function delete (User $user)
public function delete (User $user, EventDispatcherInterface $dispatcher)
{
$this->deleteImage($user);
$dispatcher->dispatch(new DeleteUserEvent($user));
$this->entity->remove($user);
$this->entity->flush();
$this->addFlash('danger', 'Utilisateur supprimé');
Expand All @@ -126,7 +129,7 @@ public function profil (User $user)
private function deleteImage (User $user): void
{
if ($user->getImage() !== null) {
$path = $this->getParameter('kernel.project_dir').'/public/user/'.$user->getImage();
$path = $this->getParameter('kernel.project_dir').'/public/users/'.$user->getImage();
if (file_exists($path)) {
unlink($path);
}
Expand Down
11 changes: 11 additions & 0 deletions src/Entity/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\ORM\Mapping\HasLifecycleCallbacks;
use Doctrine\ORM\Mapping\PreRemove;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;

#[ORM\Entity(repositoryClass: CategoryRepository::class)]
#[HasLifecycleCallbacks]
#[UniqueEntity('nom', message: 'Ce nom existe déjà')]
class Category
{
Expand Down Expand Up @@ -48,6 +51,14 @@ public function setNom(string $nom): static
return $this;
}

#[PreRemove]
public function preRemove()
{
foreach($this->medicaments as $medicament) {
$medicament->setCategory(null);
}
}

/**
* @return Collection<int, Medicament>
*/
Expand Down
15 changes: 15 additions & 0 deletions src/Event/DeleteUserEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace App\Event;

use App\Entity\User;

class DeleteUserEvent
{

public function __construct (public User $user)
{

}

}
27 changes: 27 additions & 0 deletions src/EventListener/DeleteUserListener.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace App\EventListener;

use App\Entity\Vente;
use App\Event\DeleteUserEvent;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\EventDispatcher\Attribute\AsEventListener;

final class DeleteUserListener
{

public function __construct(private EntityManagerInterface $entity)
{

}

#[AsEventListener(event: DeleteUserEvent::class)]
public function onDeleteUserEvent(DeleteUserEvent $event): void
{
$ventes = $this->entity->getRepository(Vente::class)->findBy(['user' => $event->user->getId()]);
foreach($ventes as $vente) {
$this->entity->remove($vente);
}
$this->entity->flush();
}
}
2 changes: 1 addition & 1 deletion templates/admin.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
{% if is_granted('ROLE_ADMIN') %}
<div class="admins d-flex align-items-center justify-content-center flex-row gap-3">
<a class="liens {{"admin" in app.current_route ? 'active': ''}}" href="{{path('admin.index')}}">Administration</a>
<a class="liens {{"users.index" in app.current_route ? 'active': ''}}" href="{{path('users.index')}}">Utilisateur</a>
<a class="liens {{"users.index" == app.current_route ? 'active': ''}}" href="{{path('users.index')}}">Utilisateur</a>
</div>
{% endif %}

Expand Down
2 changes: 1 addition & 1 deletion templates/admin/user/index.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
<img src="/image/users/{{user.image}}" style="height:30px;width:30px;border-radius:50%" alt="">
{% else %}
<div class="randoms">
<span class="random d-flex align-items-center justify-content-center" style="background:{{color}}">{{ user.nom | slice(0, 1) }}</span>
<span class="random d-flex align-items-center justify-content-center" style="background:{{color}}">{{ user.nom | slice(0, 1) | upper }}</span>
</div>
{% endif %}
</td>
Expand Down
2 changes: 1 addition & 1 deletion templates/user.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
<img src="/image/users/{{app.user.image}}" alt="" />
{% else %}
<div class="randoms">
<span class="random d-flex align-items-center justify-content-center" style="background:{{color}}">{{ app.user.nom | slice(0, 1) }}</span>
<span class="random d-flex align-items-center justify-content-center" style="background:{{color}}">{{ app.user.nom | slice(0, 1) | upper }}</span>
</div>
{% endif %}
<span class="admin_name">{{ app.user.nom }} {{ app.user.prenom }}</span>
Expand Down
2 changes: 1 addition & 1 deletion templates/users/listes/index.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
<img src="/image/users/{{user.image}}" style="height:30px;width:30px;border-radius:50%" alt="">
{% else %}
<div class="randoms">
<span class="random d-flex align-items-center justify-content-center" style="background:{{color}}">{{ user.nom | slice(0, 1) }}</span>
<span class="random d-flex align-items-center justify-content-center" style="background:{{color}}">{{ user.nom | slice(0, 1) | upper }}</span>
</div>
{% endif %}
</td>
Expand Down

0 comments on commit cac5b82

Please sign in to comment.