Compare commits
6 commits
c2d682967a
...
3fd76ff0ab
Author | SHA1 | Date | |
---|---|---|---|
3fd76ff0ab | |||
bcc2c609c4 | |||
98f3634cf1 | |||
c5a63a4259 | |||
fa9a84f2a7 | |||
5e901bc683 |
|
@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -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,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);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -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()
|
|
||||||
;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -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()
|
||||||
|
@ -109,7 +65,7 @@ class Comment
|
||||||
$this->children = new ArrayCollection();
|
$this->children = new ArrayCollection();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getId(): int
|
public function getId(): ?int
|
||||||
{
|
{
|
||||||
return $this->id;
|
return $this->id;
|
||||||
}
|
}
|
||||||
|
@ -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;
|
37
src/Entity/Blog/File.php
Normal file
37
src/Entity/Blog/File.php
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,109 +1,60 @@
|
||||||
<?php
|
<?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\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\PostTag;
|
|
||||||
use src\PointToolsBundle\Entity\User;
|
|
||||||
use src\PointToolsBundle\Entity\Blogs\Comment;
|
|
||||||
|
|
||||||
/**
|
#[ORM\Entity(repositoryClass: TagRepository::class)]
|
||||||
* @ORM\Table(name="posts", schema="posts", indexes={
|
#[ORM\HasLifecycleCallbacks]
|
||||||
* @ORM\Index(name="idx_post_created_at", columns={"created_at"}),
|
#[ORM\Table(name: 'tags', schema: 'posts')]
|
||||||
* @ORM\Index(name="idx_post_private", columns={"private"}),
|
|
||||||
* })
|
|
||||||
* @ORM\Entity(repositoryClass="Skobkin\Bundle\PointToolsBundle\Repository\Blogs\PostRepository")
|
|
||||||
* @ORM\HasLifecycleCallbacks
|
|
||||||
*/
|
|
||||||
class Post
|
class Post
|
||||||
{
|
{
|
||||||
public const TYPE_POST = 'post';
|
public const TYPE_POST = 'post';
|
||||||
public const TYPE_FEED = 'feed';
|
public const TYPE_FEED = 'feed';
|
||||||
|
|
||||||
/**
|
#[ORM\Id]
|
||||||
* @var string
|
#[ORM\Column(name: 'id', type: 'text')]
|
||||||
*
|
private string $id;
|
||||||
* @ORM\Column(name="id", type="text")
|
|
||||||
* @ORM\Id
|
|
||||||
*/
|
|
||||||
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: 'updated_at', type: 'datetime', nullable: true)]
|
||||||
* @var \DateTime
|
private ?\DateTime $updatedAt;
|
||||||
*
|
|
||||||
* @ORM\Column(name="updated_at", type="datetime", nullable=true)
|
|
||||||
*/
|
|
||||||
private $updatedAt;
|
|
||||||
|
|
||||||
/**
|
#[ORM\Column(name: 'type', type: 'string', length: 6)]
|
||||||
* @var string
|
private string $type = self::TYPE_POST;
|
||||||
*
|
|
||||||
* @ORM\Column(name="type", type="string", length=6)
|
|
||||||
*/
|
|
||||||
private $type = self::TYPE_POST;
|
|
||||||
|
|
||||||
/**
|
#[ORM\Column(name: 'private', type: 'boolean', nullable: true)]
|
||||||
* @var bool
|
private bool $private;
|
||||||
*
|
|
||||||
* @ORM\Column(name="private", type="boolean", nullable=true)
|
|
||||||
*/
|
|
||||||
private $private;
|
|
||||||
|
|
||||||
/**
|
#[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: User::class)]
|
||||||
* @var User
|
#[ORM\JoinColumn(name: 'author')]
|
||||||
*
|
private User $author;
|
||||||
* @ORM\ManyToOne(targetEntity="Skobkin\Bundle\PointToolsBundle\Entity\User")
|
|
||||||
* @ORM\JoinColumn(name="author")
|
|
||||||
*/
|
|
||||||
private $author;
|
|
||||||
|
|
||||||
/**
|
/** @var ArrayCollection|File[] */
|
||||||
* @var File[]|ArrayCollection
|
#[ORM\ManyToMany(targetEntity: File::class, cascade: ['persist'], fetch: 'EXTRA_LAZY')]
|
||||||
*
|
#[ORM\JoinTable(name: 'posts_files', schema: 'posts')]
|
||||||
* @ORM\ManyToMany(targetEntity="Skobkin\Bundle\PointToolsBundle\Entity\Blogs\File", fetch="EXTRA_LAZY", cascade={"persist"})
|
#[ORM\JoinColumn(name: 'post_id')]
|
||||||
* @ORM\JoinTable(name="posts_files", schema="posts",
|
#[ORM\InverseJoinColumn(name: 'file_id')]
|
||||||
* joinColumns={@ORM\JoinColumn(name="post_id")},
|
|
||||||
* inverseJoinColumns={@ORM\JoinColumn(name="file_id")}
|
|
||||||
* )
|
|
||||||
*/
|
|
||||||
private $files;
|
private $files;
|
||||||
|
|
||||||
/**
|
#[ORM\OneToMany(mappedBy: 'post', targetEntity: PostTag::class, cascade: ['persist'], fetch: 'EXTRA_LAZY', orphanRemoval: true)]
|
||||||
* @var PostTag[]|ArrayCollection
|
private ArrayCollection $postTags;
|
||||||
*
|
|
||||||
* @ORM\OneToMany(targetEntity="Skobkin\Bundle\PointToolsBundle\Entity\Blogs\PostTag", mappedBy="post", fetch="EXTRA_LAZY", cascade={"persist"}, orphanRemoval=true)
|
|
||||||
*/
|
|
||||||
private $postTags;
|
|
||||||
|
|
||||||
/**
|
/** @var ArrayCollection|Comment[] */
|
||||||
* @var Comment[]|ArrayCollection
|
#[ORM\OneToMany(targetEntity: Comment::class, mappedBy: 'post', cascade: ['persist'], )]
|
||||||
*
|
private ArrayCollection $comments;
|
||||||
* @ORM\OneToMany(targetEntity="Skobkin\Bundle\PointToolsBundle\Entity\Blogs\Comment", mappedBy="post", cascade={"persist"})
|
|
||||||
*/
|
|
||||||
private $comments;
|
|
||||||
|
|
||||||
|
|
||||||
public function __construct(string $id, User $author, \DateTime $createdAt, string $type)
|
public function __construct(string $id, User $author, \DateTime $createdAt, string $type)
|
||||||
|
@ -118,9 +69,7 @@ class Post
|
||||||
$this->comments = new ArrayCollection();
|
$this->comments = new ArrayCollection();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
#[ORM\PreUpdate]
|
||||||
* @ORM\PreUpdate
|
|
||||||
*/
|
|
||||||
public function preUpdate(): void
|
public function preUpdate(): void
|
||||||
{
|
{
|
||||||
$this->updatedAt = new \DateTime();
|
$this->updatedAt = new \DateTime();
|
||||||
|
@ -175,9 +124,7 @@ class Post
|
||||||
$this->files->removeElement($files);
|
$this->files->removeElement($files);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** @return File[]|ArrayCollection */
|
||||||
* @return File[]|ArrayCollection
|
|
||||||
*/
|
|
||||||
public function getFiles(): iterable
|
public function getFiles(): iterable
|
||||||
{
|
{
|
||||||
return $this->files;
|
return $this->files;
|
||||||
|
@ -195,9 +142,7 @@ class Post
|
||||||
$this->postTags->removeElement($tag);
|
$this->postTags->removeElement($tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** @return PostTag[]|ArrayCollection */
|
||||||
* @return PostTag[]|ArrayCollection
|
|
||||||
*/
|
|
||||||
public function getPostTags(): iterable
|
public function getPostTags(): iterable
|
||||||
{
|
{
|
||||||
return $this->postTags;
|
return $this->postTags;
|
||||||
|
@ -250,9 +195,7 @@ class Post
|
||||||
$this->comments->removeElement($comment);
|
$this->comments->removeElement($comment);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** @return Comment[]|ArrayCollection */
|
||||||
* @return Comment[]|ArrayCollection
|
|
||||||
*/
|
|
||||||
public function getComments(): iterable
|
public function getComments(): iterable
|
||||||
{
|
{
|
||||||
return $this->comments;
|
return $this->comments;
|
62
src/Entity/Blog/PostTag.php
Normal file
62
src/Entity/Blog/PostTag.php
Normal 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
37
src/Entity/Blog/Tag.php
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
33
src/Repository/Blog/FileRepository.php
Normal file
33
src/Repository/Blog/FileRepository.php
Normal 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,21 +1,39 @@
|
||||||
<?php
|
<?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 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);
|
$this->getEntityManager()->persist($entity);
|
||||||
|
|
||||||
|
if ($flush) {
|
||||||
|
$this->getEntityManager()->flush();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getPostWithComments(string $postId): ?Post
|
public function getPostWithComments(string $postId): ?Post
|
||||||
{
|
{
|
||||||
/** @var QueryBuilder $qb */
|
|
||||||
$qb = $this->createQueryBuilder('p');
|
$qb = $this->createQueryBuilder('p');
|
||||||
|
|
||||||
return $qb
|
return $qb
|
||||||
|
@ -27,7 +45,7 @@ class PostRepository extends EntityRepository
|
||||||
->orderBy('c.number', 'asc')
|
->orderBy('c.number', 'asc')
|
||||||
->setParameter('post_id', $postId)
|
->setParameter('post_id', $postId)
|
||||||
->getQuery()->getOneOrNullResult()
|
->getQuery()->getOneOrNullResult()
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function createPublicFeedPostsQuery(): QueryBuilder
|
public function createPublicFeedPostsQuery(): QueryBuilder
|
||||||
|
@ -43,6 +61,6 @@ class PostRepository extends EntityRepository
|
||||||
->where('p.private = FALSE')
|
->where('p.private = FALSE')
|
||||||
->andWhere('pa.public = TRUE')
|
->andWhere('pa.public = TRUE')
|
||||||
->orderBy('p.createdAt', 'desc')
|
->orderBy('p.createdAt', 'desc')
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
}
|
}
|
33
src/Repository/Blog/PostTagRepository.php
Normal file
33
src/Repository/Blog/PostTagRepository.php
Normal 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
43
src/Repository/Blog/TagRepository.php
Normal file
43
src/Repository/Blog/TagRepository.php
Normal 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()
|
||||||
|
;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue