From bbaa084ae0f1ddfe0080974907373e32f8b556d2 Mon Sep 17 00:00:00 2001 From: Ryan Prather Date: Tue, 30 Apr 2024 08:42:04 -0400 Subject: [PATCH] Updated code --- composer.json | 1 + src/Controller/AjaxController.php | 23 ++++++++++++--------- src/Controller/DefaultController.php | 5 +++-- src/Entity/Notes.php | 28 ++++++++++++++++++++------ src/Entity/Reference.php | 3 ++- src/Repository/ReferenceRepository.php | 25 ----------------------- templates/default/index.html.twig | 4 ++-- 7 files changed, 44 insertions(+), 45 deletions(-) diff --git a/composer.json b/composer.json index ec0fbf0..d2d0e9a 100644 --- a/composer.json +++ b/composer.json @@ -38,6 +38,7 @@ "symfony/string": "6.4.*", "symfony/translation": "6.4.*", "symfony/twig-bundle": "6.4.*", + "symfony/uid": "6.4.*", "symfony/ux-turbo": "^2.16", "symfony/validator": "6.4.*", "symfony/web-link": "6.4.*", diff --git a/src/Controller/AjaxController.php b/src/Controller/AjaxController.php index a7fb6cd..194b357 100644 --- a/src/Controller/AjaxController.php +++ b/src/Controller/AjaxController.php @@ -4,7 +4,6 @@ namespace App\Controller; use App\Entity\Bible; use DateTime; -use DateTimeZone; use App\Entity\Series; use App\Entity\Speaker; @@ -150,7 +149,7 @@ class AjaxController extends AbstractController $ref = new Reference(); $ref->setType($data->type); - if((int) $data->book) { + if(is_numeric($data->book)) { $ref->setNdx($data->book); } @@ -167,7 +166,10 @@ class AjaxController extends AbstractController 'creed' => ReferenceController::retrieveCreed($data->book) }; - $res->setContent(json_encode(['text' => $ret->getContent(), 'title' => "{$ret->getLabel()}"])); + $res->setContent(json_encode([ + 'text' => $ret->getContent(), + 'title' => "{$ret->getLabel()}", + ])); return $res; } @@ -242,15 +244,18 @@ class AjaxController extends AbstractController $note->setId($data->id); } - $note->setTitle($data->title); - $note->setDate(new DateTime($data->date)); + $refs = json_decode(json_encode($data->refs), true); $series = $emi->getRepository(Series::class)->find($data->series); $speaker = $emi->getRepository(Speaker::class)->find($data->speaker); - $note->setSeries($series); - $note->setSpeaker($speaker); - $note->setText($data->note); - $note->setPassage($data->passage); + + $note->setTitle($data->title) + ->setDate(new DateTime($data->date)) + ->setSeries($series) + ->setSpeaker($speaker) + ->setText($data->note) + ->setPassage($data->passage) + ->setRefs($refs); $emi->persist($note); $emi->flush(); diff --git a/src/Controller/DefaultController.php b/src/Controller/DefaultController.php index e4a29df..4f3ef3b 100644 --- a/src/Controller/DefaultController.php +++ b/src/Controller/DefaultController.php @@ -11,6 +11,7 @@ use Doctrine\ORM\EntityManagerInterface; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Annotation\Route; +use Symfony\Component\Uid\Uuid; class DefaultController extends AbstractController { @@ -20,14 +21,14 @@ class DefaultController extends AbstractController $speakers = $emi->getRepository(Speaker::class)->findAll(); $series = $emi->getRepository(Series::class)->findAll(); $templates = $emi->getRepository(Template::class)->findAll(); - $note = $emi->getRepository(Notes::class)->findLastNote(); + $uuid = Uuid::v4(); return $this->render('default/index.html.twig', [ 'controller_name' => 'DefaultController', 'speakers' => $speakers, 'series' => $series, 'templates' => $templates, - 'noteId' => ($note->getId() + 1) + 'id' => $uuid, ]); } diff --git a/src/Entity/Notes.php b/src/Entity/Notes.php index e42d9ed..e474baf 100644 --- a/src/Entity/Notes.php +++ b/src/Entity/Notes.php @@ -11,8 +11,8 @@ use Doctrine\ORM\Mapping as ORM; class Notes implements JsonSerializable { #[ORM\Id()] - #[ORM\Column(type: Types::INTEGER)] - private ?int $id = null; + #[ORM\Column(type: Types::STRING, length: 64)] + private ?string $id = null; #[ORM\Column(length: 255)] private ?string $title = null; @@ -33,12 +33,15 @@ class Notes implements JsonSerializable #[ORM\Column(length: 255, nullable: true)] private ?string $passage = null; + #[ORM\Column(type: Types::JSON, nullable: true)] + private ?array $refs = null; + /** * Retrieves the ID of the object. * - * @return int|null The ID of the object, or null if it is not set. + * @return string|null The ID of the object, or null if it is not set. */ - public function getId(): ?int + public function getId(): ?string { return $this->id; } @@ -46,10 +49,10 @@ class Notes implements JsonSerializable /** * Sets the ID of the object. * - * @param int $id The ID to set. + * @param string $id The ID to set. * @return static */ - public function setId(int $id): static + public function setId(string $id): static { $this->id = $id; @@ -139,6 +142,18 @@ class Notes implements JsonSerializable return $this; } + public function getRefs(): ?array + { + return $this->refs; + } + + public function setRefs(?array $refs): static + { + $this->refs = $refs; + + return $this; + } + public function jsonSerialize(): array { return [ @@ -148,6 +163,7 @@ class Notes implements JsonSerializable 'series' => $this->series, 'text' => $this->text, 'passage' => $this->passage, + 'references' => $this->refs, 'date' => $this->date->format('Y-m-d'), ]; } diff --git a/src/Entity/Reference.php b/src/Entity/Reference.php index 9a455a6..477ce63 100644 --- a/src/Entity/Reference.php +++ b/src/Entity/Reference.php @@ -2,6 +2,7 @@ namespace App\Entity; +use Doctrine\DBAL\Types\Types; use JsonSerializable; use App\Repository\ReferenceRepository; @@ -21,7 +22,7 @@ class Reference implements JsonSerializable #[ORM\Column(length: 255)] private ?string $name = null; - #[ORM\Column(length: 10)] + #[ORM\Column(length: 10, unique: true)] private ?string $label = null; #[ORM\Column(nullable: true)] diff --git a/src/Repository/ReferenceRepository.php b/src/Repository/ReferenceRepository.php index 1ba46c0..33ac7d2 100644 --- a/src/Repository/ReferenceRepository.php +++ b/src/Repository/ReferenceRepository.php @@ -20,29 +20,4 @@ class ReferenceRepository extends ServiceEntityRepository { parent::__construct($registry, Reference::class); } - - // /** - // * @return Reference[] Returns an array of Reference objects - // */ - // public function findByExampleField($value): array - // { - // return $this->createQueryBuilder('r') - // ->andWhere('r.exampleField = :val') - // ->setParameter('val', $value) - // ->orderBy('r.id', 'ASC') - // ->setMaxResults(10) - // ->getQuery() - // ->getResult() - // ; - // } - - // public function findOneBySomeField($value): ?Reference - // { - // return $this->createQueryBuilder('r') - // ->andWhere('r.exampleField = :val') - // ->setParameter('val', $value) - // ->getQuery() - // ->getOneOrNullResult() - // ; - // } } diff --git a/templates/default/index.html.twig b/templates/default/index.html.twig index 9564abe..5b53ced 100644 --- a/templates/default/index.html.twig +++ b/templates/default/index.html.twig @@ -19,7 +19,7 @@