Ported Blog\PostTag entity and repo.

This commit is contained in:
Alexey Skobkin 2023-03-19 17:30:44 +03:00
parent 98f3634cf1
commit bcc2c609c4
No known key found for this signature in database
GPG Key ID: 5D5CEF6F221278E7
4 changed files with 95 additions and 93 deletions

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,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

@ -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;
}
}

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();
}
}
}