diff --git a/migrations/Version20230403161503.php b/migrations/Version20230403161503.php index b6fab8a..7f04fb1 100644 --- a/migrations/Version20230403161503.php +++ b/migrations/Version20230403161503.php @@ -20,14 +20,12 @@ final class Version20230403161503 extends AbstractMigration public function up(Schema $schema): void { // this up() migration is auto-generated, please modify it to your needs - $this->addSql('CREATE TABLE email (id INT AUTO_INCREMENT NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); $this->addSql('ALTER TABLE user ADD name VARCHAR(255) NOT NULL, ADD email VARCHAR(255) NOT NULL'); } public function down(Schema $schema): void { // this down() migration is auto-generated, please modify it to your needs - $this->addSql('DROP TABLE email'); $this->addSql('ALTER TABLE `user` DROP name, DROP email'); } } diff --git a/migrations/Version20230403214405.php b/migrations/Version20230403214405.php new file mode 100644 index 0000000..3eb82a5 --- /dev/null +++ b/migrations/Version20230403214405.php @@ -0,0 +1,35 @@ +addSql('CREATE TABLE snip (id INT AUTO_INCREMENT NOT NULL, created_by_id INT NOT NULL, name VARCHAR(255) NOT NULL, created_at DATETIME NOT NULL, INDEX IDX_FEBD9796B03A8386 (created_by_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); + $this->addSql('ALTER TABLE snip ADD CONSTRAINT FK_FEBD9796B03A8386 FOREIGN KEY (created_by_id) REFERENCES `user` (id)'); + $this->addSql('DROP TABLE email'); + } + + public function down(Schema $schema): void + { + // this down() migration is auto-generated, please modify it to your needs + $this->addSql('CREATE TABLE email (id INT AUTO_INCREMENT NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB COMMENT = \'\' '); + $this->addSql('ALTER TABLE snip DROP FOREIGN KEY FK_FEBD9796B03A8386'); + $this->addSql('DROP TABLE snip'); + } +} diff --git a/src/Controller/HomeController.php b/src/Controller/HomeController.php index 8bab2e8..6f017e8 100644 --- a/src/Controller/HomeController.php +++ b/src/Controller/HomeController.php @@ -11,9 +11,9 @@ class HomeController extends AbstractController #[Route('/', name: 'home')] public function home(): Response { - return $this->redirectToRoute('task_view'); -// return $this->render('simple.html.twig', [ -// 'text' => 'Welcome!' -// ]); +// return $this->redirectToRoute('task_view'); + return $this->render('simple.html.twig', [ + 'text' => 'Welcome!' + ]); } } \ No newline at end of file diff --git a/src/Controller/SnipController.php b/src/Controller/SnipController.php new file mode 100644 index 0000000..1d23559 --- /dev/null +++ b/src/Controller/SnipController.php @@ -0,0 +1,29 @@ +render('snip/index.html.twig', [ + 'snips' => $repository->findAll(), + ]); + } + + #[Route('/singe/{snip}', name: '_single')] + public function single(Snip $snip): Response + { + return $this->render('snip/single.html.twig', [ + 'snip' => $snip, + ]); + } +} \ No newline at end of file diff --git a/src/Entity/.gitignore b/src/Entity/.gitignore deleted file mode 100644 index e69de29..0000000 diff --git a/src/Entity/Email.php b/src/Entity/Email.php deleted file mode 100644 index ca5d18c..0000000 --- a/src/Entity/Email.php +++ /dev/null @@ -1,20 +0,0 @@ -id; - } -} diff --git a/src/Entity/Helpers/EnableableTrait.php b/src/Entity/Helpers/EnableableTrait.php new file mode 100644 index 0000000..24981c4 --- /dev/null +++ b/src/Entity/Helpers/EnableableTrait.php @@ -0,0 +1,22 @@ + true])] + private bool $enabled = true; + + public function isEnabled(): bool + { + return $this->enabled; + } + + public function setEnabled(bool $enabled): static + { + $this->enabled = $enabled; + return $this; + } +} \ No newline at end of file diff --git a/src/Entity/Helpers/TrackedTrait.php b/src/Entity/Helpers/TrackedTrait.php new file mode 100644 index 0000000..88d6ce6 --- /dev/null +++ b/src/Entity/Helpers/TrackedTrait.php @@ -0,0 +1,54 @@ +createdBy; + } + + public function setCreatedBy(?User $createdBy): self + { + $this->createdBy = $createdBy; + + return $this; + } + + public function getCreatedAt(): ?DateTime + { + return $this->createdAt; + } + + public function setCreatedAt(DateTime $createdAt): self + { + $this->createdAt = $createdAt; + + return $this; + } + + public function getCode(): string + { + return date_format($this->createdAt, "ymd"); + } + + public function setCreatedAtTodayNoSeconds(): self + { + $this->setCreatedAt(DateTime::createFromFormat('Y-m-d H:i', date('Y-m-d H:i'))); + + return $this; + } +} \ No newline at end of file diff --git a/src/Entity/Snip.php b/src/Entity/Snip.php new file mode 100644 index 0000000..b3d8f9c --- /dev/null +++ b/src/Entity/Snip.php @@ -0,0 +1,38 @@ +id; + } + + public function getName(): ?string + { + return $this->name; + } + + public function setName(string $name): self + { + $this->name = $name; + + return $this; + } +} diff --git a/src/Form/SnipType.php b/src/Form/SnipType.php new file mode 100644 index 0000000..10494dc --- /dev/null +++ b/src/Form/SnipType.php @@ -0,0 +1,27 @@ +add('name') + ->add('createdAt') + ->add('createdBy') + ; + } + + public function configureOptions(OptionsResolver $resolver): void + { + $resolver->setDefaults([ + 'data_class' => Snip::class, + ]); + } +} diff --git a/src/Repository/SnipRepository.php b/src/Repository/SnipRepository.php new file mode 100644 index 0000000..6255abe --- /dev/null +++ b/src/Repository/SnipRepository.php @@ -0,0 +1,66 @@ + + * + * @method Snip|null find($id, $lockMode = null, $lockVersion = null) + * @method Snip|null findOneBy(array $criteria, array $orderBy = null) + * @method Snip[] findAll() + * @method Snip[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) + */ +class SnipRepository extends ServiceEntityRepository +{ + public function __construct(ManagerRegistry $registry) + { + parent::__construct($registry, Snip::class); + } + + public function save(Snip $entity, bool $flush = false): void + { + $this->getEntityManager()->persist($entity); + + if ($flush) { + $this->getEntityManager()->flush(); + } + } + + public function remove(Snip $entity, bool $flush = false): void + { + $this->getEntityManager()->remove($entity); + + if ($flush) { + $this->getEntityManager()->flush(); + } + } + +// /** +// * @return Snip[] Returns an array of Snip objects +// */ +// public function findByExampleField($value): array +// { +// return $this->createQueryBuilder('s') +// ->andWhere('s.exampleField = :val') +// ->setParameter('val', $value) +// ->orderBy('s.id', 'ASC') +// ->setMaxResults(10) +// ->getQuery() +// ->getResult() +// ; +// } + +// public function findOneBySomeField($value): ?Snip +// { +// return $this->createQueryBuilder('s') +// ->andWhere('s.exampleField = :val') +// ->setParameter('val', $value) +// ->getQuery() +// ->getOneOrNullResult() +// ; +// } +} diff --git a/templates/base/navbar.html.twig b/templates/base/navbar.html.twig index 984f013..2d07348 100644 --- a/templates/base/navbar.html.twig +++ b/templates/base/navbar.html.twig @@ -1,6 +1,6 @@