From e82ff0d2a189a6e024a24e807996224e57ff47d1 Mon Sep 17 00:00:00 2001 From: Alexey Skobkin Date: Sun, 22 Apr 2018 00:54:11 +0300 Subject: [PATCH] Comment schema changes, entity refactored. Post::$subscribed added. Migration needed. --- .../PointToolsBundle/Entity/Blogs/Comment.php | 150 +++++------------- .../PointToolsBundle/Entity/Blogs/Post.php | 26 +++ 2 files changed, 65 insertions(+), 111 deletions(-) diff --git a/src/Skobkin/Bundle/PointToolsBundle/Entity/Blogs/Comment.php b/src/Skobkin/Bundle/PointToolsBundle/Entity/Blogs/Comment.php index a0c1643..c53f332 100644 --- a/src/Skobkin/Bundle/PointToolsBundle/Entity/Blogs/Comment.php +++ b/src/Skobkin/Bundle/PointToolsBundle/Entity/Blogs/Comment.php @@ -62,10 +62,17 @@ class Comment /** * @var int * - * @ORM\Column(name="number", type="smallint") + * @ORM\Column(name="number", type="integer", unique=true) */ private $number; + /** + * @var int + * + * @ORM\Column(name="to_number", type="integer") + */ + private $toNumber; + /** * @var User * @@ -85,26 +92,36 @@ class Comment */ private $files; - /** - * @var Comment|null - * - * @ORM\ManyToOne(targetEntity="Skobkin\Bundle\PointToolsBundle\Entity\Blogs\Comment", inversedBy="children") - * @ORM\JoinColumn(name="parent_id", nullable=true) - */ - private $parent; - /** - * @var Comment[]|ArrayCollection - * - * @ORM\OneToMany(targetEntity="Skobkin\Bundle\PointToolsBundle\Entity\Blogs\Comment", fetch="EXTRA_LAZY", mappedBy="parent") - */ - private $children; + public function __construct( + string $text, + \DateTime $createdAt, + bool $rec, + Post $post, + int $number, + int $toNumber, + User $author, + array $files + ) { + $this->text = $text; + $this->createdAt = $createdAt; + $this->rec = $rec; + $this->post = $post; + $this->number = $number; + $this->toNumber = $toNumber; + $this->author = $author; - - public function __construct() - { $this->files = new ArrayCollection(); - $this->children = new ArrayCollection(); + foreach ($files as $file) { + if (!($file instanceof File)) { + throw new \RuntimeException(sprintf( + '$files array must contain only \'%s\' objects. %s given.', + \is_object($file) ? \get_class($file) : \gettype($file) + )); + } + + $this->files->add($file); + } } public function getId(): int @@ -112,66 +129,26 @@ class Comment return $this->id; } - public function setCreatedAt(\DateTime $createdAt): self - { - $this->createdAt = $createdAt; - - return $this; - } - public function getCreatedAt(): \DateTime { return $this->createdAt; } - public function setText(string $text): self - { - $this->text = $text; - - return $this; - } - public function getText(): string { return $this->text; } - public function setRec(bool $rec): self - { - $this->rec = $rec; - - return $this; - } - public function isRec(): bool { return $this->rec; } - public function getRec(): bool - { - return $this->rec; - } - public function getPost(): Post { return $this->post; } - public function setPost(Post $post): self - { - $this->post = $post; - - return $this; - } - - public function setNumber(int $number): self - { - $this->number = $number; - - return $this; - } - public function getNumber(): int { return $this->number; @@ -182,25 +159,6 @@ class Comment return $this->author; } - public function setAuthor(User $author): self - { - $this->author = $author; - - return $this; - } - - public function addFile(File $files): self - { - $this->files[] = $files; - - return $this; - } - - public function removeFile(File $files): void - { - $this->files->removeElement($files); - } - /** * @return File[]|ArrayCollection */ @@ -209,52 +167,22 @@ class Comment return $this->files; } - public function getParent(): ?Comment + public function delete(): self { - return $this->parent; - } - - public function setParent(Comment $parent): self - { - $this->parent = $parent; + $this->deleted = true; return $this; } - public function setDeleted(bool $deleted): self + public function restore(): self { - $this->deleted = $deleted; + $this->deleted = false; return $this; } - public function getDeleted(): bool - { - return $this->deleted; - } - public function isDeleted(): bool { return $this->deleted; } - - public function addChild(Comment $children): self - { - $this->children[] = $children; - - return $this; - } - - public function removeChild(Comment $children): void - { - $this->children->removeElement($children); - } - - /** - * @return Comment[]|ArrayCollection - */ - public function getChildren(): iterable - { - return $this->children; - } } diff --git a/src/Skobkin/Bundle/PointToolsBundle/Entity/Blogs/Post.php b/src/Skobkin/Bundle/PointToolsBundle/Entity/Blogs/Post.php index 9fd846b..4c63310 100644 --- a/src/Skobkin/Bundle/PointToolsBundle/Entity/Blogs/Post.php +++ b/src/Skobkin/Bundle/PointToolsBundle/Entity/Blogs/Post.php @@ -69,6 +69,13 @@ class Post */ private $deleted = false; + /** + * @var bool Status of point-tools subscription to the post (to receive WS updates) + * + * @ORM\Column(name="is_subscribed", type="boolean") + */ + private $subscribed = false; + /** * @var User * @@ -216,6 +223,25 @@ class Post { return $this->deleted; } + + public function isSubscribed(): bool + { + return $this->subscribed; + } + + public function subscribe(): self + { + $this->subscribed = true; + + return $this; + } + + public function unsubscribe(): self + { + $this->subscribed = false; + + return $this; + } public function setPrivate(bool $private): self {