From dedd507ccdeda5c347b5b9377d8085667b1197d5 Mon Sep 17 00:00:00 2001 From: Destroyeur6315 Date: Fri, 9 Feb 2024 11:19:39 +0100 Subject: [PATCH] :init: --- src/Controller/TweetTokController.php | 40 +++++++++++ src/Entity/Twok.php | 85 +++++++++++++++++++++++ src/Repository/TwokRepository.php | 48 +++++++++++++ src/Service/TwokManager.php | 47 +++++++++++++ templates/broadcast/Twok.stream.html.twig | 22 ++++++ templates/tweet_tok/index.html.twig | 24 +++++++ 6 files changed, 266 insertions(+) create mode 100644 src/Controller/TweetTokController.php create mode 100644 src/Entity/Twok.php create mode 100644 src/Repository/TwokRepository.php create mode 100644 src/Service/TwokManager.php create mode 100644 templates/broadcast/Twok.stream.html.twig create mode 100644 templates/tweet_tok/index.html.twig diff --git a/src/Controller/TweetTokController.php b/src/Controller/TweetTokController.php new file mode 100644 index 0000000..efc74c3 --- /dev/null +++ b/src/Controller/TweetTokController.php @@ -0,0 +1,40 @@ +getTwokByID(37497); + + return $this->render('tweet_tok/index.html.twig', [ + 'controller_name' => 'TweetTokController', + 'author'=> $twok->getAuteur(), + 'content' => $twok->getMessage() + ]); + } + + #[Route('/home/twok', name: 'add_twok')] + public function addTwok(TwokManager $twok_manager): Response + { + $twok = new Twok(10, 'romain', 'L\'instant présent est le plus important. Ne perdons pas notre temps + avec le passé et le futur', '09/02/2024 10:30:33'); + $twok = $twok_manager->addTwok($twok); + + + return $this->render('tweet_tok/index.html.twig', [ + 'controller_name' => 'TweetTokController', + 'author'=> 'test', + 'content' => 'test' + ]); + } +} diff --git a/src/Entity/Twok.php b/src/Entity/Twok.php new file mode 100644 index 0000000..1297312 --- /dev/null +++ b/src/Entity/Twok.php @@ -0,0 +1,85 @@ +id = $id; + $this->auteur = $auteur; + $this->message = $message; + $this->date = $date; + } + + public function getId(): ?int + { + return $this->id; + } + + public function setId(int $id): static + { + $this->id = $id; + + return $this; + } + + public function getAuteur(): ?string + { + return $this->auteur; + } + + public function setAuteur(?string $auteur): static + { + $this->auteur = $auteur; + + return $this; + } + + public function getMessage(): ?string + { + return $this->message; + } + + public function setMessage(?string $message): static + { + $this->message = $message; + + return $this; + } + + public function getDate(): ?string + { + return $this->date; + } + + public function setDate(?string $date): static + { + $this->date = $date; + + return $this; + } +} diff --git a/src/Repository/TwokRepository.php b/src/Repository/TwokRepository.php new file mode 100644 index 0000000..11b4a65 --- /dev/null +++ b/src/Repository/TwokRepository.php @@ -0,0 +1,48 @@ + + * + * @method Twok|null find($id, $lockMode = null, $lockVersion = null) + * @method Twok|null findOneBy(array $criteria, array $orderBy = null) + * @method Twok[] findAll() + * @method Twok[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) + */ +class TwokRepository extends ServiceEntityRepository +{ + public function __construct(ManagerRegistry $registry) + { + parent::__construct($registry, Twok::class); + } + +// /** +// * @return Twok[] Returns an array of Twok objects +// */ +// public function findByExampleField($value): array +// { +// return $this->createQueryBuilder('t') +// ->andWhere('t.exampleField = :val') +// ->setParameter('val', $value) +// ->orderBy('t.id', 'ASC') +// ->setMaxResults(10) +// ->getQuery() +// ->getResult() +// ; +// } + +// public function findOneBySomeField($value): ?Twok +// { +// return $this->createQueryBuilder('t') +// ->andWhere('t.exampleField = :val') +// ->setParameter('val', $value) +// ->getQuery() +// ->getOneOrNullResult() +// ; +// } +} diff --git a/src/Service/TwokManager.php b/src/Service/TwokManager.php new file mode 100644 index 0000000..941dfec --- /dev/null +++ b/src/Service/TwokManager.php @@ -0,0 +1,47 @@ +getAllTwork(); + + foreach ($data as $ligne) { + if ($ligne['id'] == $id) { + $twok = new Twok($ligne['id'], $ligne['author'], $ligne['content'], $ligne['created_at']); + return $twok; + break; + } + } + + return new Twok(0, '', '', ''); + } + + public function addTwok(Twok $my_twok) { + $encoders = [new XmlEncoder(), new JsonEncoder()]; + $normalizers = [new ObjectNormalizer()]; + $serializer = new Serializer($normalizers, $encoders); + + $path = '../var/test.json'; + var_dump($my_twok); + $jsonContent = $serializer->serialize($my_twok, 'json'); + // $jsonString = json_encode($my_twok); + file_put_contents($path, $jsonContent); + } + + public function getAllTwork(): array{ + $path = '../var/twoks_db.json'; + $jsonString = file_get_contents($path); + $jsonData = json_decode($jsonString, true); + return $jsonData; + } + +} diff --git a/templates/broadcast/Twok.stream.html.twig b/templates/broadcast/Twok.stream.html.twig new file mode 100644 index 0000000..f2676e2 --- /dev/null +++ b/templates/broadcast/Twok.stream.html.twig @@ -0,0 +1,22 @@ +{# Learn how to use Turbo Streams: https://github.com/symfony/ux-turbo#broadcast-doctrine-entities-update #} +{% block create %} + + + +{% endblock %} + +{% block update %} + + + +{% endblock %} + +{% block remove %} + +{% endblock %} diff --git a/templates/tweet_tok/index.html.twig b/templates/tweet_tok/index.html.twig new file mode 100644 index 0000000..8863f75 --- /dev/null +++ b/templates/tweet_tok/index.html.twig @@ -0,0 +1,24 @@ +{% extends 'base.html.twig' %} + +{% block title %}Hello TweetTokController!{% endblock %} + +{% block body %} + + +
+

Hello {{ controller_name }}! ✅

+ + This friendly message is coming from: + + +
{{ author }}
+
{{ content }}
+ +
+{% endblock %}