| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191 |
- <?php
- declare(strict_types=1);
- namespace App\Entity\Message;
- use ApiPlatform\Metadata\ApiResource;
- use App\Entity\Access\Access;
- use App\Entity\Core\File;
- use App\Entity\Core\Tagg;
- //use DH\Auditor\Provider\Doctrine\Auditing\Annotation\Auditable;
- use Doctrine\Common\Collections\ArrayCollection;
- use Doctrine\Common\Collections\Collection;
- use Doctrine\ORM\Mapping as ORM;
- use Ramsey\Uuid\Uuid;
- /**
- * @todo : A la suite de la migration, il faut supprimer le nom de la table pour avoir une table Email, et supprimer l'attribut discr.
- * @todo : migration table tag_message
- *
- * Classe ... qui ...
- */
- //#[Auditable]
- #[ApiResource(operations: [])]
- #[ORM\Table(name: 'Message')]
- #[ORM\Entity]
- class Email extends AbstractMessage
- {
- #[ORM\Column(length: 255, nullable: false)]
- protected string $discr = 'email';
- #[ORM\Column(type: 'boolean', options: ['default' => false])]
- private bool $isSystem = false;
- #[ORM\ManyToOne(inversedBy: 'emails')]
- #[ORM\JoinColumn(nullable: true)]
- private Access $author;
- #[ORM\OneToMany(mappedBy: 'email', targetEntity: ReportEmail::class, cascade: ['persist'], orphanRemoval: true)]
- #[ORM\JoinColumn(onDelete: 'cascade')]
- private Collection $reports;
- #[ORM\ManyToOne(cascade: ['persist'])]
- #[ORM\JoinColumn(nullable: true)]
- private Mail $mailAttached;
- #[ORM\ManyToMany(targetEntity: File::class, cascade: ['persist'], orphanRemoval: true)]
- #[ORM\JoinTable(name: 'messages_files')]
- #[ORM\JoinColumn(name: 'message_id', referencedColumnName: 'id', onDelete: 'cascade')]
- #[ORM\InverseJoinColumn(name: 'file_id', referencedColumnName: 'id', onDelete: 'cascade')]
- private Collection $files;
- #[ORM\ManyToMany(targetEntity: Tagg::class, inversedBy: 'emails', cascade: ['persist'])]
- #[ORM\JoinTable(name: 'tag_message')]
- #[ORM\JoinColumn(name: 'message_id', referencedColumnName: 'id', onDelete: 'cascade')]
- #[ORM\InverseJoinColumn(name: 'tag_id', referencedColumnName: 'id', onDelete: 'cascade')]
- protected Collection $tags;
- public function __construct()
- {
- $this->uuid = Uuid::uuid4();
- $this->reports = new ArrayCollection();
- $this->files = new ArrayCollection();
- $this->tags = new ArrayCollection();
- }
- public function getDiscr(): ?string
- {
- return $this->discr;
- }
- public function setDiscr(string $discr): self
- {
- $this->discr = $discr;
- return $this;
- }
- public function setIsSystem(bool $isSystem): self
- {
- $this->isSystem = $isSystem;
- return $this;
- }
- public function getIsSystem(): bool
- {
- return $this->isSystem;
- }
- public function getAuthor(): ?Access
- {
- return $this->author;
- }
- public function setAuthor(?Access $author): self
- {
- $this->author = $author;
- return $this;
- }
- /**
- * @return Collection<int, ReportEmail>
- */
- public function getReports(): Collection
- {
- return $this->reports;
- }
- public function addReport(ReportEmail $report): self
- {
- if (!$this->reports->contains($report)) {
- $this->reports[] = $report;
- $report->setEmail($this);
- }
- return $this;
- }
- public function removeReport(ReportEmail $report): self
- {
- if ($this->reports->removeElement($report)) {
- // set the owning side to null (unless already changed)
- if ($report->getEmail() === $this) {
- $report->setEmail(null);
- }
- }
- return $this;
- }
- public function getMailAttached(): ?Mail
- {
- return $this->mailAttached;
- }
- public function setMailAttached(?Mail $mailAttached): self
- {
- $this->mailAttached = $mailAttached;
- return $this;
- }
- /**
- * @return Collection<int, File>
- */
- public function getFiles(): Collection
- {
- return $this->files;
- }
- public function addFile(File $file): self
- {
- if (!$this->files->contains($file)) {
- $this->files[] = $file;
- }
- return $this;
- }
- public function removeFile(File $file): self
- {
- $this->files->removeElement($file);
- return $this;
- }
- /**
- * @return Collection<int, Tagg>
- */
- public function getTags(): Collection
- {
- return $this->tags;
- }
- public function addTag(Tagg $tag): self
- {
- if (!$this->tags->contains($tag)) {
- $this->tags[] = $tag;
- }
- return $this;
- }
- public function removeTag(Tagg $tag): self
- {
- $this->tags->removeElement($tag);
- return $this;
- }
- }
|