Compare commits

..

6 commits

Author SHA1 Message Date
Alexey Skobkin 3fd76ff0ab
Ported Blog\Post entity and repo. 2023-03-19 17:43:05 +03:00
Alexey Skobkin bcc2c609c4
Ported Blog\PostTag entity and repo. 2023-03-19 17:30:44 +03:00
Alexey Skobkin 98f3634cf1
Fixing Blog\{Comment, File}::getId() signature. 2023-03-19 17:24:10 +03:00
Alexey Skobkin c5a63a4259
Ported Blog\Tag entity and repo. 2023-03-19 17:23:30 +03:00
Alexey Skobkin fa9a84f2a7
Ported Blog\File entity and repo. 2023-03-19 17:18:19 +03:00
Alexey Skobkin 5e901bc683
Ported Blog\Comment entity and repo. 2023-03-19 17:01:32 +03:00
17 changed files with 388 additions and 428 deletions

View file

@ -1,44 +0,0 @@
<?php
namespace src\PointToolsBundle\Entity\Blogs;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Table(name="files", schema="posts")
* @ORM\Entity(repositoryClass="Skobkin\Bundle\PointToolsBundle\Repository\Blogs\FileRepository", readOnly=true)
*/
class File
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="remote_url", type="text", unique=true)
*/
private $remoteUrl;
public function __construct($remoteUrl)
{
$this->remoteUrl = $remoteUrl;
}
public function getId(): int
{
return $this->id;
}
public function getRemoteUrl(): string
{
return $this->remoteUrl;
}
}

View file

@ -1,79 +0,0 @@
<?php
namespace src\PointToolsBundle\Entity\Blogs;
use Doctrine\ORM\Mapping as ORM;
use src\PointToolsBundle\Entity\Blogs\Post;
use src\PointToolsBundle\Entity\Blogs\Tag;
/**
* @ORM\Table(name="posts_tags", schema="posts")
* @ORM\Entity(repositoryClass="Skobkin\Bundle\PointToolsBundle\Repository\Blogs\PostTagRepository", readOnly=true)
*/
class PostTag
{
/**
* @var int
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var Post
*
* @ORM\ManyToOne(targetEntity="Post", inversedBy="postTags")
* @ORM\JoinColumn(name="post_id", onDelete="CASCADE")
*/
private $post;
/**
* @var Tag
*
* @ORM\ManyToOne(targetEntity="Tag", fetch="EAGER")
* @ORM\JoinColumn(name="tag_id")
*/
private $tag;
/**
* @var string
*
* @ORM\Column(name="text", type="text")
*/
private $text;
public function __construct(Post $post, Tag $tag, string $text)
{
$this->post = $post;
$this->tag = $tag;
$this->text = $text;
}
public function getId(): int
{
return $this->id;
}
public function getText(): string
{
return $this->text;
}
public function getOriginalTagText(): string
{
return $this->tag->getText();
}
public function getPost(): Post
{
return $this->post;
}
public function getTag(): Tag
{
return $this->tag;
}
}

View file

@ -1,44 +0,0 @@
<?php
namespace src\PointToolsBundle\Entity\Blogs;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Table(name="tags", schema="posts")
* @ORM\Entity(repositoryClass="Skobkin\Bundle\PointToolsBundle\Repository\Blogs\TagRepository", readOnly=true)
*/
class Tag
{
/**
* @var int
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="text", type="text", unique=true)
*/
private $text;
public function __construct(string $text)
{
$this->text = $text;
}
public function getId(): int
{
return $this->id;
}
public function getText(): string
{
return $this->text;
}
}

View file

@ -1,14 +0,0 @@
<?php
namespace src\PointToolsBundle\Repository\Blogs;
use Doctrine\ORM\EntityRepository;
use src\PointToolsBundle\Entity\Blogs\Comment;
class CommentRepository extends EntityRepository
{
public function add(Comment $entity): void
{
$this->getEntityManager()->persist($entity);
}
}

View file

@ -1,14 +0,0 @@
<?php
namespace src\PointToolsBundle\Repository\Blogs;
use Doctrine\ORM\EntityRepository;
use src\PointToolsBundle\Entity\Blogs\File;
class FileRepository extends EntityRepository
{
public function add(File $entity): void
{
$this->getEntityManager()->persist($entity);
}
}

View file

