diff --git a/README.md b/README.md index 2a5e744..2b7b46e 100644 --- a/README.md +++ b/README.md @@ -25,4 +25,12 @@ npm install bootstrap npm install bootstrap-icons # Modifier asset/app.js et config/package/twig.yaml npm run dev -``` \ No newline at end of file +``` + +### Question 2 +```bash +symfony console doctrine:database:create # Création de la base de donnée +symfony console make:entity Atelier # Création d'une entité Atelier +symfony console make:migration # Création d'une migration +symfony console doctrine:migrations:migrate # On lance la migration +``` diff --git a/migrations/Version20230206163633.php b/migrations/Version20230206163633.php new file mode 100644 index 0000000..229ac97 --- /dev/null +++ b/migrations/Version20230206163633.php @@ -0,0 +1,36 @@ +addSql('CREATE TABLE atelier (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, nom VARCHAR(255) NOT NULL, description VARCHAR(1024) DEFAULT NULL)'); + $this->addSql('CREATE TABLE messenger_messages (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, body CLOB NOT NULL, headers CLOB NOT NULL, queue_name VARCHAR(190) NOT NULL, created_at DATETIME NOT NULL, available_at DATETIME NOT NULL, delivered_at DATETIME DEFAULT NULL)'); + $this->addSql('CREATE INDEX IDX_75EA56E0FB7336F0 ON messenger_messages (queue_name)'); + $this->addSql('CREATE INDEX IDX_75EA56E0E3BD61CE ON messenger_messages (available_at)'); + $this->addSql('CREATE INDEX IDX_75EA56E016BA31DB ON messenger_messages (delivered_at)'); + } + + public function down(Schema $schema): void + { + // this down() migration is auto-generated, please modify it to your needs + $this->addSql('DROP TABLE atelier'); + $this->addSql('DROP TABLE messenger_messages'); + } +} diff --git a/src/Entity/Atelier.php b/src/Entity/Atelier.php new file mode 100644 index 0000000..1f2c31f --- /dev/null +++ b/src/Entity/Atelier.php @@ -0,0 +1,50 @@ +id; + } + + public function getNom(): ?string + { + return $this->nom; + } + + public function setNom(string $nom): self + { + $this->nom = $nom; + + return $this; + } + + public function getDescription(): ?string + { + return $this->description; + } + + public function setDescription(?string $description): self + { + $this->description = $description; + + return $this; + } +} diff --git a/src/Repository/AtelierRepository.php b/src/Repository/AtelierRepository.php new file mode 100644 index 0000000..079567b --- /dev/null +++ b/src/Repository/AtelierRepository.php @@ -0,0 +1,66 @@ + + * + * @method Atelier|null find($id, $lockMode = null, $lockVersion = null) + * @method Atelier|null findOneBy(array $criteria, array $orderBy = null) + * @method Atelier[] findAll() + * @method Atelier[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) + */ +class AtelierRepository extends ServiceEntityRepository +{ + public function __construct(ManagerRegistry $registry) + { + parent::__construct($registry, Atelier::class); + } + + public function save(Atelier $entity, bool $flush = false): void + { + $this->getEntityManager()->persist($entity); + + if ($flush) { + $this->getEntityManager()->flush(); + } + } + + public function remove(Atelier $entity, bool $flush = false): void + { + $this->getEntityManager()->remove($entity); + + if ($flush) { + $this->getEntityManager()->flush(); + } + } + +// /** +// * @return Atelier[] Returns an array of Atelier objects +// */ +// public function findByExampleField($value): array +// { +// return $this->createQueryBuilder('a') +// ->andWhere('a.exampleField = :val') +// ->setParameter('val', $value) +// ->orderBy('a.id', 'ASC') +// ->setMaxResults(10) +// ->getQuery() +// ->getResult() +// ; +// } + +// public function findOneBySomeField($value): ?Atelier +// { +// return $this->createQueryBuilder('a') +// ->andWhere('a.exampleField = :val') +// ->setParameter('val', $value) +// ->getQuery() +// ->getOneOrNullResult() +// ; +// } +}