From 658b021962a526da6b0c3b374ce2cd681c273fe8 Mon Sep 17 00:00:00 2001 From: Ryan Prather Date: Mon, 13 May 2024 21:08:21 -0400 Subject: [PATCH] Entities & Repos --- src/Entity/.gitignore | 0 src/Entity/Bible.php | 190 ++++++++++++++++ src/Entity/Note.php | 196 ++++++++++++++++ src/Entity/Reference.php | 124 ++++++++++ src/Entity/Series.php | 134 +++++++++++ src/Entity/Speaker.php | 118 ++++++++++ src/Entity/Template.php | 134 +++++++++++ src/Entity/User.php | 302 +++++++++++++++++++++++++ src/Repository/BibleRepository.php | 57 +++++ src/Repository/NoteRepository.php | 56 +++++ src/Repository/ReferenceRepository.php | 52 +++++ src/Repository/SeriesRepository.php | 43 ++++ src/Repository/SpeakerRepository.php | 43 ++++ src/Repository/TemplateRepository.php | 43 ++++ src/Repository/UserRepository.php | 60 +++++ 15 files changed, 1552 insertions(+) create mode 100644 src/Entity/.gitignore create mode 100644 src/Entity/Bible.php create mode 100644 src/Entity/Note.php create mode 100644 src/Entity/Reference.php create mode 100644 src/Entity/Series.php create mode 100644 src/Entity/Speaker.php create mode 100644 src/Entity/Template.php create mode 100644 src/Entity/User.php create mode 100644 src/Repository/BibleRepository.php create mode 100644 src/Repository/NoteRepository.php create mode 100644 src/Repository/ReferenceRepository.php create mode 100644 src/Repository/SeriesRepository.php create mode 100644 src/Repository/SpeakerRepository.php create mode 100644 src/Repository/TemplateRepository.php create mode 100644 src/Repository/UserRepository.php diff --git a/src/Entity/.gitignore b/src/Entity/.gitignore new file mode 100644 index 0000000..e69de29 diff --git a/src/Entity/Bible.php b/src/Entity/Bible.php new file mode 100644 index 0000000..ae1b21a --- /dev/null +++ b/src/Entity/Bible.php @@ -0,0 +1,190 @@ +id; + } + + public function setId(?Uuid $id): static + { + $this->id = $id; + + return $this; + } + + public static function idFromString(string $id): Uuid + { + return Uuid::fromString($id); + } + + public function getBook(): ?string + { + return $this->book; + } + + public function setBook(string $book): static + { + $this->book = $book; + + return $this; + } + + public function getChapter(): ?int + { + return $this->chapter; + } + + public function setChapter(int $chapter): static + { + $this->chapter = $chapter; + + return $this; + } + + public function getVerse(): ?int + { + return $this->verse; + } + + public function setVerse(int $verse): static + { + $this->verse = $verse; + + return $this; + } + + public function getContent(): ?string + { + return $this->content; + } + + public function setContent(?string $content): static + { + $this->content = $content; + + return $this; + } + + public function getBookIndex(): ?int + { + return $this->book_index; + } + + public function setBookIndex(int $book_index): static + { + $this->book_index = $book_index; + + return $this; + } + + public function getLabel(): ?string + { + return $this->label; + } + + public function setLabel(?string $label): static + { + $this->label = $label; + + return $this; + } + + public static function findBook(string $reference): string + { + $book = ''; + $tmp = explode(' ', $reference); + $book = "{$tmp[0]}"; + + if(count($tmp) > 2) { + $book = "{$tmp[0]}{$tmp[1]}"; + } + + return $book; + } + + public static function findChapter(string $reference): string + { + $chapter = ''; + $tmp = explode(' ', $reference); + + if(count($tmp) > 2) { + $passage = $tmp[2]; + } else { + $passage = $tmp[1]; + } + + $tmp = explode(':', $passage); + $chapter = $tmp[0]; + + return $chapter; + } + + public static function findVerse(string $reference): int|array|bool + { + $verses = null; + $semicolon = strpos($reference, ':'); + if ($semicolon === false) { + return false; + } + + $tmp = substr($reference, $semicolon + 1); + + if(strpos($tmp, '-') !== false) { + $verses = explode('-', $tmp); + } else { + $verses = (int) $tmp; + } + + return $verses; + } + + public function jsonSerialize(): array + { + return [ + 'id' => $this->getId(), + 'book' => $this->getBook(), + 'chapter' => $this->getChapter(), + 'verse' => $this->getVerse(), + 'content' => $this->getContent(), + 'book_index' => $this->getBookIndex(), + 'label' => $this->getLabel(), + ]; + } +} diff --git a/src/Entity/Note.php b/src/Entity/Note.php new file mode 100644 index 0000000..703ae85 --- /dev/null +++ b/src/Entity/Note.php @@ -0,0 +1,196 @@ +id; + } + + public function setId(?Uuid $id): static + { + $this->id = $id; + + return $this; + } + + public static function idFromString(string $id): Uuid + { + return Uuid::fromString($id); + } + + public function getTitle(): ?string + { + return $this->title; + } + + public function setTitle(string $title): static + { + $this->title = $title; + + return $this; + } + + public function getDate(): ?\DateTimeInterface + { + return $this->date; + } + + public function setDate(\DateTimeInterface $date): static + { + $this->date = $date; + + return $this; + } + + public function getPassage(): ?string + { + return $this->passage; + } + + public function setPassage(string $passage): static + { + $this->passage = $passage; + + return $this; + } + + public function getRefs(): ?array + { + return $this->refs; + } + + public function setRefs(?array $refs): static + { + $this->refs = $refs; + + return $this; + } + + public function addRef(Reference $ref): static + { + $this->refs[] = $ref; + + return $this; + } + + public function getText(): ?string + { + return $this->text; + } + + public function setText(?string $text): static + { + $this->text = $text; + + return $this; + } + + public function getSpeaker(): ?Speaker + { + return $this->speaker; + } + + public function setSpeaker(?Speaker $speaker): static + { + $this->speaker = $speaker; + + return $this; + } + + public function getSeries(): ?Series + { + return $this->series; + } + + public function setSeries(?Series $series): static + { + $this->series = $series; + + return $this; + } + + public function getUser(): ?User + { + return $this->user; + } + + public function setUser(?User $user): static + { + $this->user = $user; + + return $this; + } + + public function toLink(): string + { + return "id}')\">". + $this->title. + ""; + } + + public function toTableRow(): string + { + return "". + "{$this->toLink()}". + "{$this->speaker->getName()}". + "{$this->passage}". + "{$this->date->format('M j, Y')}". + ""; + } + + public function jsonSerialize(): array + { + return [ + 'id' => $this->getId(), + 'title' => $this->getTitle(), + 'date' => $this->getDate(), + 'passage' => $this->getPassage(), + 'refs' => $this->getRefs(), + 'text' => $this->getText(), + 'speaker' => $this->getSpeaker(), + 'series' => $this->getSeries(), + 'user' => $this->getUser(), + ]; + } +} diff --git a/src/Entity/Reference.php b/src/Entity/Reference.php new file mode 100644 index 0000000..23a2b39 --- /dev/null +++ b/src/Entity/Reference.php @@ -0,0 +1,124 @@ +id; + } + + public function setId(?Uuid $id): static + { + $this->id = $id; + + return $this; + } + + public static function idFromString(string $id): Uuid + { + return Uuid::fromString($id); + } + + public function getType(): ?string + { + return $this->type; + } + + public function setType(string $type): static + { + $this->type = $type; + + return $this; + } + + public function getName(): ?string + { + return $this->name; + } + + public function setName(string $name): static + { + $this->name = $name; + + return $this; + } + + public function getLabel(): ?string + { + return $this->label; + } + + public function setLabel(string $label): static + { + $this->label = $label; + + return $this; + } + + public function getNdx(): ?int + { + return $this->ndx; + } + + public function setNdx(int $ndx): static + { + $this->ndx = $ndx; + + return $this; + } + + public function getContent(): ?string + { + return $this->content; + } + + public function setContent(?string $content): static + { + $this->content = $content; + + return $this; + } + + public function jsonSerialize(): array + { + return [ + 'id' => $this->id, + 'type' => $this->type, + 'name' => $this->name, + 'label' => $this->label, + 'ndx' => $this->ndx, + 'content' => $this->content, + ]; + } +} diff --git a/src/Entity/Series.php b/src/Entity/Series.php new file mode 100644 index 0000000..7f0a3bc --- /dev/null +++ b/src/Entity/Series.php @@ -0,0 +1,134 @@ + + */ + #[ORM\OneToMany(targetEntity: Note::class, mappedBy: 'series')] + private Collection $notes; + + public function __construct() + { + $this->notes = new ArrayCollection(); + } + + public function getId(): ?Uuid + { + return $this->id; + } + + public function setId(?Uuid $id): static + { + $this->id = $id; + + return $this; + } + + public static function idFromString(string $id): Uuid + { + return Uuid::fromString($id); + } + + public function getName(): ?string + { + return $this->name; + } + + public function setName(string $name): static + { + $this->name = $name; + + return $this; + } + + public function getUser(): ?User + { + return $this->user; + } + + public function setUser(?User $user): static + { + $this->user = $user; + + return $this; + } + + public function getTemplate(): ?Template + { + return $this->template; + } + + public function setTemplate(?Template $template): static + { + $this->template = $template; + + return $this; + } + + /** + * @return Collection + */ + public function getNotes(): Collection + { + return $this->notes; + } + + public function addNote(Note $note): static + { + if (!$this->notes->contains($note)) { + $this->notes->add($note); + $note->setSeries($this); + } + + return $this; + } + + public function removeNote(Note $note): static + { + if ($this->notes->removeElement($note)) { + // set the owning side to null (unless already changed) + if ($note->getSeries() === $this) { + $note->setSeries(null); + } + } + + return $this; + } + + public function jsonSerialize(): array + { + return [ + 'id' => $this->getId(), + 'name' => $this->getName(), + 'note_count' => count($this->getNotes()), + 'template' => $this->getTemplate(), + ]; + } +} diff --git a/src/Entity/Speaker.php b/src/Entity/Speaker.php new file mode 100644 index 0000000..b8a409c --- /dev/null +++ b/src/Entity/Speaker.php @@ -0,0 +1,118 @@ + + */ + #[ORM\OneToMany(targetEntity: Note::class, mappedBy: 'speaker')] + private Collection $notes; + + public function __construct() + { + $this->notes = new ArrayCollection(); + } + + public function setId(?Uuid $id): static + { + $this->id = $id; + + return $this; + } + + public static function idFromString(string $id): Uuid + { + return Uuid::fromString($id); + } + + public function getId(): ?Uuid + { + return $this->id; + } + + public function getName(): ?string + { + return $this->name; + } + + public function setName(string $name): static + { + $this->name = $name; + + return $this; + } + + public function getUser(): ?User + { + return $this->user; + } + + public function setUser(?User $user): static + { + $this->user = $user; + + return $this; + } + + /** + * @return Collection + */ + public function getNotes(): Collection + { + return $this->notes; + } + + public function addNote(Note $note): static + { + if (!$this->notes->contains($note)) { + $this->notes->add($note); + $note->setSpeaker($this); + } + + return $this; + } + + public function removeNote(Note $note): static + { + if ($this->notes->removeElement($note)) { + // set the owning side to null (unless already changed) + if ($note->getSpeaker() === $this) { + $note->setSpeaker(null); + } + } + + return $this; + } + + public function jsonSerialize(): array + { + return [ + 'id' => $this->getId(), + 'name' => $this->getName(), + 'note_count' => count($this->notes), + ]; + } +} diff --git a/src/Entity/Template.php b/src/Entity/Template.php new file mode 100644 index 0000000..4f6889e --- /dev/null +++ b/src/Entity/Template.php @@ -0,0 +1,134 @@ + + */ + #[ORM\OneToMany(targetEntity: Series::class, mappedBy: 'template')] + private Collection $series; + + #[ORM\ManyToOne(inversedBy: 'templates')] + private ?User $user = null; + + public function __construct() + { + $this->series = new ArrayCollection(); + } + + public function getId(): ?Uuid + { + return $this->id; + } + + public function setId(?Uuid $id): static + { + $this->id = $id; + + return $this; + } + + public static function idFromString(string $id): Uuid + { + return Uuid::fromString($id); + } + + public function getName(): ?string + { + return $this->name; + } + + public function setName(string $name): static + { + $this->name = $name; + + return $this; + } + + public function getContent(): ?string + { + return $this->content; + } + + public function setContent(string $content): static + { + $this->content = $content; + + return $this; + } + + /** + * @return Collection + */ + public function getSeries(): Collection + { + return $this->series; + } + + public function addSeries(Series $series): static + { + if (!$this->series->contains($series)) { + $this->series->add($series); + $series->setTemplate($this); + } + + return $this; + } + + public function removeSeries(Series $series): static + { + if ($this->series->removeElement($series)) { + // set the owning side to null (unless already changed) + if ($series->getTemplate() === $this) { + $series->setTemplate(null); + } + } + + return $this; + } + + public function getUser(): ?User + { + return $this->user; + } + + public function setUser(?User $user): static + { + $this->user = $user; + + return $this; + } + + public function jsonSerialize(): array + { + return [ + 'id' => $this->getId(), + 'name' => $this->getName(), + 'content' => $this->getContent(), + ]; + } +} diff --git a/src/Entity/User.php b/src/Entity/User.php new file mode 100644 index 0000000..16493cf --- /dev/null +++ b/src/Entity/User.php @@ -0,0 +1,302 @@ + The user roles + */ + #[ORM\Column] + private array $roles = []; + + /** + * @var string The hashed password + */ + #[ORM\Column] + private ?string $password = null; + + #[ORM\Column(length: 255)] + private ?string $name = null; + + /** + * @var Collection + */ + #[ORM\OneToMany(targetEntity: Series::class, mappedBy: 'user')] + private Collection $series; + + /** + * @var Collection + */ + #[ORM\OneToMany(targetEntity: Speaker::class, mappedBy: 'user')] + private Collection $speakers; + + /** + * @var Collection + */ + #[ORM\OneToMany(targetEntity: Template::class, mappedBy: 'user')] + private Collection $templates; + + /** + * @var Collection + */ + #[ORM\OneToMany(targetEntity: Note::class, mappedBy: 'user')] + private Collection $notes; + + public function __construct() + { + $this->series = new ArrayCollection(); + $this->speakers = new ArrayCollection(); + $this->templates = new ArrayCollection(); + $this->notes = new ArrayCollection(); + } + + public function getId(): ?Uuid + { + return $this->id; + } + + public function setId(?Uuid $id): static + { + $this->id = $id; + + return $this; + } + + public static function idFromString(string $id): Uuid + { + return Uuid::fromString($id); + } + + public function getEmail(): ?string + { + return $this->email; + } + + public function setEmail(string $email): static + { + $this->email = $email; + + return $this; + } + + /** + * A visual identifier that represents this user. + * + * @see UserInterface + */ + public function getUserIdentifier(): string + { + return (string) $this->email; + } + + /** + * @see UserInterface + * + * @return list + */ + public function getRoles(): array + { + $roles = $this->roles; + // guarantee every user at least has ROLE_USER + $roles[] = 'ROLE_USER'; + + return array_unique($roles); + } + + /** + * @param list $roles + */ + public function setRoles(array $roles): static + { + $this->roles = $roles; + + return $this; + } + + /** + * @see PasswordAuthenticatedUserInterface + */ + public function getPassword(): string + { + return $this->password; + } + + public function setPassword(string $password): static + { + $this->password = $password; + + return $this; + } + + /** + * @see UserInterface + */ + public function eraseCredentials(): void + { + // If you store any temporary, sensitive data on the user, clear it here + // $this->plainPassword = null; + } + + public function getName(): ?string + { + return $this->name; + } + + public function setName(string $name): static + { + $this->name = $name; + + return $this; + } + + /** + * @return Collection + */ + public function getSeries(): Collection + { + return $this->series; + } + + public function addSeries(Series $series): static + { + if (!$this->series->contains($series)) { + $this->series->add($series); + $series->setUser($this); + } + + return $this; + } + + public function removeSeries(Series $series): static + { + if ($this->series->removeElement($series)) { + // set the owning side to null (unless already changed) + if ($series->getUser() === $this) { + $series->setUser(null); + } + } + + return $this; + } + + /** + * @return Collection + */ + public function getSpeakers(): Collection + { + return $this->speakers; + } + + public function addSpeaker(Speaker $speaker): static + { + if (!$this->speakers->contains($speaker)) { + $this->speakers->add($speaker); + $speaker->setUser($this); + } + + return $this; + } + + public function removeSpeaker(Speaker $speaker): static + { + if ($this->speakers->removeElement($speaker)) { + // set the owning side to null (unless already changed) + if ($speaker->getUser() === $this) { + $speaker->setUser(null); + } + } + + return $this; + } + + /** + * @return Collection + */ + public function getTemplates(): Collection + { + return $this->templates; + } + + public function addTemplate(Template $template): static + { + if (!$this->templates->contains($template)) { + $this->templates->add($template); + $template->setUser($this); + } + + return $this; + } + + public function removeTemplate(Template $template): static + { + if ($this->templates->removeElement($template)) { + // set the owning side to null (unless already changed) + if ($template->getUser() === $this) { + $template->setUser(null); + } + } + + return $this; + } + + /** + * @return Collection + */ + public function getNotes(): Collection + { + return $this->notes; + } + + public function addNote(Note $note): static + { + if (!$this->notes->contains($note)) { + $this->notes->add($note); + $note->setUser($this); + } + + return $this; + } + + public function removeNote(Note $note): static + { + if ($this->notes->removeElement($note)) { + // set the owning side to null (unless already changed) + if ($note->getUser() === $this) { + $note->setUser(null); + } + } + + return $this; + } + + public function jsonSerialize(): array + { + return [ + 'id' => $this->id, + 'email' => $this->email, + 'name' => $this->name, + ]; + } +} diff --git a/src/Repository/BibleRepository.php b/src/Repository/BibleRepository.php new file mode 100644 index 0000000..9a0a64b --- /dev/null +++ b/src/Repository/BibleRepository.php @@ -0,0 +1,57 @@ + + */ +class BibleRepository extends ServiceEntityRepository +{ + public function __construct(ManagerRegistry $registry) + { + parent::__construct($registry, Bible::class); + } + + public function findRange(Bible $bible, array $passage): array + { + return $this->createQueryBuilder('b') + ->andWhere('b.book = :book') + ->andWhere('b.chapter = :chapter') + ->andWhere('b.verse BETWEEN :verseStart AND :verseEnd') + ->setParameter('book', $bible->getBook()) + ->setParameter('chapter', $bible->getChapter()) + ->setParameter('verseStart', $passage[0]) + ->setParameter('verseEnd', $passage[1]) + ->getQuery() + ->getResult(); + } + + // /** + // * @return Bible[] Returns an array of Bible objects + // */ + // public function findByExampleField($value): array + // { + // return $this->createQueryBuilder('b') + // ->andWhere('b.exampleField = :val') + // ->setParameter('val', $value) + // ->orderBy('b.id', 'ASC') + // ->setMaxResults(10) + // ->getQuery() + // ->getResult() + // ; + // } + + // public function findOneBySomeField($value): ?Bible + // { + // return $this->createQueryBuilder('b') + // ->andWhere('b.exampleField = :val') + // ->setParameter('val', $value) + // ->getQuery() + // ->getOneOrNullResult() + // ; + // } +} diff --git a/src/Repository/NoteRepository.php b/src/Repository/NoteRepository.php new file mode 100644 index 0000000..52bfe34 --- /dev/null +++ b/src/Repository/NoteRepository.php @@ -0,0 +1,56 @@ + + */ +class NoteRepository extends ServiceEntityRepository +{ + public function __construct(ManagerRegistry $registry) + { + parent::__construct($registry, Note::class); + } + + public function getLast4Notes(?User $user): array + { + $ret = $this->createQueryBuilder('n') + ->where('n.user = :user') + ->setParameter('user', (string) $user->getId()) + ->orderBy('n.date', 'DESC') + ->setMaxResults(4) + ->getQuery() + ->getResult(); + return $ret; + } + + // /** + // * @return Note[] Returns an array of Note objects + // */ + // public function findByExampleField($value): array + // { + // return $this->createQueryBuilder('n') + // ->andWhere('n.exampleField = :val') + // ->setParameter('val', $value) + // ->orderBy('n.id', 'ASC') + // ->setMaxResults(10) + // ->getQuery() + // ->getResult() + // ; + // } + + // public function findOneBySomeField($value): ?Note + // { + // return $this->createQueryBuilder('n') + // ->andWhere('n.exampleField = :val') + // ->setParameter('val', $value) + // ->getQuery() + // ->getOneOrNullResult() + // ; + // } +} diff --git a/src/Repository/ReferenceRepository.php b/src/Repository/ReferenceRepository.php new file mode 100644 index 0000000..178e950 --- /dev/null +++ b/src/Repository/ReferenceRepository.php @@ -0,0 +1,52 @@ + + */ +class ReferenceRepository extends ServiceEntityRepository +{ + public function __construct(ManagerRegistry $registry) + { + parent::__construct($registry, Reference::class); + } + + public function findByType(string $type): array + { + return $this->createQueryBuilder('r') + ->andWhere('r.type = :val') + ->setParameter('val', $type) + ->getQuery() + ->getResult(); + } + + // /** + // * @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/src/Repository/SeriesRepository.php b/src/Repository/SeriesRepository.php new file mode 100644 index 0000000..dac03b6 --- /dev/null +++ b/src/Repository/SeriesRepository.php @@ -0,0 +1,43 @@ + + */ +class SeriesRepository extends ServiceEntityRepository +{ + public function __construct(ManagerRegistry $registry) + { + parent::__construct($registry, Series::class); + } + + // /** + // * @return Series[] Returns an array of Series 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): ?Series + // { + // return $this->createQueryBuilder('s') + // ->andWhere('s.exampleField = :val') + // ->setParameter('val', $value) + // ->getQuery() + // ->getOneOrNullResult() + // ; + // } +} diff --git a/src/Repository/SpeakerRepository.php b/src/Repository/SpeakerRepository.php new file mode 100644 index 0000000..46078f0 --- /dev/null +++ b/src/Repository/SpeakerRepository.php @@ -0,0 +1,43 @@ + + */ +class SpeakerRepository extends ServiceEntityRepository +{ + public function __construct(ManagerRegistry $registry) + { + parent::__construct($registry, Speaker::class); + } + + // /** + // * @return Speaker[] Returns an array of Speaker 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): ?Speaker + // { + // return $this->createQueryBuilder('s') + // ->andWhere('s.exampleField = :val') + // ->setParameter('val', $value) + // ->getQuery() + // ->getOneOrNullResult() + // ; + // } +} diff --git a/src/Repository/TemplateRepository.php b/src/Repository/TemplateRepository.php new file mode 100644 index 0000000..2dfa8a4 --- /dev/null +++ b/src/Repository/TemplateRepository.php @@ -0,0 +1,43 @@ + + */ +class TemplateRepository extends ServiceEntityRepository +{ + public function __construct(ManagerRegistry $registry) + { + parent::__construct($registry, Template::class); + } + + // /** + // * @return Template[] Returns an array of Template 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): ?Template + // { + // return $this->createQueryBuilder('t') + // ->andWhere('t.exampleField = :val') + // ->setParameter('val', $value) + // ->getQuery() + // ->getOneOrNullResult() + // ; + // } +} diff --git a/src/Repository/UserRepository.php b/src/Repository/UserRepository.php new file mode 100644 index 0000000..4f2804e --- /dev/null +++ b/src/Repository/UserRepository.php @@ -0,0 +1,60 @@ + + */ +class UserRepository extends ServiceEntityRepository implements PasswordUpgraderInterface +{ + public function __construct(ManagerRegistry $registry) + { + parent::__construct($registry, User::class); + } + + /** + * Used to upgrade (rehash) the user's password automatically over time. + */ + public function upgradePassword(PasswordAuthenticatedUserInterface $user, string $newHashedPassword): void + { + if (!$user instanceof User) { + throw new UnsupportedUserException(sprintf('Instances of "%s" are not supported.', $user::class)); + } + + $user->setPassword($newHashedPassword); + $this->getEntityManager()->persist($user); + $this->getEntityManager()->flush(); + } + + // /** + // * @return User[] Returns an array of User objects + // */ + // public function findByExampleField($value): array + // { + // return $this->createQueryBuilder('u') + // ->andWhere('u.exampleField = :val') + // ->setParameter('val', $value) + // ->orderBy('u.id', 'ASC') + // ->setMaxResults(10) + // ->getQuery() + // ->getResult() + // ; + // } + + // public function findOneBySomeField($value): ?User + // { + // return $this->createQueryBuilder('u') + // ->andWhere('u.exampleField = :val') + // ->setParameter('val', $value) + // ->getQuery() + // ->getOneOrNullResult() + // ; + // } +}