api/src/MassCommunication/Entity/CampaignTemplate.php
<?php
/**
* Copyright (c) 2020, MOBICOOP. All rights reserved.
* This project is dual licensed under AGPL and proprietary licence.
***************************
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <gnu.org/licenses>.
***************************
* Licence MOBICOOP described in the file
* LICENSE
**************************/
namespace App\MassCommunication\Entity;
use Doctrine\ORM\Mapping as ORM;
use ApiPlatform\Core\Annotation\ApiResource;
use ApiPlatform\Core\Annotation\ApiProperty;
use Symfony\Component\Serializer\Annotation\MaxDepth;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Serializer\Annotation\Groups;
use App\Communication\Entity\Medium;
/**
* A mass communication campaign template.
*
* @ORM\Entity
* @ORM\HasLifecycleCallbacks
* @ApiResource(
* attributes={
* "normalization_context"={"groups"={"read_campaign"}, "enable_max_depth"="true"},
* "denormalization_context"={"groups"={"write_campaign"}}
* },
* collectionOperations={
* "get"={
* "swagger_context" = {
* "tags"={"Mass Communication"}
* }
* },
* "post"={
* "swagger_context" = {
* "tags"={"Mass Communication"}
* }
* },
* },
* itemOperations={
* "get"={
* "swagger_context" = {
* "tags"={"Mass Communication"}
* }
* },
* "put"={
* "swagger_context" = {
* "tags"={"Mass Communication"}
* }
* },
* "delete"={
* "swagger_context" = {
* "tags"={"Mass Communication"}
* }
* }
* }
* )
*/
class CampaignTemplate
{
/**
* @var int The id of this campaign template.
*
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
* @ApiProperty(identifier=true)
* @Groups("read_campaign")
*/
private $id;
/**
* @var string Name of the campaign template.
*
* @Assert\NotBlank
* @ORM\Column(type="string", length=255)
* @Groups({"read_campaign","write_campaign"})
*/
private $name;
/**
* @var string Header of the campaign template.
*
* @ORM\Column(type="text", nullable=true)
* @Groups({"read_campaign","write_campaign"})
*/
private $header;
/**
* @var string Body of the campaign template.
*
* @Assert\NotBlank
* @ORM\Column(type="text")
* @Groups({"read_campaign","write_campaign"})
*/
private $body;
/**
* @var string Footer of the campaign template.
*
* @ORM\Column(type="text", nullable=true)
* @Groups({"read_campaign","write_campaign"})
*/
private $footer;
/**
* @var Medium The medium used for the campaign template.
*
* @ORM\ManyToOne(targetEntity="\App\Communication\Entity\Medium")
* @ORM\JoinColumn(nullable=false, onDelete="CASCADE")
* @Groups({"read_campaign","write_campaign"})
* @MaxDepth(1)
*/
private $medium;
/**
* @var \DateTimeInterface Creation date.
*
* @ORM\Column(type="datetime", nullable=true)
* @Groups({"read_campaign"})
*/
private $createdDate;
/**
* @var \DateTimeInterface Updated date.
*
* @ORM\Column(type="datetime", nullable=true)
* @Groups({"read_campaign"})
*/
private $updatedDate;
public function getId(): ?int
{
return $this->id;
}
public function setId(int $id): self
{
$this->id = $id;
return $this;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getHeader(): ?string
{
return $this->header;
}
public function setHeader(string $header): self
{
$this->header = $header;
return $this;
}
public function getBody(): ?string
{
return $this->body;
}
public function setBody(string $body): self
{
$this->body = $body;
return $this;
}
public function getFooter(): ?string
{
return $this->footer;
}
public function setFooter(string $footer): self
{
$this->footer = $footer;
return $this;
}
public function getMedium(): Medium
{
return $this->medium;
}
public function setMedium(?Medium $medium): self
{
$this->medium = $medium;
return $this;
}
public function getCreatedDate(): ?\DateTimeInterface
{
return $this->createdDate;
}
public function setCreatedDate(\DateTimeInterface $createdDate): self
{
$this->createdDate = $createdDate;
return $this;
}
public function getUpdatedDate(): ?\DateTimeInterface
{
return $this->updatedDate;
}
public function setUpdatedDate(\DateTimeInterface $updatedDate): self
{
$this->updatedDate = $updatedDate;
return $this;
}
// DOCTRINE EVENTS
/**
* Creation date.
*
* @ORM\PrePersist
*/
public function setAutoCreatedDate()
{
$this->setCreatedDate(new \Datetime());
}
/**
* Update date.
*
* @ORM\PreUpdate
*/
public function setAutoUpdatedDate()
{
$this->setUpdatedDate(new \Datetime());
}
}