From 3fd76ff0ab04c0289e711e2d7136e1747b4a1bd6 Mon Sep 17 00:00:00 2001 From: Alexey Skobkin Date: Sun, 19 Mar 2023 17:43:05 +0300 Subject: [PATCH] Ported Blog\Post entity and repo. --- .../Entity/Blogs => src/Entity/Blog}/Post.php | 135 +++++------------- .../Repository/Blog}/PostRepository.php | 36 +++-- 2 files changed, 66 insertions(+), 105 deletions(-) rename {old/src/PointToolsBundle/Entity/Blogs => src/Entity/Blog}/Post.php (51%) rename {old/src/PointToolsBundle/Repository/Blogs => src/Repository/Blog}/PostRepository.php (56%) diff --git a/old/src/PointToolsBundle/Entity/Blogs/Post.php b/src/Entity/Blog/Post.php similarity index 51% rename from old/src/PointToolsBundle/Entity/Blogs/Post.php rename to src/Entity/Blog/Post.php index 6c01b89..2d8ff69 100644 --- a/old/src/PointToolsBundle/Entity/Blogs/Post.php +++ b/src/Entity/Blog/Post.php @@ -1,109 +1,60 @@ comments = new ArrayCollection(); } - /** - * @ORM\PreUpdate - */ + #[ORM\PreUpdate] public function preUpdate(): void { $this->updatedAt = new \DateTime(); @@ -175,9 +124,7 @@ class Post $this->files->removeElement($files); } - /** - * @return File[]|ArrayCollection - */ + /** @return File[]|ArrayCollection */ public function getFiles(): iterable { return $this->files; @@ -195,9 +142,7 @@ class Post $this->postTags->removeElement($tag); } - /** - * @return PostTag[]|ArrayCollection - */ + /** @return PostTag[]|ArrayCollection */ public function getPostTags(): iterable { return $this->postTags; @@ -250,9 +195,7 @@ class Post $this->comments->removeElement($comment); } - /** - * @return Comment[]|ArrayCollection - */ + /** @return Comment[]|ArrayCollection */ public function getComments(): iterable { return $this->comments; diff --git a/old/src/PointToolsBundle/Repository/Blogs/PostRepository.php b/src/Repository/Blog/PostRepository.php similarity index 56% rename from old/src/PointToolsBundle/Repository/Blogs/PostRepository.php rename to src/Repository/Blog/PostRepository.php index de09311..2f5bf97 100644 --- a/old/src/PointToolsBundle/Repository/Blogs/PostRepository.php +++ b/src/Repository/Blog/PostRepository.php @@ -1,21 +1,39 @@ + * + * @method Post|null find($id, $lockMode = null, $lockVersion = null) + * @method Post|null findOneBy(array $criteria, array $orderBy = null) + * @method Post[] findAll() + * @method Post[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) + */ +class PostRepository extends ServiceEntityRepository { - public function add(Post $entity): void + public function __construct(ManagerRegistry $registry) + { + parent::__construct($registry, Post::class); + } + + public function save(Post $entity, bool $flush = false): void { $this->getEntityManager()->persist($entity); + + if ($flush) { + $this->getEntityManager()->flush(); + } } public function getPostWithComments(string $postId): ?Post { - /** @var QueryBuilder $qb */ $qb = $this->createQueryBuilder('p'); return $qb @@ -27,7 +45,7 @@ class PostRepository extends EntityRepository ->orderBy('c.number', 'asc') ->setParameter('post_id', $postId) ->getQuery()->getOneOrNullResult() - ; + ; } public function createPublicFeedPostsQuery(): QueryBuilder @@ -43,6 +61,6 @@ class PostRepository extends EntityRepository ->where('p.private = FALSE') ->andWhere('pa.public = TRUE') ->orderBy('p.createdAt', 'desc') - ; + ; } -} \ No newline at end of file +}