chamilo /
chamilo-lms
| 1 | <?php |
||
| 2 | |||
| 3 | declare(strict_types=1); |
||
| 4 | |||
| 5 | /* For licensing terms, see /license.txt */ |
||
| 6 | |||
| 7 | namespace Chamilo\CourseBundle\Entity; |
||
| 8 | |||
| 9 | use Chamilo\CoreBundle\Entity\AbstractResource; |
||
| 10 | use Chamilo\CoreBundle\Entity\ResourceInterface; |
||
| 11 | use Chamilo\CourseBundle\Repository\CAnnouncementRepository; |
||
| 12 | use DateTime; |
||
| 13 | use Doctrine\Common\Collections\ArrayCollection; |
||
| 14 | use Doctrine\Common\Collections\Collection; |
||
| 15 | use Doctrine\ORM\Mapping as ORM; |
||
| 16 | use Stringable; |
||
| 17 | use Symfony\Component\Validator\Constraints as Assert; |
||
| 18 | |||
| 19 | #[ORM\Table(name: 'c_announcement')] |
||
| 20 | #[ORM\Entity(repositoryClass: CAnnouncementRepository::class)] |
||
| 21 | class CAnnouncement extends AbstractResource implements ResourceInterface, Stringable |
||
| 22 | { |
||
| 23 | #[ORM\Column(name: 'iid', type: 'integer')] |
||
| 24 | #[ORM\Id] |
||
| 25 | #[ORM\GeneratedValue] |
||
| 26 | protected ?int $iid = null; |
||
| 27 | |||
| 28 | #[Assert\NotBlank] |
||
| 29 | #[ORM\Column(name: 'title', type: 'text', nullable: false)] |
||
| 30 | protected string $title; |
||
| 31 | |||
| 32 | #[ORM\Column(name: 'content', type: 'text', nullable: true)] |
||
| 33 | protected ?string $content; |
||
| 34 | |||
| 35 | #[ORM\Column(name: 'end_date', type: 'date', nullable: true)] |
||
| 36 | protected ?DateTime $endDate = null; |
||
| 37 | |||
| 38 | #[ORM\Column(name: 'email_sent', type: 'boolean', nullable: true)] |
||
| 39 | protected ?bool $emailSent = null; |
||
| 40 | |||
| 41 | #[ORM\OneToMany(mappedBy: 'announcement', targetEntity: CAnnouncementAttachment::class, cascade: ['persist'])] |
||
| 42 | private Collection $attachments; |
||
| 43 | |||
| 44 | public function __construct() |
||
| 45 | { |
||
| 46 | $this->content = ''; |
||
| 47 | $this->attachments = new ArrayCollection(); |
||
| 48 | } |
||
| 49 | |||
| 50 | public function __toString(): string |
||
| 51 | { |
||
| 52 | return $this->getTitle(); |
||
| 53 | } |
||
| 54 | |||
| 55 | /** |
||
| 56 | * @return Collection<int, CAnnouncementAttachment> |
||
| 57 | */ |
||
| 58 | public function getAttachments(): Collection |
||
| 59 | { |
||
| 60 | return $this->attachments; |
||
| 61 | } |
||
| 62 | |||
| 63 | public function addAttachment(CAnnouncementAttachment $attachment): static |
||
| 64 | { |
||
| 65 | if (!$this->attachments->contains($attachment)) { |
||
| 66 | $this->attachments->add($attachment); |
||
| 67 | $attachment->setAnnouncement($this); |
||
| 68 | } |
||
| 69 | |||
| 70 | return $this; |
||
| 71 | } |
||
| 72 | |||
| 73 | public function removeAttachment(CAnnouncementAttachment $attachment): static |
||
| 74 | { |
||
| 75 | if ($this->attachments->removeElement($attachment)) { |
||
| 76 | // set the owning side to null (unless already changed) |
||
| 77 | if ($attachment->getAnnouncement() === $this) { |
||
| 78 | $attachment->setAnnouncement(null); |
||
| 79 | } |
||
| 80 | } |
||
| 81 | |||
| 82 | return $this; |
||
| 83 | } |
||
| 84 | |||
| 85 | public function setTitle(string $title): self |
||
| 86 | { |
||
| 87 | $this->title = $title; |
||
| 88 | |||
| 89 | return $this; |
||
| 90 | } |
||
| 91 | |||
| 92 | public function getTitle(): string |
||
| 93 | { |
||
| 94 | return $this->title; |
||
| 95 | } |
||
| 96 | |||
| 97 | public function setContent(string $content): self |
||
| 98 | { |
||
| 99 | $this->content = $content; |
||
| 100 | |||
| 101 | return $this; |
||
| 102 | } |
||
| 103 | |||
| 104 | public function getContent(): ?string |
||
| 105 | { |
||
| 106 | return $this->content; |
||
| 107 | } |
||
| 108 | |||
| 109 | public function setEndDate(?DateTime $endDate): self |
||
| 110 | { |
||
| 111 | $this->endDate = $endDate; |
||
| 112 | |||
| 113 | return $this; |
||
| 114 | } |
||
| 115 | |||
| 116 | public function getEndDate(): ?DateTime |
||
| 117 | { |
||
| 118 | return $this->endDate; |
||
| 119 | } |
||
| 120 | |||
| 121 | public function setEmailSent(bool $emailSent): self |
||
| 122 | { |
||
| 123 | $this->emailSent = $emailSent; |
||
| 124 | |||
| 125 | return $this; |
||
| 126 | } |
||
| 127 | |||
| 128 | /** |
||
| 129 | * Get emailSent. |
||
| 130 | * |
||
| 131 | * @return bool |
||
| 132 | */ |
||
| 133 | public function getEmailSent() |
||
| 134 | { |
||
| 135 | return $this->emailSent; |
||
| 136 | } |
||
| 137 | |||
| 138 | public function getIid(): ?int |
||
| 139 | { |
||
| 140 | return $this->iid; |
||
| 141 | } |
||
| 142 | |||
| 143 | public function getResourceIdentifier(): int |
||
| 144 | { |
||
| 145 | return $this->getIid(); |
||
|
0 ignored issues
–
show
Bug
Best Practice
introduced
by
Loading history...
|
|||
| 146 | } |
||
| 147 | |||
| 148 | public function getResourceName(): string |
||
| 149 | { |
||
| 150 | return $this->getTitle(); |
||
| 151 | } |
||
| 152 | |||
| 153 | public function setResourceName(string $name): self |
||
| 154 | { |
||
| 155 | return $this->setTitle($name); |
||
| 156 | } |
||
| 157 | } |
||
| 158 |