<?php
namespace App\Entity;
use App\Repository\DocumentRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
#[ORM\Entity(repositoryClass: DocumentRepository::class)]
class Document
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
private $id;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $code;
#[ORM\Column(type: 'text')]
private $nom;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $nature;
#[ORM\ManyToOne(targetEntity: TypeDocument::class, inversedBy: 'documents')]
private $typedocument;
#[ORM\Column(type: 'text')]
private $description;
#[Gedmo\Timestampable(on: 'create')]
#[ORM\Column(type: 'datetime')]
private $created_at;
#[Gedmo\Timestampable(on: 'update')]
#[ORM\Column(type: 'datetime')]
private $updated_at;
#[ORM\Column(type: 'integer')]
private $created_by;
#[ORM\Column(type: 'integer')]
private $updated_by;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $file;
#[ORM\Column]
private ?bool $access = false;
#[ORM\ManyToOne(inversedBy: 'documents')]
private ?Groupe $groupe = null;
#[ORM\Column(type: Types::DATE_MUTABLE, nullable: true)]
private ?\DateTimeInterface $datepublication = null;
#[ORM\Column(type: Types::DATE_MUTABLE, nullable: true)]
private ?\DateTimeInterface $datepublicationpublic = null;
#[ORM\OneToMany(mappedBy: 'document', targetEntity: Commentaire::class)]
private Collection $commentaires;
#[ORM\Column(type: 'json')]
private $roles = [];
public function __construct()
{
$this->commentaires = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getCode(): ?string
{
return $this->code;
}
public function setCode(?string $code): self
{
$this->code = $code;
return $this;
}
public function getNom(): ?string
{
return $this->nom;
}
public function setNom(string $nom): self
{
$this->nom = $nom;
return $this;
}
public function getNature(): ?string
{
return $this->nature;
}
public function setNature(?string $nature): self
{
$this->nature = $nature;
return $this;
}
public function getTypedocument(): ?TypeDocument
{
return $this->typedocument;
}
public function setTypedocument(?TypeDocument $typedocument): self
{
$this->typedocument = $typedocument;
return $this;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(string $description): self
{
$this->description = $description;
return $this;
}
public function getCreatedAt(): ?\DateTimeInterface
{
return $this->created_at;
}
public function setCreatedAt(\DateTimeInterface $created_at): self
{
$this->created_at = $created_at;
return $this;
}
public function getUpdatedAt(): ?\DateTimeInterface
{
return $this->updated_at;
}
public function setUpdatedAt(\DateTimeInterface $updated_at): self
{
$this->updated_at = $updated_at;
return $this;
}
public function getCreatedBy(): ?int
{
return $this->created_by;
}
public function setCreatedBy(int $created_by): self
{
$this->created_by = $created_by;
return $this;
}
public function getUpdatedBy(): ?int
{
return $this->updated_by;
}
public function setUpdatedBy(int $updated_by): self
{
$this->updated_by = $updated_by;
return $this;
}
public function getFile(): ?string
{
return $this->file;
}
public function setFile(?string $file): self
{
$this->file = $file;
return $this;
}
public function isAccess(): ?bool
{
return $this->access;
}
public function setAccess(bool $access): self
{
$this->access = $access;
return $this;
}
public function getGroupe(): ?Groupe
{
return $this->groupe;
}
public function setGroupe(?Groupe $groupe): self
{
$this->groupe = $groupe;
return $this;
}
public function getDatepublication(): ?\DateTimeInterface
{
return $this->datepublication;
}
public function setDatepublication(?\DateTimeInterface $datepublication): self
{
$this->datepublication = $datepublication;
return $this;
}
public function getDatepublicationpublic(): ?\DateTimeInterface
{
return $this->datepublicationpublic;
}
public function setDatepublicationpublic(?\DateTimeInterface $datepublicationpublic): self
{
$this->datepublicationpublic = $datepublicationpublic;
return $this;
}
/**
* @return Collection<int, Commentaire>
*/
public function getCommentaires(): Collection
{
return $this->commentaires;
}
public function addCommentaire(Commentaire $commentaire): self
{
if (!$this->commentaires->contains($commentaire)) {
$this->commentaires->add($commentaire);
$commentaire->setDocument($this);
}
return $this;
}
public function removeCommentaire(Commentaire $commentaire): self
{
if ($this->commentaires->removeElement($commentaire)) {
// set the owning side to null (unless already changed)
if ($commentaire->getDocument() === $this) {
$commentaire->setDocument(null);
}
}
return $this;
}
public function getRoles(): array
{
$roles = $this->roles;
return array_unique($roles);
}
public function setRoles(array $roles): self
{
$this->roles = $roles;
return $this;
}
public function hasRole($role)
{
return in_array($role, $this->getRoles(), true);
}
public function addRole($role)
{
if (!in_array($role, $this->roles, true)) {
$this->roles[] = $role;
}
return $this;
}
public function removeRole($role)
{
if (false !== $key = array_search($role, $this->roles, true)) {
unset($this->roles[$key]);
$this->roles = array_values($this->roles);
}
return $this;
}
public function removeAllRole(): self
{
foreach ($this->roles as $role) {
$this->removeRole($role);
}
return $this;
}
}