@ -1,14 +0,0 @@
<?php
namespace src\PointToolsBundle\Repository\Blogs;
use Doctrine\ORM\EntityRepository;
use src\PointToolsBundle\Entity\Blogs\PostTag;
class PostTagRepository extends EntityRepository
{
public function add(PostTag $entity): void
{
$this->getEntityManager()->persist($entity);
}
}

View file

@ -1,25 +0,0 @@
<?php
namespace src\PointToolsBundle\Repository\Blogs;
use Doctrine\ORM\EntityRepository;
use src\PointToolsBundle\Entity\Blogs\Tag;
use function Skobkin\Bundle\PointToolsBundle\Repository\Blogs\mb_strtolower;
class TagRepository extends EntityRepository
{
public function add(Tag $entity): void
{
$this->getEntityManager()->persist($entity);
}
public function findOneByLowerText(string $text): ?Tag
{
$qb = $this->createQueryBuilder('t');
return $qb
->where('LOWER(t.text) = :text')
->setParameter('text', mb_strtolower($text))
->getQuery()->getOneOrNullResult()
;
}
}

View file

@ -1,106 +1,62 @@
<?php
declare(strict_types=1);
namespace src\PointToolsBundle\Entity\Blogs;
namespace App\Entity\Blog;
use App\Entity\Blog\File;
use App\Entity\Blog\Post;
use App\Entity\User;
use App\Repository\Blog\CommentRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use src\PointToolsBundle\Entity\Blogs\File;
use src\PointToolsBundle\Entity\Blogs\Post;
use src\PointToolsBundle\Entity\User;
/**
* @ORM\Table(name="comments", schema="posts", indexes={
* @ORM\Index(name="idx_comment_created_at", columns={"created_at"})
* })
* @ORM\Entity(repositoryClass="Skobkin\Bundle\PointToolsBundle\Repository\Blogs\CommentRepository")
*/
#[ORM\Entity(repositoryClass: CommentRepository::class)]
#[ORM\Table(name: 'comments', schema: 'posts')]
#[ORM\Index(columns: ['created_at'], name: 'idx_comment_created_at')]
class Comment
{
/**
* @var int
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue
*/
private $id;
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(name: 'id', type: 'integer')]
private ?int $id;
/**
* @var string
*
* @ORM\Column(name="text", type="text")
*/
private $text;
#[ORM\Column(name: 'text', type: 'text')]
private string $text;
/**
* @var \DateTime
*
* @ORM\Column(name="created_at", type="datetime")
*/
private $createdAt;
#[ORM\Column(name: 'created_at', type: 'datetime')]
private \DateTime $createdAt;
/**
* @var boolean
*
* @ORM\Column(name="is_rec", type="boolean")
*/
private $rec;
#[ORM\Column(name: 'is_rec', type: 'boolean')]
private bool $rec = false;
/**
* @var bool
*
* @ORM\Column(name="is_deleted", type="boolean")
*/
private $deleted = false;
#[ORM\Column(name: 'is_deleted', type: 'boolean')]
private bool $deleted = false;
/**
* @var Post
*
* @ORM\ManyToOne(targetEntity="Skobkin\Bundle\PointToolsBundle\Entity\Blogs\Post", inversedBy="comments")
* @ORM\JoinColumn(name="post_id")
*/
private $post;
#[ORM\ManyToOne(targetEntity: Post::class, inversedBy: 'comments')]
#[ORM\JoinColumn(name: 'post_id')]
private Post $post;
/**
* @var int
*
* @ORM\Column(name="number", type="smallint")
*/
private $number;
#[ORM\Column(name: 'number', type: 'smallint')]
private int $number;
/**
* @var User
*
* @ORM\ManyToOne(targetEntity="Skobkin\Bundle\PointToolsBundle\Entity\User", fetch="EAGER")
* @ORM\JoinColumn(name="author_id")
*/
private $author;
#[ORM\ManyToOne(targetEntity: User::class, fetch: 'EAGER')]
#[ORM\JoinColumn(name: 'author_id')]
private User $author;
/**
* @var File[]|ArrayCollection
*
* @ORM\ManyToMany(targetEntity="Skobkin\Bundle\PointToolsBundle\Entity\Blogs\File", fetch="EXTRA_LAZY", cascade={"persist"})
* @ORM\JoinTable(name="comments_files", schema="posts",
* joinColumns={@ORM\JoinColumn(name="comment_id")},
* inverseJoinColumns={@ORM\JoinColumn(name="file_id")}
* )
*/
private $files;
/** @var ArrayCollection|File[] */
#[ORM\ManyToMany(targetEntity: File::class, fetch: 'EXTRA_LAZY')]
#[ORM\JoinTable(name: 'comments_files', schema: 'posts')]
#[ORM\JoinColumn(name: 'comment_id')]
#[ORM\InverseJoinColumn(name: 'file_id')]
private ArrayCollection $files;
/**
* @var Comment|null
*
* @ORM\ManyToOne(targetEntity="Skobkin\Bundle\PointToolsBundle\Entity\Blogs\Comment", inversedBy="children")
* @ORM\JoinColumn(name="parent_id", nullable=true)
*/
private $parent;
#[ORM\ManyToOne(targetEntity: self::class, inversedBy: 'children')]
#[ORM\JoinColumn(name: 'parent_id', nullable: true)]
private ?self $parent;
/**
* @var Comment[]|ArrayCollection
*
* @ORM\OneToMany(targetEntity="Skobkin\Bundle\PointToolsBundle\Entity\Blogs\Comment", fetch="EXTRA_LAZY", mappedBy="parent")
*/
private $children;
/** @var ArrayCollection|self[] */
#[ORM\OneToMany(mappedBy: 'parent', targetEntity: self::class, fetch: 'EXTRA_LAZY')]
private ArrayCollection $children;
public function __construct()
@ -109,7 +65,7 @@ class Comment
$this->children = new ArrayCollection();
}
public function getId(): int
public function getId(): ?int
{
return $this->id;
}
@ -252,9 +208,7 @@ class Comment
$this->children->removeElement($children);
}
/**
* @return Comment[]|ArrayCollection
*/
/** @return ArrayCollection|self[] */
public function getChildren(): iterable
{
return $this->children;

37
src/Entity/Blog/File.php Normal file
View file

@ -0,0 +1,37 @@
<?php
declare(strict_types=1);
namespace App\Entity\Blog;
use App\Entity\Blog\Post;
use App\Repository\Blog\FileRepository;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: FileRepository::class)]
#[ORM\Table(name: 'files', schema: 'posts')]
class File
{
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'AUTO')]
#[ORM\Column(name: 'id', type: 'integer')]
private ?int $id;
#[ORM\Column(name: 'remote_url', type: 'text', unique: true)]
private string $remoteUrl;
public function __construct($remoteUrl)
{
$this->remoteUrl = $remoteUrl;
}
public function getId(): ?int
{
return $this->id;
}
public function getRemoteUrl(): string
{
return $this->remoteUrl;
}
}

