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