api/src/Communication/Entity/Medium.php
<?php
/**
* Copyright (c) 2018, 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\Communication\Entity;
use Doctrine\ORM\Mapping as ORM;
use ApiPlatform\Core\Annotation\ApiResource;
use ApiPlatform\Core\Annotation\ApiProperty;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
use ApiPlatform\Core\Annotation\ApiFilter;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\OrderFilter;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
/**
* A communication medium.
*
* @ORM\Entity
* @ORM\HasLifecycleCallbacks
* @ApiResource(
* attributes={
* "normalization_context"={"groups"={"read","readSolidary"}, "enable_max_depth"="true"},
* "denormalization_context"={"groups"={"write","writeSolidary"}}
* },
* itemOperations={
* "get"={
* "swagger_context" = {
* "tags"={"Communication"}
* }
* },
* },
* collectionOperations={
* "get"={
* "swagger_context" = {
* "tags"={"Communication"}
* }
* }
* },
* )
* @ApiFilter(OrderFilter::class, properties={"id", "name"}, arguments={"orderParameterName"="order"})
* @ApiFilter(SearchFilter::class, properties={"name":"partial"})
*/
class Medium
{
const MEDIUM_MESSAGE = 1; // internal message
const MEDIUM_EMAIL = 2; // email
const MEDIUM_SMS = 3; // sms
const MEDIUM_PUSH = 4; // push notification
/**
* @var int The id of this medium.
*
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
* @ApiProperty(identifier=true)
* @Groups({"read","readSolidary","writeSolidary"})
*/
private $id;
/**
* @var string Name of the medium.
*
* @Assert\NotBlank
* @ORM\Column(type="string", length=255)
* @Groups({"read","write","readSolidary","writeSolidary"})
*/
private $name;
/**
* @var \DateTimeInterface Creation date.
*
* @ORM\Column(type="datetime", nullable=true)
* @Groups({"read"})
*/
private $createdDate;
/**
* @var \DateTimeInterface Updated date.
*
* @ORM\Column(type="datetime", nullable=true)
* @Groups({"read"})
*/
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 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());
}
}