You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
201 lines
4.2 KiB
201 lines
4.2 KiB
<?php
|
|
|
|
/* For licensing terms, see /license.txt */
|
|
|
|
namespace Chamilo\CoreBundle\Entity;
|
|
|
|
use ApiPlatform\Core\Annotation\ApiResource;
|
|
use Chamilo\CoreBundle\Traits\TimestampableAgoTrait;
|
|
use Doctrine\Common\Collections\ArrayCollection;
|
|
use Doctrine\ORM\Mapping as ORM;
|
|
use Gedmo\Mapping\Annotation as Gedmo;
|
|
use Gedmo\Timestampable\Traits\TimestampableEntity;
|
|
use Gedmo\Tree\Traits\NestedSetEntity;
|
|
use Symfony\Component\Serializer\Annotation\Groups;
|
|
use Symfony\Component\Validator\Constraints as Assert;
|
|
|
|
/**
|
|
* @ApiResource(
|
|
* attributes={"security"="is_granted('ROLE_ADMIN')"},
|
|
* normalizationContext={"groups"={"comment:read"}}
|
|
* )
|
|
*
|
|
* @Gedmo\Tree(type="nested")
|
|
* @ORM\Entity(repositoryClass="Gedmo\Tree\Entity\Repository\NestedTreeRepository")
|
|
* @ORM\Table(name="resource_comment")
|
|
*/
|
|
class ResourceComment
|
|
{
|
|
use TimestampableEntity;
|
|
use TimestampableAgoTrait;
|
|
use NestedSetEntity;
|
|
|
|
/**
|
|
* @ORM\Id
|
|
* @ORM\Column(type="integer")
|
|
* @ORM\GeneratedValue(strategy="AUTO")
|
|
* @Groups({"comment:read"})
|
|
*/
|
|
protected $id;
|
|
|
|
/**
|
|
* @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\ResourceNode", inversedBy="comments")
|
|
* @ORM\JoinColumn(name="resource_node_id", referencedColumnName="id", onDelete="SET NULL")
|
|
*/
|
|
protected $resourceNode;
|
|
|
|
/**
|
|
* @var User
|
|
*
|
|
* @Groups({"comment:read"})
|
|
* @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\User")
|
|
* @ORM\JoinColumn(name="author_id", referencedColumnName="id", onDelete="SET NULL")
|
|
*/
|
|
protected $author;
|
|
|
|
/**
|
|
* @var string
|
|
*
|
|
* @Groups({"comment:read"})
|
|
* @Assert\NotBlank()
|
|
*
|
|
* @ORM\Column(name="content", type="string", nullable=false)
|
|
*/
|
|
protected $content;
|
|
|
|
/**
|
|
* @Gedmo\TreeParent
|
|
*
|
|
* @ORM\ManyToOne(
|
|
* targetEntity="ResourceComment",
|
|
* inversedBy="children"
|
|
* )
|
|
* @ORM\JoinColumns({@ORM\JoinColumn(onDelete="CASCADE")})
|
|
*/
|
|
protected $parent;
|
|
|
|
/**
|
|
* @var \DateTime
|
|
* @Groups({"comment:read"})
|
|
* @Gedmo\Timestampable(on="create")
|
|
* @ORM\Column(type="datetime")
|
|
*/
|
|
protected $createdAt;
|
|
|
|
/**
|
|
* @var \DateTime
|
|
*
|
|
* @Groups({"comment:read"})
|
|
* @Gedmo\Timestampable(on="update")
|
|
* @ORM\Column(type="datetime")
|
|
*/
|
|
protected $updatedAt;
|
|
|
|
/**
|
|
* @var ResourceComment[]
|
|
*
|
|
* @ORM\OneToMany(
|
|
* targetEntity="ResourceComment",
|
|
* mappedBy="parent"
|
|
* )
|
|
* @ORM\OrderBy({"id" = "ASC"})
|
|
*/
|
|
protected $children;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->createdAt = new \DateTimeImmutable();
|
|
$this->content = '';
|
|
$this->children = new ArrayCollection();
|
|
}
|
|
|
|
public function getId()
|
|
{
|
|
return $this->id;
|
|
}
|
|
|
|
/**
|
|
* @return ResourceComment
|
|
*/
|
|
public function setId($id)
|
|
{
|
|
$this->id = $id;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getContent(): string
|
|
{
|
|
return $this->content;
|
|
}
|
|
|
|
public function setContent(string $content): self
|
|
{
|
|
$this->content = $content;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getResourceNode()
|
|
{
|
|
return $this->resourceNode;
|
|
}
|
|
|
|
/**
|
|
* @return ResourceComment
|
|
*/
|
|
public function setResourceNode($resourceNode)
|
|
{
|
|
$this->resourceNode = $resourceNode;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getAuthor(): User
|
|
{
|
|
return $this->author;
|
|
}
|
|
|
|
/**
|
|
* @return ResourceComment
|
|
*/
|
|
public function setAuthor(User $author)
|
|
{
|
|
$this->author = $author;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getParent()
|
|
{
|
|
return $this->parent;
|
|
}
|
|
|
|
/**
|
|
* @return ResourceComment
|
|
*/
|
|
public function setParent($parent)
|
|
{
|
|
$this->parent = $parent;
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* @return ResourceComment[]
|
|
*/
|
|
public function getChildren(): array
|
|
{
|
|
return $this->children;
|
|
}
|
|
|
|
/**
|
|
* @param ResourceComment[] $children
|
|
*/
|
|
public function setChildren(array $children): self
|
|
{
|
|
$this->children = $children;
|
|
|
|
return $this;
|
|
}
|
|
}
|
|
|