View file

@ -1,109 +1,60 @@
<?php
declare(strict_types=1);
namespace src\PointToolsBundle\Entity\Blogs;
namespace App\Entity\Blog;
use App\Entity\User;
use App\Repository\Blog\TagRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use src\PointToolsBundle\Entity\Blogs\File;
use src\PointToolsBundle\Entity\Blogs\PostTag;
use src\PointToolsBundle\Entity\User;
use src\PointToolsBundle\Entity\Blogs\Comment;
/**
* @ORM\Table(name="posts", schema="posts", indexes={
* @ORM\Index(name="idx_post_created_at", columns={"created_at"}),
* @ORM\Index(name="idx_post_private", columns={"private"}),
* })
* @ORM\Entity(repositoryClass="Skobkin\Bundle\PointToolsBundle\Repository\Blogs\PostRepository")
* @ORM\HasLifecycleCallbacks
*/
#[ORM\Entity(repositoryClass: TagRepository::class)]
#[ORM\HasLifecycleCallbacks]
#[ORM\Table(name: 'tags', schema: 'posts')]
class Post
{
public const TYPE_POST = 'post';
public const TYPE_FEED = 'feed';
/**
* @var string
*
* @ORM\Column(name="id", type="text")
* @ORM\Id
*/
private $id;
#[ORM\Id]
#[ORM\Column(name: 'id', type: 'text')]
private string $id;
/**
* @var string
*
* @ORM\Column(name="text", type="text")
*/
private $text;
#[ORM\Column(name: 'text', type: 'text')]
private string $text;
/**
* @var \DateTime
*
* @ORM\Column(name="created_at", type="datetime")
*/
private $createdAt;
#[ORM\Column(name: 'created_at', type: 'datetime')]
private \DateTime $createdAt;
/**
* @var \DateTime
*
* @ORM\Column(name="updated_at", type="datetime", nullable=true)
*/
private $updatedAt;
#[ORM\Column(name: 'updated_at', type: 'datetime', nullable: true)]
private ?\DateTime $updatedAt;
/**
* @var string
*
* @ORM\Column(name="type", type="string", length=6)
*/
private $type = self::TYPE_POST;
#[ORM\Column(name: 'type', type: 'string', length: 6)]
private string $type = self::TYPE_POST;
/**
* @var bool
*
* @ORM\Column(name="private", type="boolean", nullable=true)
*/
private $private;
#[ORM\Column(name: 'private', type: 'boolean', nullable: true)]
private bool $private;
/**
* @var bool
*
* @ORM\Column(name="is_deleted", type="boolean")
*/
private $deleted = false;
#[ORM\Column(name: 'is_deleted', type: 'boolean')]
private bool $deleted = false;
/**
* @var User
*
* @ORM\ManyToOne(targetEntity="Skobkin\Bundle\PointToolsBundle\Entity\User")
* @ORM\JoinColumn(name="author")
*/
private $author;
#[ORM\ManyToOne(targetEntity: User::class)]
#[ORM\JoinColumn(name: 'author')]
private User $author;
/**
* @var File[]|ArrayCollection
*
* @ORM\ManyToMany(targetEntity="Skobkin\Bundle\PointToolsBundle\Entity\Blogs\File", fetch="EXTRA_LAZY", cascade={"persist"})
* @ORM\JoinTable(name="posts_files", schema="posts",
* joinColumns={@ORM\JoinColumn(name="post_id")},
* inverseJoinColumns={@ORM\JoinColumn(name="file_id")}
* )
*/
/** @var ArrayCollection|File[] */
#[ORM\ManyToMany(targetEntity: File::class, cascade: ['persist'], fetch: 'EXTRA_LAZY')]
#[ORM\JoinTable(name: 'posts_files', schema: 'posts')]
#[ORM\JoinColumn(name: 'post_id')]
#[ORM\InverseJoinColumn(name: 'file_id')]
private $files;
/**
* @var PostTag[]|ArrayCollection
*
* @ORM\OneToMany(targetEntity="Skobkin\Bundle\PointToolsBundle\Entity\Blogs\PostTag", mappedBy="post", fetch="EXTRA_LAZY", cascade={"persist"}, orphanRemoval=true)
*/
private $postTags;
#[ORM\OneToMany(mappedBy: 'post', targetEntity: PostTag::class, cascade: ['persist'], fetch: 'EXTRA_LAZY', orphanRemoval: true)]
private ArrayCollection $postTags;
/**
* @var Comment[]|ArrayCollection
*
* @ORM\OneToMany(targetEntity="Skobkin\Bundle\PointToolsBundle\Entity\Blogs\Comment", mappedBy="post", cascade={"persist"})
*/
private $comments;
/** @var ArrayCollection|Comment[] */
#[ORM\OneToMany(targetEntity: Comment::class, mappedBy: 'post', cascade: ['persist'], )]
private ArrayCollection $comments;
public function __construct(string $id, User $author, \DateTime $createdAt, string $type)
@ -118,9 +69,7 @@ class Post
$this->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;

View file

@ -0,0 +1,62 @@
<?php
declare(strict_types=1);
namespace App\Entity\Blog;
use App\Entity\Blog\Post;
use App\Repository\Blog\PostTagRepository;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: PostTagRepository::class)]
#[ORM\Table(name: 'posts_tags', schema: 'posts')]
class PostTag
{
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'AUTO')]
#[ORM\Column(name: 'id', type: 'integer')]
private ?int $id;
#[ORM\ManyToOne(targetEntity: Post::class, inversedBy: 'postTags')]
#[ORM\JoinColumn(name: 'post_id', onDelete: 'CASCADE')]
private Post $post;
#[ORM\ManyToOne(targetEntity: Tag::class, fetch: 'EAGER')]
#[ORM\JoinColumn(name: 'tag_id')]
private Tag $tag;
#[ORM\Column(name: 'text', type: 'text')]
private string $text;
public function __construct(Post $post, Tag $tag, string $text)
{
$this->post = $post;
$this->tag = $tag;
$this->text = $text;
}
public function getId(): ?int
{
return $this->id;
}
public function getText(): string
{
return $this->text;
}
public function getOriginalTagText(): string
{
return $this->tag->getText();
}
public function getPost(): Post
{
return $this->post;
}
public function getTag(): Tag
{
return $this->tag;
}
}

