Comment schema changes, entity refactored. Post::$subscribed added. Migration needed.

This commit is contained in:
Alexey Skobkin 2018-04-22 00:54:11 +03:00
parent 184030ebd5
commit e82ff0d2a1
2 changed files with 65 additions and 111 deletions

View file

@ -62,10 +62,17 @@ class Comment
/** /**
* @var int * @var int
* *
* @ORM\Column(name="number", type="smallint") * @ORM\Column(name="number", type="integer", unique=true)
*/ */
private $number; private $number;
/**
* @var int
*
* @ORM\Column(name="to_number", type="integer")
*/
private $toNumber;
/** /**
* @var User * @var User
* *
@ -85,26 +92,36 @@ class Comment
*/ */
private $files; 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;
/** public function __construct(
* @var Comment[]|ArrayCollection string $text,
* \DateTime $createdAt,
* @ORM\OneToMany(targetEntity="Skobkin\Bundle\PointToolsBundle\Entity\Blogs\Comment", fetch="EXTRA_LAZY", mappedBy="parent") bool $rec,
*/ Post $post,
private $children; 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->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 public function getId(): int
@ -112,66 +129,26 @@ class Comment
return $this->id; return $this->id;
} }
public function setCreatedAt(\DateTime $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
public function getCreatedAt(): \DateTime public function getCreatedAt(): \DateTime
{ {
return $this->createdAt; return $this->createdAt;
} }
public function setText(string $text): self
{
$this->text = $text;
return $this;
}
public function getText(): string public function getText(): string
{ {
return $this->text; return $this->text;
} }
public function setRec(bool $rec): self
{
$this->rec = $rec;
return $this;
}
public function isRec(): bool public function isRec(): bool
{ {
return $this->rec; return $this->rec;
} }
public function getRec(): bool
{
return $this->rec;
}
public function getPost(): Post public function getPost(): Post
{ {
return $this->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 public function getNumber(): int
{ {
return $this->number; return $this->number;
@ -182,25 +159,6 @@ class Comment
return $this->author; 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 * @return File[]|ArrayCollection
*/ */
@ -209,52 +167,22 @@ class Comment
return $this->files; return $this->files;
} }
public function getParent(): ?Comment public function delete(): self
{ {
return $this->parent; $this->deleted = true;
}
public function setParent(Comment $parent): self
{
$this->parent = $parent;
return $this; return $this;
} }
public function setDeleted(bool $deleted): self public function restore(): self
{ {
$this->deleted = $deleted; $this->deleted = false;
return $this; return $this;
} }
public function getDeleted(): bool
{
return $this->deleted;
}
public function isDeleted(): bool public function isDeleted(): bool
{ {
return $this->deleted; 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;
}
} }

View file

@ -69,6 +69,13 @@ class Post
*/ */
private $deleted = false; 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 * @var User
* *
@ -217,6 +224,25 @@ class Post
return $this->deleted; 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 public function setPrivate(bool $private): self
{ {
$this->private = $private; $this->private = $private;