37
src/Entity/Blog/Tag.php Normal file
View file

@ -0,0 +1,37 @@
<?php
declare(strict_types=1);
namespace App\Entity\Blog;
use App\Entity\Blog\Post;
use App\Repository\Blog\TagRepository;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: TagRepository::class)]
#[ORM\Table(name: 'tags', schema: 'posts')]
class Tag
{
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'AUTO')]
#[ORM\Column(name: 'id', type: 'integer')]
private ?int $id;
#[ORM\Column(name: 'text', type: 'text', unique: true)]
private string $text;
public function __construct(string $text)
{
$this->text = $text;
}
public function getId(): ?int
{
return $this->id;
}
public function getText(): string
{
return $this->text;
}
}

View file

@ -0,0 +1,34 @@
<?php
declare(strict_types=1);
namespace App\Repository\Blog;
use App\Entity\Blog\Comment;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
* @extends ServiceEntityRepository<Comment>
*
* @method Comment|null find($id, $lockMode = null, $lockVersion = null)
* @method Comment|null findOneBy(array $criteria, array $orderBy = null)
* @method Comment[] findAll()
* @method Comment[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
*/
class CommentRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, Comment::class);
}
public function save(Comment $entity, bool $flush = false): void
{
$this->getEntityManager()->persist($entity);
if ($flush) {
$this->getEntityManager()->flush();
}
}
}

View file

@ -0,0 +1,33 @@
<?php
declare(strict_types=1);
namespace App\Repository\Blog;
use App\Entity\Blog\File;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
* @extends ServiceEntityRepository<File>
*
* @method File|null find($id, $lockMode = null, $lockVersion = null)
* @method File|null findOneBy(array $criteria, array $orderBy = null)
* @method File[] findAll()
* @method File[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
*/
class FileRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, File::class);
}
public function save(File $entity, bool $flush = false): void
{
$this->getEntityManager()->persist($entity);
if ($flush) {
$this->getEntityManager()->flush();
}
}
}

View file

@ -1,21 +1,39 @@
<?php
declare(strict_types=1);
namespace src\PointToolsBundle\Repository\Blogs;
namespace App\Repository\Blog;
use Doctrine\ORM\EntityRepository;
use App\Entity\Blog\Post;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\ORM\QueryBuilder;
use src\PointToolsBundle\Entity\Blogs\Post;
use Doctrine\Persistence\ManagerRegistry;
class PostRepository extends EntityRepository
/**
* @extends ServiceEntityRepository<Post>
*
* @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')
;
;
}
}

View file

@ -0,0 +1,33 @@
<?php
declare(strict_types=1);
namespace App\Repository\Blog;
use App\Entity\Blog\PostTag;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
* @extends ServiceEntityRepository<PostTag>
*
* @method PostTag|null find($id, $lockMode = null, $lockVersion = null)
* @method PostTag|null findOneBy(array $criteria, array $orderBy = null)
* @method PostTag[] findAll()
* @method PostTag[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
*/
class PostTagRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, PostTag::class);
}
public function save(PostTag $entity, bool $flush = false): void
{
$this->getEntityManager()->persist($entity);
if ($flush) {
$this->getEntityManager()->flush();
}
}
}

View file

@ -0,0 +1,43 @@
<?php
declare(strict_types=1);
namespace App\Repository\Blog;
use App\Entity\Blog\Tag;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
* @extends ServiceEntityRepository<Tag>
*
* @method Tag|null find($id, $lockMode = null, $lockVersion = null)
* @method Tag|null findOneBy(array $criteria, array $orderBy = null)
* @method Tag[] findAll()
* @method Tag[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
*/
class TagRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, Tag::class);
}
public function save(Tag $entity, bool $flush = false): void
{
$this->getEntityManager()->persist($entity);
if ($flush) {
$this->getEntityManager()->flush();
}
}
public function findOneByLowerText(string $text): ?Tag
{
$qb = $this->createQueryBuilder('t');
return $qb
->where('LOWER(t.text) = :text')
->setParameter('text', \mb_strtolower($text))
->getQuery()->getOneOrNullResult()
;
}
}